Ejemplo n.º 1
0
        public override void Search(Sentence sentence)
        {
            base.Search(sentence);

            if (Search1Matches != 0)
            {
                sentence.AddToMatches(Search1Matches * Search1.Length);

                RoundImportance(sentence);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/2be73700-38cd-4098-9852-95b8d1406498
        /// Used the above method instead of my initial idea of split, remove incorrect and then count.
        /// Because of the additional loop involved.
        /// </summary>
        public virtual void Search(Sentence sentence)
        {
            // Reset the proximity of each search
            MatchesProximity = 1;

            // Get all matches for the first search option.
            MatchCollection matches1 = Regex.Matches(sentence.Value, Search1);
            Search1Matches = matches1.Count;

            // If there is no second search option return
            if (string.IsNullOrEmpty(Search2)) return;

            // Get all matches for the second search option.
            MatchCollection matches2 = Regex.Matches(sentence.Value, Search2);
            Search2Matches = matches2.Count;

            // Return if there are not matches in both searches.
            if (Search1Matches == 0 || Search2Matches == 0) return;

            // This is the position of the first match in value
            int startIndex = 0;
            if (matches1[0].Index > matches2[0].Index)
            {
                startIndex = matches2[0].Index;
            }
            else
            {
                startIndex = matches1[0].Index;
            }

            // This is the position of the last match in value
            int endIndex = 0;
            if (matches1[matches1.Count - 1].Index > matches2[matches2.Count - 1].Index)
            {
                endIndex = matches2[matches2.Count - 1].Index;
            }
            else
            {
                endIndex = matches1[matches1.Count - 1].Index;
            }

            // Percentage closeness of the first and last match.

            MatchesProximity = 100 -
            // Because we value close matches we remove the distance percentage of matches from 100%
                (((endIndex - startIndex) -
                    // Remove all matches from each search from the length.
                    ((Search1Matches - 1) * Search1.Length) -
                    ((Search2Matches - 1) * Search2.Length))
                // Get as percentage of all characters in the sentence
                / sentence.Value.Length);
        }
Ejemplo n.º 3
0
        public override void Search(Sentence sentence)
        {
            base.Search(sentence);

            if (Search1Matches != 0 && Search2Matches != 0)
            {
                // We use an optional perimeter to get the number of pairs and couples in the search.

                sentence.AddToMatches(
                    Search1Matches * Search1.Length + Search2Matches * Search2.Length,
                    Math.Min(Search1Matches, Search2Matches) * (Search1.Length + Search2.Length));

                sentence.Importance *= MatchesProximity;

                RoundImportance(sentence);
            }
        }
Ejemplo n.º 4
0
 protected void RoundImportance(Sentence sentence)
 {
     sentence.Importance = Math.Round(sentence.Importance, 2);
 }