aboutsummaryrefslogtreecommitdiff
path: root/ext/js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-03-25 21:40:27 -0400
committerGitHub <noreply@github.com>2021-03-25 21:40:27 -0400
commit4ddd3ec80cc0682a46c2d3fed137a5fa7657c5b0 (patch)
treeed3fafd7630396118d576c54c69afa98b3656b07 /ext/js
parent6af0ee26b943d87e25b5d7ff9b8cade6999b3660 (diff)
Fix incorrect sorting (#1557)
* Sort by the maximum length of transformedText instead of deinflectedText * Update docs * Update tests
Diffstat (limited to 'ext/js')
-rw-r--r--ext/js/language/translator.js17
1 files changed, 9 insertions, 8 deletions
diff --git a/ext/js/language/translator.js b/ext/js/language/translator.js
index 934c8e4a..5f3d5bcd 100644
--- a/ext/js/language/translator.js
+++ b/ext/js/language/translator.js
@@ -933,7 +933,7 @@ class Translator {
return {index, headwordIndex, dictionary, dictionaryIndex, dictionaryPriority, hasReading, frequency};
}
- _createTermDictionaryEntry(id, isPrimary, sequence, inflections, score, dictionaryIndex, dictionaryPriority, sourceTermExactMatchCount, maxDeinflectedTextLength, headwords, definitions) {
+ _createTermDictionaryEntry(id, isPrimary, sequence, inflections, score, dictionaryIndex, dictionaryPriority, sourceTermExactMatchCount, maxTransformedTextLength, headwords, definitions) {
return {
type: 'term',
id,
@@ -944,7 +944,7 @@ class Translator {
dictionaryIndex,
dictionaryPriority,
sourceTermExactMatchCount,
- maxDeinflectedTextLength,
+ maxTransformedTextLength,
headwords,
definitions,
pronunciations: [],
@@ -958,7 +958,7 @@ class Translator {
const {index: dictionaryIndex, priority: dictionaryPriority} = this._getDictionaryOrder(dictionary, enabledDictionaryMap);
const sourceTermExactMatchCount = (isPrimary && deinflectedText === expression ? 1 : 0);
const source = this._createSource(originalText, transformedText, deinflectedText, isPrimary);
- const maxDeinflectedTextLength = deinflectedText.length;
+ const maxTransformedTextLength = transformedText.length;
const headwordTagGroups = [];
const definitionTagGroups = [];
@@ -974,7 +974,7 @@ class Translator {
dictionaryIndex,
dictionaryPriority,
sourceTermExactMatchCount,
- maxDeinflectedTextLength,
+ maxTransformedTextLength,
[this._createTermHeadword(0, expression, reading, [source], headwordTagGroups)],
[this._createTermDefinition(0, [0], dictionary, definitionTagGroups, glossary)]
);
@@ -1000,7 +1000,7 @@ class Translator {
let score = Number.MIN_SAFE_INTEGER;
let dictionaryIndex = Number.MAX_SAFE_INTEGER;
let dictionaryPriority = Number.MIN_SAFE_INTEGER;
- let maxDeinflectedTextLength = 0;
+ let maxTransformedTextLength = 0;
let sourceTermExactMatchCount = 0;
let isPrimary = false;
const definitions = [];
@@ -1013,7 +1013,7 @@ class Translator {
dictionaryPriority = Math.max(dictionaryPriority, dictionaryEntry.dictionaryPriority);
if (dictionaryEntry.isPrimary) {
isPrimary = true;
- maxDeinflectedTextLength = Math.max(maxDeinflectedTextLength, dictionaryEntry.maxDeinflectedTextLength);
+ maxTransformedTextLength = Math.max(maxTransformedTextLength, dictionaryEntry.maxTransformedTextLength);
sourceTermExactMatchCount += dictionaryEntry.sourceTermExactMatchCount;
const dictionaryEntryInflections = dictionaryEntry.inflections;
if (inflections === null || dictionaryEntryInflections.length < inflections.length) {
@@ -1036,7 +1036,7 @@ class Translator {
dictionaryIndex,
dictionaryPriority,
sourceTermExactMatchCount,
- maxDeinflectedTextLength,
+ maxTransformedTextLength,
[...headwords.values()],
definitions
);
@@ -1176,11 +1176,12 @@ class Translator {
const stringComparer = this._stringComparer;
const compareFunction = (v1, v2) => {
// Sort by length of source term
- let i = v2.maxDeinflectedTextLength - v1.maxDeinflectedTextLength;
+ let i = v2.maxTransformedTextLength - v1.maxTransformedTextLength;
if (i !== 0) { return i; }
// Sort by the number of inflection reasons
i = v1.inflections.length - v2.inflections.length;
+ console.log({'v1.inflections': v1.inflections, 'v2.inflections': v2.inflections});
if (i !== 0) { return i; }
// Sort by how many terms exactly match the source (e.g. for exact kana prioritization)