fix stem length checking

Starting from the end and stopping at first match doesn't guarantee
correctness. Starting from the beginning does.
This commit is contained in:
siikamiika 2019-10-30 12:04:49 +02:00
parent c35a05cd62
commit d19f447b80

View File

@ -90,9 +90,10 @@ async function apiTextParse(text, optionsContext) {
definitions = dictTermsSort(definitions);
const {expression, source, reading} = definitions[0];
let stemLength = source.length;
while (source[stemLength - 1] !== expression[stemLength - 1]) {
--stemLength;
let stemLength = 0;
const shortest = Math.min(source.length, expression.length);
while (stemLength < shortest && source[stemLength] === expression[stemLength]) {
++stemLength;
}
const offset = source.length - stemLength;