Ejemplo n.º 1
0
        /// <summary>
        /// gets the similarity of the two strings using Monge Elkan.
        /// </summary>
        /// <param name="firstWord"></param>
        /// <param name="secondWord"></param>
        /// <returns>a value between 0-1 of the similarity</returns>
        public override double GetSimilarity(string firstWord, string secondWord)
        {
            if ((firstWord != null) && (secondWord != null))
            {
                Collection <string> firstTokens  = tokeniser.Tokenize(firstWord);
                Collection <string> secondTokens = tokeniser.Tokenize(secondWord);

                double sumMatches = 0.0;
                for (int i = 0; i < firstTokens.Count; i++)
                {
                    string sToken   = firstTokens[i];
                    double maxFound = 0.0;
                    for (int j = 0; j < secondTokens.Count; j++)
                    {
                        string tToken = secondTokens[j];
                        double found  = internalStringMetric.GetSimilarity(sToken, tToken);
                        if (found > maxFound)
                        {
                            maxFound = found;
                        }
                    }
                    sumMatches += maxFound;
                }
                return(sumMatches / firstTokens.Count);
            }
            return(defaultMismatchScore);
        }
Ejemplo n.º 2
0
        public override double GetSimilarity(string firstWord, string secondWord)
        {
            if (firstWord == null || secondWord == null)
            {
                return(DefaultMismatchScore);
            }

            Collection <string> collection  = Tokeniser.Tokenize(firstWord);
            Collection <string> collection2 = Tokeniser.Tokenize(secondWord);
            double num = 0.0;

            for (int i = 0; i < collection.Count; i++)
            {
                string str  = collection[i];
                double num3 = 0.0;
                for (int j = 0; j < collection2.Count; j++)
                {
                    string str2       = collection2[j];
                    double similarity = _internalStringMetric.GetSimilarity(str, str2);
                    if (similarity > num3)
                    {
                        num3 = similarity;
                    }
                }
                num += num3;
            }
            return(num / collection.Count);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// gets the similarity measure of the JaroWinkler metric for the given strings.
 /// </summary>
 /// <param name="firstWord"></param>
 /// <param name="secondWord"></param>
 /// <returns>0-1 similarity measure of the JaroWinkler metric</returns>
 public override double GetSimilarity(string firstWord, string secondWord)
 {
     if ((firstWord != null) && (secondWord != null))
     {
         double dist         = jaroStringMetric.GetSimilarity(firstWord, secondWord);
         int    prefixLength = GetPrefixLength(firstWord, secondWord);
         return(dist + prefixLength * prefixAdustmentScale * (1.0 - dist));
     }
     return(0.0);
 }
Ejemplo n.º 4
0
 public override double GetSimilarity(string firstWord, string secondWord)
 {
     if (firstWord != null && secondWord != null)
     {
         double similarity   = _jaroStringMetric.GetSimilarity(firstWord, secondWord);
         int    prefixLength = GetPrefixLength(firstWord, secondWord);
         return(similarity + prefixLength * PrefixAdustmentScale * (1.0 - similarity));
     }
     return(DefaultMismatchScore);
 }
Ejemplo n.º 5
0
 public static StringDistanceResult MeasureDistance(this AbstractStringMetric metric, string a, string b)
 {
     return(new StringDistanceResult
     {
         Similarity = metric.GetSimilarity(a, b),
         UnnormalizedSimilarity = metric.GetUnnormalisedSimilarity(a, b),
         MetricAlgorithm = metric,
         SimilarityDescription = metric.GetSimilarityExplained(a, b),
         ShortDescription = metric.ShortDescriptionString,
         LongDescription = metric.LongDescriptionString
     });
 }