|
81 | 81 | * @param {string} [options_p.wildcards] - characters that will be used as wildcards if provided
|
82 | 82 | * @param {number} [options_p.astral] - Use astral aware calculation
|
83 | 83 | * @param {string} [options_p.normalize] - Normalize unicode representations
|
| 84 | + * @param {string} [options_p.ratio_alg] - a string representing the ratio algorithm to use, either "levenshtein" or "difflib", default "levenshtein" |
| 85 | + * @param {boolean} [options_p.autojunk] - autojunk argument passed to difflib if you're using the ratio_alg option, default true |
84 | 86 | * @returns {number} - the levenshtein ratio (0-100).
|
85 | 87 | */
|
86 | 88 | var options = clone_and_set_option_defaults(options_p);
|
|
108 | 110 | * @param {string} [options_p.wildcards] - characters that will be used as wildcards if provided
|
109 | 111 | * @param {number} [options_p.astral] - Use astral aware calculation
|
110 | 112 | * @param {string} [options_p.normalize] - Normalize unicode representations
|
| 113 | + * @param {boolean} [options_p.autojunk] - autojunk argument passed to difflib, default true |
111 | 114 | * @returns {number} - the levenshtein ratio (0-100).
|
112 | 115 | */
|
113 | 116 | var options = clone_and_set_option_defaults(options_p);
|
|
136 | 139 | * @param {string} [options_p.wildcards] - characters that will be used as wildcards if provided
|
137 | 140 | * @param {number} [options_p.astral] - Use astral aware calculation
|
138 | 141 | * @param {string} [options_p.normalize] - Normalize unicode representations
|
| 142 | + * @param {string} [options_p.ratio_alg] - a string representing the ratio algorithm to use, either "levenshtein" or "difflib", default "levenshtein" |
| 143 | + * @param {boolean} [options_p.autojunk] - autojunk argument passed to difflib if you're using the ratio_alg option, default true |
139 | 144 | * @returns {number} - the levenshtein ratio (0-100).
|
140 | 145 | */
|
141 | 146 | var options = clone_and_set_option_defaults(options_p);
|
|
164 | 169 | * @param {string} [options_p.wildcards] - characters that will be used as wildcards if provided
|
165 | 170 | * @param {number} [options_p.astral] - Use astral aware calculation
|
166 | 171 | * @param {string} [options_p.normalize] - Normalize unicode representations
|
| 172 | + * @param {boolean} [options_p.autojunk] - autojunk argument passed to difflib, default true |
167 | 173 | * @returns {number} - the levenshtein ratio (0-100).
|
168 | 174 | */
|
169 | 175 | var options = clone_and_set_option_defaults(options_p);
|
|
191 | 197 | * @param {string} [options_p.wildcards] - characters that will be used as wildcards if provided
|
192 | 198 | * @param {number} [options_p.astral] - Use astral aware calculation
|
193 | 199 | * @param {string} [options_p.normalize] - Normalize unicode representations
|
| 200 | + * @param {string} [options_p.ratio_alg] - a string representing the ratio algorithm to use, either "levenshtein" or "difflib", default "levenshtein" |
| 201 | + * @param {boolean} [options_p.autojunk] - autojunk argument passed to difflib if you're using the ratio_alg option, default true |
194 | 202 | * @returns {number} - the levenshtein ratio (0-100).
|
195 | 203 | */
|
196 | 204 | var options = clone_and_set_option_defaults(options_p);
|
|
221 | 229 | * @param {string} [options_p.wildcards] - characters that will be used as wildcards if provided
|
222 | 230 | * @param {number} [options_p.astral] - Use astral aware calculation
|
223 | 231 | * @param {string} [options_p.normalize] - Normalize unicode representations
|
| 232 | + * @param {boolean} [options_p.autojunk] - autojunk argument passed to difflib, default true |
224 | 233 | * @returns {number} - the levenshtein ratio (0-100).
|
225 | 234 | */
|
226 | 235 | var options = clone_and_set_option_defaults(options_p);
|
|
252 | 261 | * @param {string} [options_p.wildcards] - characters that will be used as wildcards if provided
|
253 | 262 | * @param {number} [options_p.astral] - Use astral aware calculation
|
254 | 263 | * @param {string} [options_p.normalize] - Normalize unicode representations
|
| 264 | + * @param {string} [options_p.ratio_alg] - a string representing the ratio algorithm to use, either "levenshtein" or "difflib", default "levenshtein" |
| 265 | + * @param {boolean} [options_p.autojunk] - autojunk argument passed to difflib if you're using the ratio_alg option, default true |
255 | 266 | * @returns {number} - the levenshtein ratio (0-100).
|
256 | 267 | */
|
257 | 268 | var options = clone_and_set_option_defaults(options_p);
|
|
278 | 289 | * @param {string} [options_p.wildcards] - characters that will be used as wildcards if provided
|
279 | 290 | * @param {number} [options_p.astral] - Use astral aware calculation
|
280 | 291 | * @param {string} [options_p.normalize] - Normalize unicode representations
|
| 292 | + * @param {boolean} [options_p.autojunk] - autojunk argument passed to difflib, default true |
281 | 293 | * @returns {number} - the levenshtein ratio (0-100).
|
282 | 294 | */
|
283 | 295 | var options = clone_and_set_option_defaults(options_p);
|
|
364 | 376 | * @param {boolean} [options_p.sortBySimilarity] - sort tokens by similarity to each other before combining instead of alphabetically
|
365 | 377 | * @param {string} [options_p.wildcards] - characters that will be used as wildcards if provided
|
366 | 378 | * @param {boolean} [options_p.returnObjects] - return array of object instead of array of tuples; default false
|
| 379 | + * @param {string} [options_p.ratio_alg] - a string representing the ratio algorithm to use, either "levenshtein" or "difflib", default "levenshtein" |
| 380 | + * @param {boolean} [options_p.autojunk] - autojunk argument passed to difflib if you're using the ratio_alg option, default true |
367 | 381 | * @returns {Array[] | Object[]} - array of choice results with their computed ratios (0-100).
|
368 | 382 | */
|
369 | 383 | var options = clone_and_set_option_defaults(options_p);
|
|
510 | 524 | * @param {Object} [options_p.abortController] - track abortion
|
511 | 525 | * @param {Object} [options_p.cancelToken] - track cancellation
|
512 | 526 | * @param {number} [options_p.asyncLoopOffset] - number of rows to run in between every async loop iteration, default 256
|
| 527 | + * @param {string} [options_p.ratio_alg] - a string representing the ratio algorithm to use, either "levenshtein" or "difflib", default "levenshtein" |
| 528 | + * @param {boolean} [options_p.autojunk] - autojunk argument passed to difflib if you're using the ratio_alg option, default true |
513 | 529 | * @param {function} callback - node style callback (err, arrayOfResults)
|
514 | 530 | */
|
515 | 531 | var options = clone_and_set_option_defaults(options_p);
|
|
894 | 910 | if (!validate(str1)) return 0;
|
895 | 911 | if (!validate(str2)) return 0;
|
896 | 912 | if (options.ratio_alg && options.ratio_alg === "difflib") {
|
897 |
| - var m = new SequenceMatcher(null, str1, str2); |
| 913 | + var m = new SequenceMatcher(null, str1, str2, options.autojunk); |
898 | 914 | var r = m.ratio();
|
899 | 915 | return Math.round(100 * r);
|
900 | 916 | }
|
|
929 | 945 | var shorter = str2
|
930 | 946 | var longer = str1
|
931 | 947 | }
|
932 |
| - var m = new SequenceMatcher(null, shorter, longer); |
| 948 | + var m = new SequenceMatcher(null, shorter, longer, options.autojunk); |
933 | 949 | var blocks = m.getMatchingBlocks();
|
934 | 950 | var scores = [];
|
935 | 951 | for (var b = 0; b < blocks.length; b++) {
|
|
0 commit comments