-
Notifications
You must be signed in to change notification settings - Fork 5
/
example.js
46 lines (38 loc) · 1.36 KB
/
example.js
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var DL, distance;
DL = require('damerau-levenshtein');
distance = DL();
console.log("Default costs (1):");
console.log("Michael", "Michelle", distance("Michael", "Michelle"));
distance = DL({ insert: 2, remove: 2 });
console.log("Insert cost 2 and remove cost 2:");
console.log("Michael", "Michelle", distance("Michael", "Michelle"));
distance = DL({ transpose: 0.5 });
console.log("Transpose cost 0.5:");
console.log("Michael", "Michelle", distance("Michael", "Michelle"));
distance = DL();
console.log("With transposition activated (default):");
console.log("el", "le", distance("el", "le"));
distance = DL({}, false);
console.log("With transposition deactivated:");
console.log("el", "le", distance("el", "le"));
distance = DL({
transpose: function (backward, forward) {
if (backward === 'e') return 0.5;
else return 1;
}
});
console.log("With lower cost of transposing e backwards:");
console.log("el", "le", distance("el", "le"));
console.log("le", "el", distance("le", "el"));
distance = DL({
insert: 1,
remove: 0.5,
substitute: 0.8,
transpose: function (backward, forward) {
if (backward === 'n') return 0.5;
else return 1;
}
});
console.log("A strign", "Another string", distance("A strign", "Another string"));
distance = DL({}, false);
console.log("A strign", "Another string", distance("A strign", "Another string"));