0

I need to cross names from two lists. What is the best away to compare the names? As you may expect, in one list we can have the complete name, on the other just the first and last.

Besides that, since the list are user typed there are always differences between the names, especially one the enterprise's ones.

So far I am using the Levenshtein distance algorithm. Is there any better algorithm? Or any considerations I should make?

public static int Compute(string s, string t)
{
int n = s.Length;
int m = t.Length;
int[,] d = new int[n + 1, m + 1];

// Step 1
if (n == 0)
{
    return m;
}

if (m == 0)
{
    return n;
}

// Step 2
for (int i = 0; i <= n; d[i, 0] = i++)
{
}

for (int j = 0; j <= m; d[0, j] = j++)
{
}

// Step 3
for (int i = 1; i <= n; i++)
{
    //Step 4
    for (int j = 1; j <= m; j++)
    {
    // Step 5
    int cost = (t[j - 1] == s[i - 1]) ? 0 : 1;

    // Step 6
    d[i, j] = Math.Min(
        Math.Min(d[i - 1, j] + 1, d[i, j - 1] + 1),
        d[i - 1, j - 1] + cost);
    }
}
// Step 7
return d[n, m];
}

So far, my main concern is the difference between the source and target parameter. Should the source be the most complete name or ii doesn't make a difference?

3
  • The Levenshtein distance is strictly a character-based measure. Human names have a rich internal structure and are very much not randomly distributed, therefore domain-specific algorithms will be much better. There is a huge body of work in this field; SOUNDEX was in fact patented in 1918! Apr 24, 2015 at 8:50
  • "Soundex is a phonetic algorithm for indexing names by sound, as pronounced in English." And for non English names?
    – cap7
    Apr 24, 2015 at 8:53
  • See here: stackoverflow.com/questions/127592/… Apr 24, 2015 at 8:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy