From de6db32aa69be6c33d17ddb4f2dc4305e8771f59 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Fri, 14 May 2021 19:26:27 -0400 Subject: Improve source term exact match count (#1674) * Update sourceTermExactMatchCount to be based on headword count * Update tests --- ext/js/language/translator.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'ext/js') diff --git a/ext/js/language/translator.js b/ext/js/language/translator.js index 21ea9daf..d416d405 100644 --- a/ext/js/language/translator.js +++ b/ext/js/language/translator.js @@ -1007,7 +1007,6 @@ class Translator { let dictionaryIndex = Number.MAX_SAFE_INTEGER; let dictionaryPriority = Number.MIN_SAFE_INTEGER; let maxTransformedTextLength = 0; - let sourceTermExactMatchCount = 0; let isPrimary = false; const definitions = []; const definitionsMap = checkDuplicateDefinitions ? new Map() : null; @@ -1020,7 +1019,6 @@ class Translator { if (dictionaryEntry.isPrimary) { isPrimary = true; maxTransformedTextLength = Math.max(maxTransformedTextLength, dictionaryEntry.maxTransformedTextLength); - sourceTermExactMatchCount += dictionaryEntry.sourceTermExactMatchCount; const dictionaryEntryInflections = dictionaryEntry.inflections; if (inflections === null || dictionaryEntryInflections.length < inflections.length) { inflections = dictionaryEntryInflections; @@ -1033,6 +1031,18 @@ class Translator { } } + const headwordsArray = [...headwords.values()]; + + let sourceTermExactMatchCount = 0; + for (const {term, sources} of headwordsArray) { + for (const {deinflectedText, isPrimary: isPrimary2} of sources) { + if (isPrimary2 && deinflectedText === term) { + ++sourceTermExactMatchCount; + break; + } + } + } + return this._createTermDictionaryEntry( -1, isPrimary, @@ -1042,7 +1052,7 @@ class Translator { dictionaryPriority, sourceTermExactMatchCount, maxTransformedTextLength, - [...headwords.values()], + headwordsArray, definitions ); } -- cgit v1.2.3