Skip to content
Snippets Groups Projects
Commit b169f62e authored by Ashwin Ganesh's avatar Ashwin Ganesh
Browse files

Upload New File

parent 32f11b8b
No related branches found
No related tags found
No related merge requests found
using System;
using SoftWx.Match;
public class EditDistance {
/// <summary>Wrapper for third party edit distance algorithms.</summary>
/// <summary>Supported edit distance algorithms.</summary>
public enum DistanceAlgorithm {
/// <summary>Levenshtein algorithm.</summary>
Levenshtein,
/// <summary>Damerau optimal string alignment algorithm.</summary>
DamerauOSA
}
private DistanceAlgorithm algorithm;
private IDistance distanceComparer;
/// <summary>Create a new EditDistance object.</summary>
/// <param name="algorithm">The desired edit distance algorithm.</param>
public EditDistance(DistanceAlgorithm algorithm) {
this.algorithm = algorithm;
switch (algorithm) {
case DistanceAlgorithm.DamerauOSA: this.distanceComparer = new DamerauOSA(); break;
case DistanceAlgorithm.Levenshtein: this.distanceComparer = new Levenshtein(); break;
default: throw new ArgumentException("Unknown distance algorithm.");
}
}
/// <summary>Compare a string to the base string to determine the edit distance,
/// using the previously selected algorithm.</summary>
/// <param name="string2">The string to compare.</param>
/// <param name="maxDistance">The maximum distance allowed.</param>
/// <returns>The edit distance (or -1 if maxDistance exceeded).</returns>
public int Compare(string string1, string string2, int maxDistance) {
return (int)this.distanceComparer.Distance(string1, string2, maxDistance);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment