Esempio n. 1
0
        public static void FindEquations()
        {
            foreach (RangeWrapper par in RangeWrapper.ReadParagraphsStartingFromCursor(Globals.ThisAddIn.Application.ActiveDocument))
            {
                string parContent = par.Text;

                par.Select();

                var sb = new StringBuilder();
                sb.AppendFormat("#Fields: {0}", par.Range.Fields.Count).AppendLine();
                int numRangeChars = par.Range.Characters.Count;
                int numTextChars  = par.Text.Length;
                sb.AppendFormat("#RangeChars: {0}", numRangeChars).AppendLine();
                sb.AppendFormat("#TextChars: {0}", numTextChars).AppendLine();
                if (numTextChars != numRangeChars)
                {
                    sb.AppendFormat("#Diff: {0}", numTextChars - numRangeChars).AppendLine();
                    //sb.AppendFormat("#RRs: {0}", CountFoundSubstrings(parContent, "\r\r")).AppendLine();
                }

                sb.AppendLine().AppendLine("Content Made Visible:").AppendLine(StringUtil.MakeStringVisible(parContent));

                if (DialogResult.OK != MessageBox.Show(sb.ToString(), "Paragraph Content", MessageBoxButtons.OKCancel))
                {
                    return;
                }
            }
        }
Esempio n. 2
0
        public static void MakeEachParagraphVisible()
        {
            foreach (RangeWrapper par in RangeWrapper.ReadParagraphsStartingFromCursor(Globals.ThisAddIn.Application.ActiveDocument))
            {
                string parContent = par.Text;

                par.Select();
                if (DialogResult.OK != MessageBox.Show(StringUtil.MakeStringVisible(parContent), "Paragraph Content", MessageBoxButtons.OKCancel))
                {
                    return;
                }
            }
        }
Esempio n. 3
0
        public static void CheckWordTokenizerCorrespondenceWithRange(bool refine)
        {
            var tokenizer = new WordTokenizer(WordTokenizerOptions.ReturnPunctuations);

            foreach (
                RangeWrapper par in
                RangeWrapper.ReadParagraphsStartingFromCursor(Globals.ThisAddIn.Application.ActiveDocument))
            {
                int rangeRepairOffset = 0;

                string parContent   = par.Text;
                string tobeVerified = parContent;
                if (refine)
                {
                    tobeVerified = StringUtil.RefineAndFilterPersianWord(tobeVerified);
                }

                int count = 0;
                foreach (var wordInfo in tokenizer.Tokenize(tobeVerified))
                {
                    count++;
                    if (count % 5 != 0)
                    {
                        continue;
                    }

                    // check for every 5 words

                    int widx = wordInfo.Index;
                    int wend = wordInfo.EndIndex;

                    if (refine)
                    {
                        widx = StringUtil.IndexInNotFilterAndRefinedString(parContent, widx);
                        wend = StringUtil.IndexInNotFilterAndRefinedString(parContent, wend);
                    }

                    var wordRange = par.GetRangeWithCharIndex(widx + rangeRepairOffset, wend + rangeRepairOffset);

                    if (wordRange == null || !wordRange.IsRangeValid)
                    {
                        continue;
                    }

                    string wordRangeText = wordRange.Text;
                    if (refine)
                    {
                        wordRangeText = StringUtil.RefineAndFilterPersianWord(wordRangeText);
                    }

                    if (wordRangeText != wordInfo.Value)
                    {
                        // Try to recover here, by fixing rangeRepairOffset
                        var originalWord  = parContent.Substring(widx, wend - widx + 1);
                        var remStrParText = parContent.Substring(widx);

                        var    remParRange   = par.GetRangeWithCharIndex(widx + rangeRepairOffset);
                        string remRngParText = remParRange.Text;


                        // see if any of the rem pars contain the other
                        int  remi       = -1;
                        bool isStrInRng = true;
                        remi = remRngParText.IndexOf(remStrParText, StringComparison.Ordinal);
                        if (remi < 0)
                        {
                            remi       = remStrParText.IndexOf(remRngParText, StringComparison.Ordinal);
                            isStrInRng = false;
                        }

                        if (remi < 0)
                        {
                            Debug.Assert(false, "Non recoverable situation met!");
                            //continue;
                        }

                        if (!isStrInRng)
                        {
                            remi = -remi;
                        }

                        // make sure that you can find the appropriate range

                        int i;
                        for (i = 0; i < 3; i++)
                        {
                            var testRange = par.GetRangeWithCharIndex(widx + rangeRepairOffset + remi, wend + rangeRepairOffset + remi);
                            if (testRange.Text == originalWord)
                            {
                                rangeRepairOffset += remi;
                                wordRange          = testRange;
                                wordRangeText      = wordRange.Text;
                                if (refine)
                                {
                                    wordRangeText = StringUtil.RefineAndFilterPersianWord(wordRangeText);
                                }

                                break;
                            }

                            remi = remi < 0 ? remi - 1 : remi + 1;
                        }

                        if (i >= 3) // i.e., if the above loop did not break
                        {
                            Debug.Assert(false, "Substrings found but ranges not found!");
                            //continue;
                        }
                    }

                    string msg = String.Format("Range: {0}\r\n({1} - {2})\r\n\r\nTokenizer: {3}\r\n({4} - {5})\r\nRangeOffset:{6}",
                                               wordRange.Text, wordRange.Start, wordRange.End, wordInfo.Value,
                                               wordInfo.Index, wordInfo.EndIndex, rangeRepairOffset);

                    wordRange.Select();

                    Debug.Assert(wordRangeText == wordInfo.Value, String.Format(
                                     "The word tokenizer's found word boundries do not match the corresponding range content." +
                                     Environment.NewLine +
                                     "Tokenizer: {0} -> ({1} - {2})" + Environment.NewLine +
                                     "Range: {3} -> ({4} - {5})",
                                     wordInfo.Value, wordInfo.Index, wordInfo.EndIndex,
                                     wordRange.Text, wordRange.Start, wordRange.End));


                    if (DialogResult.OK != MessageBox.Show(msg, "word check", MessageBoxButtons.OKCancel))
                    {
                        return;
                    }
                }
            } // end of foreach par
        }
        private void VerifierThreadCallBack()
        {
            LastUserAction = UserSelectedActions.None;
            IEnumerable <RangeWrapper> parEnumerable = RangeWrapper.ReadParagraphsStartingFromCursor(m_verifier.Document);

            try
            {
                // Check if revisions are visible, if so make them invisible and turn them back on in the end
                m_isRevisionsEnabled = DocumentUtils.IsRevisionsEnabled(m_verifier.Document);
                if (m_isRevisionsEnabled)
                {
                    DocumentUtils.ChangeShowingRevisions(m_verifier.Document, false);
                }

                while (!m_cancelationPending)
                {
                    foreach (RangeWrapper par in parEnumerable)
                    {
                        SendParagraphForVerification(par);

                        if (m_cancelationPending)
                        {
                            break;
                        }

                        if (m_cancelationPending || LastUserAction == UserSelectedActions.Resume)
                        {
                            break;
                        }
                    } // end of foreach par

                    // if resume was pressed without been cancelled, then restart from the beginning
                    if (!m_cancelationPending && LastUserAction == UserSelectedActions.Resume)
                    {
                        parEnumerable  = RangeWrapper.ReadParagraphsStartingFromCursor(m_verifier.Document);
                        LastUserAction = UserSelectedActions.None;
                    }
                    // otherwise it means that we actually reached the end of the text
                    else if (!m_cancelationPending)
                    {
                        m_verifierRequestType = VerifierRequestTypes.RequestEndOfLoop;
                        m_eventUserInputRequest.Set();
                        m_eventUserInputAvailable.WaitOne();

                        if (!m_cancelationPending)
                        {
                            // make it read from the beginning of the document
                            parEnumerable  = RangeWrapper.ReadParagraphs(m_verifier.Document);
                            LastUserAction = UserSelectedActions.None;
                            HideResumeButton();
                            GoIdle();
                        }
                    }
                } // end of while
            }
            finally
            {
                // Check if revisions are visible, if so make them invisible and turn them back on in the end
                if (m_isRevisionsEnabled && !m_isDocumentClosed)
                {
                    DocumentUtils.ChangeShowingRevisions(m_verifier.Document, true);
                }
                //m_eventVerifierThreadStoped.Set();
            }
        }