diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-04-18 18:08:02 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-18 18:08:02 -0400 |
commit | f9774b4ce985b9920cee8afec0f756e5e1bfc9fa (patch) | |
tree | 0c89f0eeeb09e40bbf96145266bb6bcfbae9ae99 /ext | |
parent | 609d4fe3347f87290a428e2ba1192acb991b2e38 (diff) |
Improve dictionary sequence info (#1617)
* Ensure negative sequence is always -1
* Expose sequence on definition objects
* Update how sequence is exposed for definitions
* Update test data
* Update TS docs
Diffstat (limited to 'ext')
-rw-r--r-- | ext/js/data/anki-note-data-creator.js | 3 | ||||
-rw-r--r-- | ext/js/language/translator.js | 22 |
2 files changed, 13 insertions, 12 deletions
diff --git a/ext/js/data/anki-note-data-creator.js b/ext/js/data/anki-note-data-creator.js index e3ff2ca0..1cd5aaf4 100644 --- a/ext/js/data/anki-note-data-creator.js +++ b/ext/js/data/anki-note-data-creator.js @@ -354,7 +354,7 @@ class AnkiNoteDataCreator { const definitions = []; const definitionTags = []; - for (const {tags, headwordIndices, entries, dictionary} of dictionaryEntry.definitions) { + for (const {tags, headwordIndices, entries, dictionary, sequence} of dictionaryEntry.definitions) { const definitionTags2 = []; for (const tag of tags) { definitionTags.push(this._convertTag(tag)); @@ -362,7 +362,6 @@ class AnkiNoteDataCreator { } if (!hasDefinitions) { continue; } const only = merged ? DictionaryDataUtil.getDisambiguations(dictionaryEntry.headwords, headwordIndices, allTermsSet, allReadingsSet) : void 0; - const {sequence} = dictionaryEntry; definitions.push({ sequence, dictionary, diff --git a/ext/js/language/translator.js b/ext/js/language/translator.js index 28634f9c..1e335ac3 100644 --- a/ext/js/language/translator.js +++ b/ext/js/language/translator.js @@ -927,8 +927,8 @@ class Translator { return {index, term, reading, sources, tags, wordClasses}; } - _createTermDefinition(index, headwordIndices, dictionary, tags, entries) { - return {index, headwordIndices, dictionary, tags, entries}; + _createTermDefinition(index, headwordIndices, dictionary, sequence, tags, entries) { + return {index, headwordIndices, dictionary, sequence, tags, entries}; } _createTermPronunciation(index, headwordIndex, dictionary, dictionaryIndex, dictionaryPriority, pitches) { @@ -960,12 +960,14 @@ class Translator { } _createTermDictionaryEntryFromDatabaseEntry(databaseEntry, originalText, transformedText, deinflectedText, reasons, isPrimary, enabledDictionaryMap) { - const {term, reading: rawReading, definitionTags, termTags, definitions, score, dictionary, id, sequence, rules} = databaseEntry; + const {term, reading: rawReading, definitionTags, termTags, definitions, score, dictionary, id, sequence: rawSequence, rules} = databaseEntry; const reading = (rawReading.length > 0 ? rawReading : term); const {index: dictionaryIndex, priority: dictionaryPriority} = this._getDictionaryOrder(dictionary, enabledDictionaryMap); const sourceTermExactMatchCount = (isPrimary && deinflectedText === term ? 1 : 0); const source = this._createSource(originalText, transformedText, deinflectedText, isPrimary); const maxTransformedTextLength = transformedText.length; + const hasSequence = (rawSequence >= 0); + const sequence = hasSequence ? rawSequence : -1; const headwordTagGroups = []; const definitionTagGroups = []; @@ -976,7 +978,7 @@ class Translator { id, isPrimary, sequence, - sequence >= 0 ? dictionary : null, + hasSequence ? dictionary : null, reasons, score, dictionaryIndex, @@ -984,7 +986,7 @@ class Translator { sourceTermExactMatchCount, maxTransformedTextLength, [this._createTermHeadword(0, term, reading, [source], headwordTagGroups, rules)], - [this._createTermDefinition(0, [0], dictionary, definitionTagGroups, definitions)] + [this._createTermDefinition(0, [0], dictionary, sequence, definitionTagGroups, definitions)] ); } @@ -1148,21 +1150,21 @@ class Translator { } _addTermDefinitions(definitions, newDefinitions, headwordIndexMap) { - for (const {headwordIndices, dictionary, tags, entries} of newDefinitions) { + for (const {headwordIndices, dictionary, sequence, tags, entries} of newDefinitions) { const headwordIndicesNew = []; for (const headwordIndex of headwordIndices) { headwordIndicesNew.push(headwordIndexMap[headwordIndex]); } - definitions.push(this._createTermDefinition(definitions.length, headwordIndicesNew, dictionary, tags, entries)); + definitions.push(this._createTermDefinition(definitions.length, headwordIndicesNew, dictionary, sequence, tags, entries)); } } _addTermDefinitions2(definitions, definitionsMap, newDefinitions, headwordIndexMap) { - for (const {headwordIndices, dictionary, tags, entries} of newDefinitions) { - const key = this._createMapKey([dictionary, ...entries]); + for (const {headwordIndices, dictionary, sequence, tags, entries} of newDefinitions) { + const key = this._createMapKey([dictionary, sequence, ...entries]); let definition = definitionsMap.get(key); if (typeof definition === 'undefined') { - definition = this._createTermDefinition(definitions.length, [], dictionary, [], [...entries]); + definition = this._createTermDefinition(definitions.length, [], dictionary, sequence, [], [...entries]); definitions.push(definition); definitionsMap.set(key, definition); } |