/// <summary> /// Compares two strings for similarity. /// </summary> /// <param name="firstWord">The first string to compare.</param> /// <param name="secondWord">The second string to compare.</param> /// <param name="threshold">Any similarity score at or above this value will be considered similar.</param> /// <param name="algorithm">Specify the algorithm to use for comparing <paramref name="firstWord"/> and <paramref name="secondWord"/>. The default /// algorithm is <see cref="SimMetricAlgorithm.Levenstein"/>.</param> /// <returns>`true` if the similarity score is equal or above <paramref name="threshold"/>. Otherwise, `false`.</returns> /// <remarks><![CDATA[ /// The following code demonstrates how to filter a list of strings based on the degree of similarity: /// ```C# /// string word = "fooler" /// var list = new List<string>() { "fowler", "fish", "crawler" }; /// var filtered = List<string>(); /// foreach (string item in list) /// { /// if (item.NearEquals(word)) /// filtered.Add(item); /// } /// Console.WriteLine("You typed '{0}'. Did you mean: {1}", word, filtered); /// ``` /// ]]></remarks> public static bool NearEquals(this string firstWord, string secondWord, double threshold, SimMetricAlgorithm algorithm) { IStringMetric sim = StringMetricFactory.FromAlgorithm(algorithm); double diff = sim.GetSimilarity(firstWord, secondWord); return((diff < threshold) ? true : false); }
/// <summary> /// Constructor for use by the serializer, you should be using this otherwise. /// </summary> /// <param name="dictionary"></param> /// <param name="wordlist"></param> internal SymmetricPredictor(Dictionary<string, List<int>> dictionary, List<string> wordlist, IStringMetric stringMetric) { _stringSimilarityProvider = stringMetric; Dictionary = dictionary; Wordlist = wordlist; }
/// <summary> /// Will process a list of words into the Dictionary and WordList /// </summary> /// <param name="strings">The words in the corpus.</param> public SymmetricPredictor(IEnumerable<string> strings, IStringMetric stringMetric) { _stringSimilarityProvider = stringMetric; foreach (var key in strings) { CreateSymmetricEntry(key); } Wordlist.TrimExcess(); }
/// <inheritdoc cref="IStringMatcher.IsMatch"/> public double IsMatch(string input) { IStringMetric m = GetStringMetricType(); return(MatchBehaviourHelper.Convert(MatchBehaviour, MatchScores.ToScore(_patterns.Select(p => m.GetSimilarity(p, input))))); }
internal SpellCheck(IEnumerable <string> words, IStringMetric metric) : base(words) { StringSimilarityProvider = metric; }
public SpellCheck(int terminalCount, char[] characters, int rootNodeIndex, int[] firstChildForNode, int[] edges, ushort[] edgeCharacter, IStringMetric metric) : base(terminalCount, characters, rootNodeIndex, firstChildForNode, edges, edgeCharacter) { StringSimilarityProvider = metric; }
public void AddArbitrationMetric(IStringMetric arbitrationMetric) { metricsForArbitration.Add(arbitrationMetric); }
public static double CalcMetric(this Image image, string title, ITokenizer tokenizer, IStringMetric metric) { var imageTitle = string.Join(" ", tokenizer.Tokenize(image.Title)); var similarity = metric.GetSimilarity(title.ToLower(), imageTitle.ToLower()); return(similarity); }