-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathJaroDistance.cs
29 lines (27 loc) · 1.13 KB
/
JaroDistance.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FuzzyString
{
public static partial class ComparisonMetrics
{
public static double JaroDistance(this string source, string target)
{
int m = source.Intersect(target).Count();
if (m == 0) { return 0; }
else
{
string sourceTargetIntersetAsString = "";
string targetSourceIntersetAsString = "";
IEnumerable<char> sourceIntersectTarget = source.Intersect(target);
IEnumerable<char> targetIntersectSource = target.Intersect(source);
foreach (char character in sourceIntersectTarget) { sourceTargetIntersetAsString += character; }
foreach (char character in targetIntersectSource) { targetSourceIntersetAsString += character; }
double t = sourceTargetIntersetAsString.LevenshteinDistance(targetSourceIntersetAsString) / 2;
return ((m / source.Length) + (m / target.Length) + ((m - t) / m)) / 3;
}
}
}
}