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