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); definitions = dictTermsSort(definitions);
const {expression, source, reading} = definitions[0]; const {expression, source, reading} = definitions[0];
let stemLength = source.length; let stemLength = 0;
while (source[stemLength - 1] !== expression[stemLength - 1]) { const shortest = Math.min(source.length, expression.length);
--stemLength; while (stemLength < shortest && source[stemLength] === expression[stemLength]) {
++stemLength;
} }
const offset = source.length - stemLength; const offset = source.length - stemLength;