74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
matrix[i][j] = Math.min(matrix[i][j], matrix[i-2][j-2] + nCost); // Transposition
}
}
}
return matrix[nLen1][nLen2];
}
catch (e) {
helpers.logerror(e);
}
},
distanceDamerauLevenshtein: function (s1, s2) {
// distance of Damerau-Levenshtein between <s1> and <s2>
// https://fr.wikipedia.org/wiki/Distance_de_Damerau-Levenshtein
try {
|
|
|
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
matrix[i][j] = Math.min(matrix[i][j], matrix[i-2][j-2] + nCost); // Transposition
}
}
}
return matrix[nLen1][nLen2];
}
catch (e) {
console.error(e);
}
},
distanceDamerauLevenshtein: function (s1, s2) {
// distance of Damerau-Levenshtein between <s1> and <s2>
// https://fr.wikipedia.org/wiki/Distance_de_Damerau-Levenshtein
try {
|
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
matrix[i+1][j+1] = Math.min(matrix[i+1][j+1], matrix[i1] ? matrix[i1][j1] + (i-i1-1) + 1 + (j-j1-1) : Infinity);
}
sd[s1[i-1]] = i;
}
return matrix[nLen1+1][nLen2+1];
}
catch (e) {
helpers.logerror(e);
}
},
showDistance (s1, s2) {
console.log(`Distance: ${s1} / ${s2} = ${this.distanceDamerauLevenshtein(s1, s2)})`);
},
|
|
|
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
matrix[i+1][j+1] = Math.min(matrix[i+1][j+1], matrix[i1] ? matrix[i1][j1] + (i-i1-1) + 1 + (j-j1-1) : Infinity);
}
sd[s1[i-1]] = i;
}
return matrix[nLen1+1][nLen2+1];
}
catch (e) {
console.error(e);
}
},
showDistance (s1, s2) {
console.log(`Distance: ${s1} / ${s2} = ${this.distanceDamerauLevenshtein(s1, s2)})`);
},
|
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
changeWordWithSuffixCode: function (sWord, sSfxCode) {
if (sSfxCode == "0") {
return sWord;
}
return sSfxCode[0] == '0' ? sWord + sSfxCode.slice(1) : sWord.slice(0, -(sSfxCode.charCodeAt(0)-48)) + sSfxCode.slice(1);
},
// Prefix and suffix
defineAffixCode: function (sFlex, sStem) {
/*
UNTESTED!
Returns a string defining how to get stem from flexion. Examples:
"0" if stem = flexion
"stem" if no common substring
"n(pfx)/m(sfx)"
with n and m: chars with numeric meaning, "0" = 0, "1" = 1, ... ":" = 10, etc. (See ASCII table.) Says how many letters to strip from flexion.
pfx [optional]: string to add before the flexion
sfx [optional]: string to add after the flexion
*/
if (sFlex == sStem) {
return "0";
}
// is stem a substring of flexion?
let n = sFlex.indexOf(sStem);
|
|
|
|
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
changeWordWithSuffixCode: function (sWord, sSfxCode) {
if (sSfxCode == "0") {
return sWord;
}
return sSfxCode[0] == '0' ? sWord + sSfxCode.slice(1) : sWord.slice(0, -(sSfxCode.charCodeAt(0)-48)) + sSfxCode.slice(1);
},
// Prefix and suffix
defineAffixCode: function (sFlex, sStem) {
/*
UNTESTED!
Returns a string defining how to get stem from flexion. Examples:
"0" if stem = flexion
"stem" if no common substring
"n(pfx)/m(sfx)"
with n and m: chars with numeric meaning, "0" = 0, "1" = 1, ... ":" = 10, etc. (See ASCII table.) Says how many letters to strip from flexion.
pfx [optional]: string to add before the flexion
sfx [optional]: string to add after the flexion
*/
if (sFlex == sStem) {
return "0";
}
// is stem a substring of flexion?
let n = sFlex.indexOf(sStem);
|