Example #1
0
        public void processSocKitMessage(TurKitSocKit.TurKitFindFixVerify message)
        {
            findFixVerifies.Add(message);
            postProcessSocKitMessage(message);

            /*
             * Word.Range curParagraphRange = range.Paragraphs[message.paragraph + 1].Range;
             * Word.Document doc = Globals.Soylent.jobToDoc[job];
             *
             * foreach (TurKitSocKit.TurKitFindFixVerifyPatch tkspatch in message.patches)
             * {
             *
             *  int start = curParagraphRange.Start + tkspatch.editStart;
             *  int end = curParagraphRange.Start + tkspatch.editEnd;
             *  //Word.Range patchRange = Globals.Soylent.Application.ActiveDocument.Range(start, end); //New range for this patch, yay!
             *  Word.Range patchRange = doc.Range(start, end);
             *
             *  List<string> alternatives = new List<string>();
             *  foreach (TurKitSocKit.TurKitFindFixVerifyOption option in (from option in tkspatch.options where option.field == "revision" select option))
             *  {
             *      alternatives.AddRange(from alternative in option.alternatives select alternative.editedText);
             *  }
             *
             *  List<string> reasons = new List<string>();
             *  foreach (TurKitSocKit.TurKitFindFixVerifyOption option in (from option in tkspatch.options where option.field == "reason" select option))
             *  {
             *      reasons.AddRange(from alternative in option.alternatives select alternative.text);
             *  }
             *
             *
             *
             *  CrowdproofPatch thisPatch = new CrowdproofPatch(patchRange, alternatives, reasons);
             *  // add the original as an option
             *  //thisPatch.replacements.Add(tkspatch.originalText);
             *
             *  patches.Add(thisPatch);
             * }
             *
             * paragraphsCompleted++;
             *
             * if (paragraphsCompleted == numParagraphs) //If we have done all paragraphs, make them available to the user!
             * {
             *  //TODO: use a delegate.
             *  //Globals.Soylent.soylentMap[Globals.Soylent.Application.ActiveDocument].Invoke(new crowdproofDelegate(this.crowdproofDataReceived), new object[] { });
             *  Globals.Soylent.soylentMap[doc].Invoke(new crowdproofDelegate(this.crowdproofDataReceived), new object[] { });
             *
             *  this.tk.turkitLoopTimer.Dispose();
             *  //CrowdproofView view = this.view as CrowdproofView;
             *  //view.crowdproofDataReceived();
             *  //this.AnnotateResult();
             * }
             */
        }
Example #2
0
 /// <summary>
 /// Processes a shortn message, one that contains the final results of the algorithm. One per paragraph
 /// </summary>
 /// <param name="message"></param>
 public void processSocKitMessage(TurKitSocKit.TurKitFindFixVerify message)
 {
     findFixVerifies.Add(message);
     postProcessSocKitMessage(message);
 }
Example #3
0
        public void postProcessSocKitMessage(TurKitSocKit.TurKitFindFixVerify message)
        {
            if (paragraphsCompleted.Contains(message.paragraph))
            {
                return; // we've already processed this paragraph
            }

            Word.Range curParagraphRange = range.Paragraphs[message.paragraph + 1].Range;
            int        nextStart         = 0; //Is always the location where the next patch (dummy or otherwise) should start.
            int        nextEnd;               //Is where the last patch ended.  Kinda poorly named. Tells us if we need to add a dummy patch after the last real patch

            Microsoft.Office.Interop.Word.Document doc = Globals.Soylent.jobToDoc[this.job];

            foreach (TurKitSocKit.TurKitFindFixVerifyPatch tkspatch in message.patches)
            {
                //For text in between patches, we create dummy patches.
                if (tkspatch.editStart > nextStart)
                {
                    nextEnd = tkspatch.editStart;
                    int        dummyStart = curParagraphRange.Start + nextStart;
                    int        dummyEnd   = curParagraphRange.Start + nextEnd;
                    Word.Range dummyRange = doc.Range(dummyStart, dummyEnd);

                    DummyPatch dummyPatch = new DummyPatch(dummyRange);
                    Debug.WriteLine("dummy patch: " + dummyRange.Text);

                    patches.Add(dummyPatch);
                }

                int        start      = curParagraphRange.Start + tkspatch.editStart;
                int        end        = curParagraphRange.Start + tkspatch.editEnd;
                Word.Range patchRange = doc.Range(start, end);
                Debug.WriteLine("new patch: " + patchRange.Text);

                List <string> alternatives = new List <string>();
                foreach (TurKitSocKit.TurKitFindFixVerifyOption option in (from option in tkspatch.options where option.editsText select option))
                {
                    alternatives.AddRange(from alternative in option.alternatives select alternative.editedText);
                }

                ShortnPatch thisPatch = new ShortnPatch(patchRange, alternatives);
                // add the original as an option
                thisPatch.replacements.Add(tkspatch.originalText);

                patches.Add(thisPatch);
                nextStart = tkspatch.editEnd;
            }


            //If the last patch we found isn't the end of the paragraph, create a DummyPatch
            if (nextStart < (curParagraphRange.Text.Length - 1))
            {
                nextEnd = curParagraphRange.Text.Length;
                Word.Range dummyRange = doc.Range(curParagraphRange.Start + nextStart, curParagraphRange.End);
                Debug.WriteLine("dummy patch: " + dummyRange.Text);

                DummyPatch dummyPatch = new DummyPatch(dummyRange);

                patches.Add(dummyPatch);
            }
            paragraphsCompleted.Add(message.paragraph);

            if (paragraphsCompleted.Count() == numParagraphs) //If we have done all paragraphs, make them available to the user!
            {
                //TODO: use a delegate.
                if (this.tk.turkitLoopTimer != null)
                {
                    this.tk.turkitLoopTimer.Dispose();
                }

                this.jobDone = true;

                /*
                 * foreach (Patch patch in patches)
                 * {
                 *  Debug.WriteLine(patch.range.Start + " - " + patch.range.End + " : " + patch.range.Text + " || " + (patch is DummyPatch));
                 * }
                 */

                returnShortnResults();
            }
        }