Similitude/String/WeightedLevenshteinResolver.cs
/// <summary>
/// Compares two string and resolves a normalized value indicating their similarity.
/// The result is based on the number of single-character edits <see cref="GetDistance"/> between two strings
/// in relation to the maximum number of single-character edits possible for the longest provided string.
/// </summary>
/// <param name="first">The first string.</param>
/// <param name="second">The second string.</param>
/// <returns>A number in the range [0, 1].</returns>
Compares two string and resolves a normalized value indicating their similarity.
The result is based on the number of single-character edits  between two strings
in relation to the maximum number of single-character edits possible for the longest provided string.
Compares two string and resolves a normalized value indicating their similarity . The result is based on the number of single - character edits between two strings in relation to the maximum number of single - character edits possible for the longest provided string .
public virtual double GetSimilarity([NotNull] string first, [NotNull] string second)
        {
            var maxWeight = Math.Max(InsertionWeight, Math.Max(RemovalWeight, SubstitutaionWeight));
            var maxLength = Math.Max(first.Length, second.Length);
            var maxDistance = maxLength * maxWeight;
            if (maxDistance == 0)
            {
                return 0;
            }
            var distance = GetDistance(first, second);
            var normalizedSimilarity = (double) (maxDistance - distance) / maxDistance;
            return normalizedSimilarity;
        }
public virtual double GetSimilarity ( [ NotNull ] string first , [ NotNull ] string second ) { var maxWeight = Math . Max ( InsertionWeight , Math . Max ( RemovalWeight , SubstitutaionWeight ) ) ; var maxLength = Math . Max ( first . Length , second . Length ) ; var maxDistance = maxLength * maxWeight ; if ( maxDistance == 0 ) { return 0 ; } var distance = GetDistance ( first , second ) ; var normalizedSimilarity = ( double ) ( maxDistance - distance ) / maxDistance ; return normalizedSimilarity ; }
Compares two string and resolves a normalized value indicating their similarity.
Compares two string and resolves a normalized value indicating their similarity .
A number in the range [0, 1].
A number in the range [ 0 1 ] .
string
[NotNull]
first
The first string.
The first string .
second
The second string.
The second string .