示例#1
0
 ///<summary>
 /// Get Similarity Score
 ///</summary>
 ///<param name="word1">First Word</param>
 ///<param name="word2">Second Word</param>
 ///<param name="algorithm">String Distance Algorithm</param>
 ///<param name="kashefiConfig">Configuration of Kashefi's String Distance Method</param>
 ///<returns>Similarity Score</returns>
 public double GetWordSimilarity(string word1, string word2, StringDistanceAlgorithm algorithm, KashefiConfig kashefiConfig)
 {
     return(GetDifference(word1, word2, algorithm, true, kashefiConfig));
 }
示例#2
0
        private static double GetDifference(string word1, string word2, StringDistanceAlgorithm algorithm, bool exportAsSimilarity, KashefiConfig kashefiConfig)
        {
            double distance = -1;

            StringDistanceAlgorithms.ExportResultAsSimilarity = exportAsSimilarity;

            if (algorithm == StringDistanceAlgorithm.Hamming)
            {
                distance = StringDistanceAlgorithms.Hamming(word1, word2);
            }
            else if (algorithm == StringDistanceAlgorithm.Levenestain)
            {
                distance = StringDistanceAlgorithms.Levenstein(word1, word2);
            }
            else if (algorithm == StringDistanceAlgorithm.GNULevenesain)
            {
                distance = StringDistanceAlgorithms.GNULevenstein(word1, word2);
            }
            else if (algorithm == StringDistanceAlgorithm.Kashefi)
            {
                distance = StringDistanceAlgorithms.KashefiMeasure(word1, word2, kashefiConfig);
            }
            else if (algorithm == StringDistanceAlgorithm.Needleman)
            {
                double          nGapCost = (kashefiConfig.DeleteGapCost + kashefiConfig.InsertGapCost) / 2.0;
                NeedlemanConfig nc       = new NeedlemanConfig(kashefiConfig.Keyboard, nGapCost, kashefiConfig.SubstituteGapCost);

                distance = StringDistanceAlgorithms.NeedlemanWunch(word1, word2, nc);
            }
            else if (algorithm == StringDistanceAlgorithm.JaroWinkler)
            {
                distance = StringDistanceAlgorithms.JaroWinckler(word1, word2);
            }
            else if (algorithm == StringDistanceAlgorithm.Cosine)
            {
                distance = StringDistanceAlgorithms.Cosine(word1, word2);
            }
            else if (algorithm == StringDistanceAlgorithm.DamerauLevenestain)
            {
                distance = StringDistanceAlgorithms.DamerauLevenstein(word1, word2);
            }
            else if (algorithm == StringDistanceAlgorithm.WagnerFischer)
            {
                distance = StringDistanceAlgorithms.WagnerFischer(word1, word2);
            }

            return(distance);
        }
示例#3
0
 ///<summary>
 /// Get String Distance
 ///</summary>
 ///<param name="word1">First Word</param>
 ///<param name="word2">Second Word</param>
 ///<param name="algorithm">String Distance Algorithm</param>
 ///<param name="kashefiConfig">Configuration of Kashefi's String Distance Method</param>
 ///<returns>String Distance</returns>
 public double GetStringDistance(string word1, string word2, StringDistanceAlgorithm algorithm, KashefiConfig kashefiConfig)
 {
     return(GetDifference(word1, word2, algorithm, false, kashefiConfig));
 }