Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
hubot-natural
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ar-noc
hubot-natural
Commits
b169f62e
Commit
b169f62e
authored
5 years ago
by
Ashwin Ganesh
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
32f11b8b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
EditDistance.cs
+36
-0
36 additions, 0 deletions
EditDistance.cs
with
36 additions
and
0 deletions
EditDistance.cs
0 → 100644
+
36
−
0
View file @
b169f62e
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
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment