private SearchQuery(string name, SearchKind kind)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            Name = name;
            Kind = kind;

            switch (kind)
            {
                case SearchKind.Exact:
                    _predicate = s => StringComparer.Ordinal.Equals(name, s);
                    break;
                case SearchKind.ExactIgnoreCase:
                    _predicate = s => CaseInsensitiveComparison.Comparer.Equals(name, s);
                    break;
                case SearchKind.Fuzzy:
                    // Create a single WordSimilarityChecker and capture a delegate reference to 
                    // its 'AreSimilar' method. That way we only create the WordSimilarityChecker
                    // once and it can cache all the information it needs while it does the AreSimilar
                    // check against all the possible candidates.
                    var editDistance = new WordSimilarityChecker(name);
                    _predicate = editDistance.AreSimilar;
                    break;
            }
        }
 public TextChunk(string text, bool allowFuzzingMatching)
 {
     this.Text = text;
     this.CharacterSpans = StringBreaker.BreakIntoCharacterParts(text);
     this.SimilarityChecker = allowFuzzingMatching
         ? new WordSimilarityChecker(text, substringsAreSimilar: false)
         : null;
 }
Exemple #3
0
        public IList<string> FindSimilarWords(string value)
        {
            var result = _bkTree.Find(value, threshold: null);

            using (var spellChecker = new WordSimilarityChecker(value))
            {
                return result.Where(spellChecker.AreSimilar).ToArray();
            }
        }
Exemple #4
0
 /// <summary>
 /// Returns true if 'originalText' and 'candidateText' are likely a misspelling of each other.
 /// Returns false otherwise.  If it is a likely misspelling a similarityWeight is provided
 /// to help rank the match.  Lower costs mean it was a better match.
 /// </summary>
 public static bool AreSimilar(string originalText, string candidateText, out double similarityWeight)
 {
     using (var checker = new WordSimilarityChecker(originalText))
     {
         return checker.AreSimilar(candidateText, out similarityWeight);
     }
 }