Improve source term exact match count (#1674)
* Update sourceTermExactMatchCount to be based on headword count * Update tests
This commit is contained in:
parent
ff9dafc6f7
commit
de6db32aa6
@ -1007,7 +1007,6 @@ class Translator {
|
|||||||
let dictionaryIndex = Number.MAX_SAFE_INTEGER;
|
let dictionaryIndex = Number.MAX_SAFE_INTEGER;
|
||||||
let dictionaryPriority = Number.MIN_SAFE_INTEGER;
|
let dictionaryPriority = Number.MIN_SAFE_INTEGER;
|
||||||
let maxTransformedTextLength = 0;
|
let maxTransformedTextLength = 0;
|
||||||
let sourceTermExactMatchCount = 0;
|
|
||||||
let isPrimary = false;
|
let isPrimary = false;
|
||||||
const definitions = [];
|
const definitions = [];
|
||||||
const definitionsMap = checkDuplicateDefinitions ? new Map() : null;
|
const definitionsMap = checkDuplicateDefinitions ? new Map() : null;
|
||||||
@ -1020,7 +1019,6 @@ class Translator {
|
|||||||
if (dictionaryEntry.isPrimary) {
|
if (dictionaryEntry.isPrimary) {
|
||||||
isPrimary = true;
|
isPrimary = true;
|
||||||
maxTransformedTextLength = Math.max(maxTransformedTextLength, dictionaryEntry.maxTransformedTextLength);
|
maxTransformedTextLength = Math.max(maxTransformedTextLength, dictionaryEntry.maxTransformedTextLength);
|
||||||
sourceTermExactMatchCount += dictionaryEntry.sourceTermExactMatchCount;
|
|
||||||
const dictionaryEntryInflections = dictionaryEntry.inflections;
|
const dictionaryEntryInflections = dictionaryEntry.inflections;
|
||||||
if (inflections === null || dictionaryEntryInflections.length < inflections.length) {
|
if (inflections === null || dictionaryEntryInflections.length < inflections.length) {
|
||||||
inflections = dictionaryEntryInflections;
|
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(
|
return this._createTermDictionaryEntry(
|
||||||
-1,
|
-1,
|
||||||
isPrimary,
|
isPrimary,
|
||||||
@ -1042,7 +1052,7 @@ class Translator {
|
|||||||
dictionaryPriority,
|
dictionaryPriority,
|
||||||
sourceTermExactMatchCount,
|
sourceTermExactMatchCount,
|
||||||
maxTransformedTextLength,
|
maxTransformedTextLength,
|
||||||
[...headwords.values()],
|
headwordsArray,
|
||||||
definitions
|
definitions
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -8933,7 +8933,7 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"sourceTermExactMatchCount": 2,
|
"sourceTermExactMatchCount": 1,
|
||||||
"screenshotFileName": null,
|
"screenshotFileName": null,
|
||||||
"clipboardImageFileName": null,
|
"clipboardImageFileName": null,
|
||||||
"clipboardText": null,
|
"clipboardText": null,
|
||||||
@ -9261,7 +9261,7 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"sourceTermExactMatchCount": 2,
|
"sourceTermExactMatchCount": 1,
|
||||||
"screenshotFileName": null,
|
"screenshotFileName": null,
|
||||||
"clipboardImageFileName": null,
|
"clipboardImageFileName": null,
|
||||||
"clipboardText": null,
|
"clipboardText": null,
|
||||||
@ -9539,7 +9539,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"pitches": [],
|
"pitches": [],
|
||||||
"sourceTermExactMatchCount": 2,
|
"sourceTermExactMatchCount": 1,
|
||||||
"screenshotFileName": null,
|
"screenshotFileName": null,
|
||||||
"clipboardImageFileName": null,
|
"clipboardImageFileName": null,
|
||||||
"clipboardText": null,
|
"clipboardText": null,
|
||||||
@ -9791,7 +9791,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"pitches": [],
|
"pitches": [],
|
||||||
"sourceTermExactMatchCount": 2,
|
"sourceTermExactMatchCount": 1,
|
||||||
"screenshotFileName": null,
|
"screenshotFileName": null,
|
||||||
"clipboardImageFileName": null,
|
"clipboardImageFileName": null,
|
||||||
"clipboardText": null,
|
"clipboardText": null,
|
||||||
@ -10745,7 +10745,7 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"sourceTermExactMatchCount": 4,
|
"sourceTermExactMatchCount": 2,
|
||||||
"screenshotFileName": null,
|
"screenshotFileName": null,
|
||||||
"clipboardImageFileName": null,
|
"clipboardImageFileName": null,
|
||||||
"clipboardText": null,
|
"clipboardText": null,
|
||||||
@ -11198,7 +11198,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"pitches": [],
|
"pitches": [],
|
||||||
"sourceTermExactMatchCount": 4,
|
"sourceTermExactMatchCount": 2,
|
||||||
"screenshotFileName": null,
|
"screenshotFileName": null,
|
||||||
"clipboardImageFileName": null,
|
"clipboardImageFileName": null,
|
||||||
"clipboardText": null,
|
"clipboardText": null,
|
||||||
|
@ -5578,7 +5578,7 @@
|
|||||||
"score": 10,
|
"score": 10,
|
||||||
"dictionaryIndex": 0,
|
"dictionaryIndex": 0,
|
||||||
"dictionaryPriority": 0,
|
"dictionaryPriority": 0,
|
||||||
"sourceTermExactMatchCount": 2,
|
"sourceTermExactMatchCount": 1,
|
||||||
"maxTransformedTextLength": 4,
|
"maxTransformedTextLength": 4,
|
||||||
"headwords": [
|
"headwords": [
|
||||||
{
|
{
|
||||||
@ -5797,7 +5797,7 @@
|
|||||||
"score": 10,
|
"score": 10,
|
||||||
"dictionaryIndex": 0,
|
"dictionaryIndex": 0,
|
||||||
"dictionaryPriority": 0,
|
"dictionaryPriority": 0,
|
||||||
"sourceTermExactMatchCount": 2,
|
"sourceTermExactMatchCount": 1,
|
||||||
"maxTransformedTextLength": 4,
|
"maxTransformedTextLength": 4,
|
||||||
"headwords": [
|
"headwords": [
|
||||||
{
|
{
|
||||||
@ -5996,7 +5996,7 @@
|
|||||||
"score": 10,
|
"score": 10,
|
||||||
"dictionaryIndex": 0,
|
"dictionaryIndex": 0,
|
||||||
"dictionaryPriority": 0,
|
"dictionaryPriority": 0,
|
||||||
"sourceTermExactMatchCount": 2,
|
"sourceTermExactMatchCount": 1,
|
||||||
"maxTransformedTextLength": 2,
|
"maxTransformedTextLength": 2,
|
||||||
"headwords": [
|
"headwords": [
|
||||||
{
|
{
|
||||||
@ -6177,7 +6177,7 @@
|
|||||||
"score": 10,
|
"score": 10,
|
||||||
"dictionaryIndex": 0,
|
"dictionaryIndex": 0,
|
||||||
"dictionaryPriority": 0,
|
"dictionaryPriority": 0,
|
||||||
"sourceTermExactMatchCount": 2,
|
"sourceTermExactMatchCount": 1,
|
||||||
"maxTransformedTextLength": 2,
|
"maxTransformedTextLength": 2,
|
||||||
"headwords": [
|
"headwords": [
|
||||||
{
|
{
|
||||||
@ -6630,7 +6630,7 @@
|
|||||||
"score": 10,
|
"score": 10,
|
||||||
"dictionaryIndex": 0,
|
"dictionaryIndex": 0,
|
||||||
"dictionaryPriority": 0,
|
"dictionaryPriority": 0,
|
||||||
"sourceTermExactMatchCount": 4,
|
"sourceTermExactMatchCount": 2,
|
||||||
"maxTransformedTextLength": 4,
|
"maxTransformedTextLength": 4,
|
||||||
"headwords": [
|
"headwords": [
|
||||||
{
|
{
|
||||||
@ -7029,7 +7029,7 @@
|
|||||||
"score": 10,
|
"score": 10,
|
||||||
"dictionaryIndex": 0,
|
"dictionaryIndex": 0,
|
||||||
"dictionaryPriority": 0,
|
"dictionaryPriority": 0,
|
||||||
"sourceTermExactMatchCount": 4,
|
"sourceTermExactMatchCount": 2,
|
||||||
"maxTransformedTextLength": 2,
|
"maxTransformedTextLength": 2,
|
||||||
"headwords": [
|
"headwords": [
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user