Exemplo n.º 1
0
        private TextSplitted getTextSplitted(FoundAcronym acronym, string text)
        {
            TextSplitted ret = new TextSplitted();

            string          leftText = StringTreatment.NormalizeText(text.Substring(0, acronym.Index));
            MatchCollection newLines = Regex.Matches(leftText, Environment.NewLine, RegexOptions.RightToLeft);

            if (newLines.Count == 0)
            {
                ret.MainParagraph = leftText.Trim();
            }
            else
            {
                ret.MainParagraph = leftText.Substring(newLines[0].Index).Trim();
                leftText          = leftText.Substring(0, newLines[0].Index);
                for (int i = 1; i <= _paragraphsAround && i <= newLines.Count; i++)
                {
                    string nextParagraph = leftText.Substring(i < newLines.Count ? newLines[i].Index : 0);
                    if (!string.IsNullOrWhiteSpace(nextParagraph))
                    {
                        ret.LeftParagraphs.Add(nextParagraph.Trim());
                    }
                    if (i < newLines.Count)
                    {
                        leftText = leftText.Substring(0, newLines[i].Index);
                    }
                }
            }

            ret.MainParagraph += " "; // +acronym.Caption + " ";

            string rightText = StringTreatment.NormalizeText(text.Substring(acronym.Index + acronym.Caption.Length));

            newLines = Regex.Matches(rightText, Environment.NewLine);
            if (newLines.Count == 0)
            {
                ret.MainParagraph += rightText.Trim();
            }
            else
            {
                ret.MainParagraph += rightText.Substring(0, newLines[0].Index).Trim();
                int indexOfLastLineBreak = newLines[0].Index;
                for (int i = 1; i <= _paragraphsAround && i <= newLines.Count; i++)
                {
                    string nextParagraph = rightText.Substring(indexOfLastLineBreak, i < newLines.Count ? (newLines[i].Index - indexOfLastLineBreak)
                                                                                                        : rightText.Length - indexOfLastLineBreak);
                    if (!string.IsNullOrWhiteSpace(nextParagraph))
                    {
                        ret.RightParagraphs.Add(nextParagraph.Trim());
                    }
                    if (i < newLines.Count)
                    {
                        indexOfLastLineBreak = newLines[i].Index;
                    }
                }
            }

            return(ret);
        }
Exemplo n.º 2
0
 private SelectedMeaningBase getAcronymMeaning(FoundAcronym acronym)
 {
     try
     {
         Cursor.Current = Cursors.WaitCursor;
         return(_acroInquisitor.GetAcronymMeaning(acronym, rtxtInput.Text));
     }
     finally
     {
         Cursor.Current = Cursors.Default;
     }
 }
Exemplo n.º 3
0
        public override SelectedMeaningBase SelectMeaning(FoundAcronym acronym, string text)
        {
            List <RankedSelectedMeaning> meanings = acronym.Acronym.Meanings.Select(x => new RankedSelectedMeaning(x)).ToList();

            if (_criteriaOrder.Contains(RankingCriteria.Score))
            {
                TextSplitted textSplitted = getTextSplitted(acronym, text);
                foreach (RankedSelectedMeaning meaning in meanings)
                {
                    calculateScore(meaning, textSplitted);
                }
            }

            return(sortByCriteriaOrder(meanings).FirstOrDefault());
        }
Exemplo n.º 4
0
        private void setCursor(Point cursorLocation)
        {
            try
            {
                _updatingText = true;
                if (_lastPoint == null || _lastPoint != cursorLocation)
                {
                    bool isOnAcronym = false;

                    int mouseIndex = rtxtInput.GetCharIndexFromPosition(cursorLocation);

                    if (_acronyms != null)
                    {
                        FoundAcronym pointedAcronym = _acronyms.FirstOrDefault(x => x.Index <= mouseIndex && x.Index + x.Caption.Length >= mouseIndex);

                        if (pointedAcronym != null)
                        {
                            Point firstAcronymPosition = rtxtInput.GetPositionFromCharIndex(pointedAcronym.Index);
                            Point lastAcronymPosition  = rtxtInput.GetPositionFromCharIndex(pointedAcronym.Index + pointedAcronym.Caption.Length);

                            if (pointedAcronym != null &&
                                lastAcronymPosition.X >= cursorLocation.X &&
                                firstAcronymPosition.X <= cursorLocation.X &&
                                firstAcronymPosition.Y + 2 * txtSearchString.Font.SizeInPoints >= cursorLocation.Y)
                            {
                                List <FoundAcronym> acronymsToPaint = null;
                                if (!pointedAcronym.IsMeaningSet)
                                {
                                    pointedAcronym.Meaning = getAcronymMeaning(pointedAcronym);

                                    acronymsToPaint = new List <FoundAcronym>();
                                    acronymsToPaint.Add(pointedAcronym);
                                    acronymsToPaint.AddRange(_acronyms.Where(x => x.Caption.Replace(".", string.Empty) == pointedAcronym.Caption.Replace(".", string.Empty) &&
                                                                             !x.IsMeaningSet &&
                                                                             x.Index != pointedAcronym.Index));
                                }

                                Point tooltipLocation = new Point(cursorLocation.X + 2, cursorLocation.Y + 2);

                                if (pointedAcronym.Meaning != null)
                                {
                                    paint(acronymsToPaint, _acronymKnownColor);
                                    ttpAcronym.Show(string.Format("{0}: {1}{2}",
                                                                  pointedAcronym.Caption.Replace(".", string.Empty),
                                                                  pointedAcronym.Meaning,
                                                                  chkShowExplanation.Checked ? Environment.NewLine + pointedAcronym.Meaning.Explanation
                                                                                             : string.Empty),
                                                    rtxtInput, tooltipLocation);
                                    _pointedAcronym  = pointedAcronym;
                                    rtxtInput.Cursor = Cursors.Hand;
                                }
                                else
                                {
                                    paint(acronymsToPaint, _acronymUnknownColor);
                                    ttpAcronym.Show("Acronym not found", rtxtInput, tooltipLocation);
                                    _pointedAcronym  = null;
                                    rtxtInput.Cursor = Cursors.Default;
                                }
                                isOnAcronym = true;
                            }
                        }
                    }

                    if (!isOnAcronym)
                    {
                        ttpAcronym.Hide(rtxtInput);
                        _pointedAcronym  = null;
                        rtxtInput.Cursor = Cursors.Default;
                    }

                    _lastPoint = cursorLocation;
                }
            }
            finally
            {
                _updatingText = false;
            }
        }
Exemplo n.º 5
0
 public SelectedMeaningBase GetAcronymMeaning(FoundAcronym foundAcronym, string wholeText)
 {
     foundAcronym.Acronym = DataContext.Instance.AcronymSet.FirstOrDefault(x => x.Caption == foundAcronym.Caption.Replace(".", string.Empty));
     return(foundAcronym.Acronym == null ? null : MeaningSelector.SelectMeaning(foundAcronym, wholeText));
 }
Exemplo n.º 6
0
 public abstract SelectedMeaningBase SelectMeaning(FoundAcronym acronym, string text);