Beispiel #1
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();
            }
        }
Beispiel #2
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();
            }
        }