Translator refactoring for consistency (#1619)

* Remove unused argument

* Improve naming in _groupDictionaryEntriesByHeadword

More consistent with _getRelatedDictionaryEntries.
This commit is contained in:
toasted-nutbread 2021-04-18 18:15:58 -04:00 committed by GitHub
parent 03dd1dc6ff
commit b40cfe0458
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -371,7 +371,7 @@ class Translator {
if (sequenceList.length > 0) { if (sequenceList.length > 0) {
const secondarySearchDictionaryMap = this._getSecondarySearchDictionaryMap(enabledDictionaryMap); const secondarySearchDictionaryMap = this._getSecondarySearchDictionaryMap(enabledDictionaryMap);
await this._addRelatedDictionaryEntries(groupedDictionaryEntries, ungroupedDictionaryEntriesMap, sequenceList, mainDictionary, enabledDictionaryMap); await this._addRelatedDictionaryEntries(groupedDictionaryEntries, ungroupedDictionaryEntriesMap, sequenceList, enabledDictionaryMap);
for (const group of groupedDictionaryEntries) { for (const group of groupedDictionaryEntries) {
this._sortTermDictionaryEntriesById(group.dictionaryEntries); this._sortTermDictionaryEntriesById(group.dictionaryEntries);
} }
@ -388,7 +388,7 @@ class Translator {
return newDictionaryEntries; return newDictionaryEntries;
} }
async _addRelatedDictionaryEntries(groupedDictionaryEntries, ungroupedDictionaryEntriesMap, sequenceList, mainDictionary, enabledDictionaryMap) { async _addRelatedDictionaryEntries(groupedDictionaryEntries, ungroupedDictionaryEntriesMap, sequenceList, enabledDictionaryMap) {
const databaseEntries = await this._database.findTermsBySequenceBulk(sequenceList); const databaseEntries = await this._database.findTermsBySequenceBulk(sequenceList);
for (const databaseEntry of databaseEntries) { for (const databaseEntry of databaseEntries) {
const {dictionaryEntries, ids} = groupedDictionaryEntries[databaseEntry.index]; const {dictionaryEntries, ids} = groupedDictionaryEntries[databaseEntry.index];
@ -474,20 +474,19 @@ class Translator {
for (const dictionaryEntry of dictionaryEntries) { for (const dictionaryEntry of dictionaryEntries) {
const {inflections, headwords: [{term, reading}]} = dictionaryEntry; const {inflections, headwords: [{term, reading}]} = dictionaryEntry;
const key = this._createMapKey([term, reading, ...inflections]); const key = this._createMapKey([term, reading, ...inflections]);
let dictionaryEntries2 = groups.get(key); let groupDictionaryEntries = groups.get(key);
if (typeof dictionaryEntries2 === 'undefined') { if (typeof groupDictionaryEntries === 'undefined') {
dictionaryEntries2 = []; groupDictionaryEntries = [];
groups.set(key, dictionaryEntries2); groups.set(key, groupDictionaryEntries);
} }
dictionaryEntries2.push(dictionaryEntry); groupDictionaryEntries.push(dictionaryEntry);
} }
const results = []; const newDictionaryEntries = [];
for (const dictionaryEntries2 of groups.values()) { for (const groupDictionaryEntries of groups.values()) {
const dictionaryEntry = this._createGroupedDictionaryEntry(dictionaryEntries2, false); newDictionaryEntries.push(this._createGroupedDictionaryEntry(groupDictionaryEntries, false));
results.push(dictionaryEntry);
} }
return results; return newDictionaryEntries;
} }
// Tags // Tags