Skip to content

Commit a8e6cfa

Browse files
committed
fuzzy matcher example
1 parent e301c03 commit a8e6cfa

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Pattern.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Pattern.Matcher.prototype = {
3939
description: '',
4040
_pattern: null,
4141
_matcher: null,
42+
_err: 0,
4243

4344
dispose: function() {
4445
this._pattern = null;
@@ -75,6 +76,19 @@ Pattern.NaiveMatcher = new Pattern.Matcher(function naive_matcher(s, o) {
7576
'https://en.wikipedia.org/wiki/String_searching_algorithm',
7677
"This is a &quot;<i>naive</i>&quot; string search algorithm, in that it tests each succesive position of the input text to see if the pattern matches and does not exploit information about the pattern or the text in order to speed up the search."
7778
);
79+
Pattern.FuzzyMatcher = new Pattern.Matcher(function fuzzy_matcher(s, o) {
80+
var p = this._pattern, n = s.length, m = p.length, i, matcher;
81+
if (arguments.length < 2) o = 0;
82+
if (o < 0) o += n;
83+
if ((0 < n) && (0 < m) && (n >= o+m))
84+
{
85+
return (new Matchy.NFA(p, {errors:this._err || 1})).match(s, o);
86+
}
87+
return -1;
88+
},
89+
'https://en.wikipedia.org/wiki/Levenshtein_distance',
90+
"This is an approximate string search algorithm using Levenshtein distance to find matches that have at most k errors."
91+
);
7892
Pattern.FSAMatcher = new Pattern.Matcher(
7993
'fsa',
8094
'https://en.wikipedia.org/wiki/Finite-state_machine',

src/Pattern.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)