Use findKanjiBulk and findKanjiMetaBulk in Translator.findKanji
This commit is contained in:
parent
d212d0aba1
commit
a25167df73
@ -277,33 +277,44 @@ class Translator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async findKanji(text, dictionaries) {
|
async findKanji(text, dictionaries) {
|
||||||
let definitions = [];
|
|
||||||
const processed = {};
|
|
||||||
const titles = Object.keys(dictionaries);
|
const titles = Object.keys(dictionaries);
|
||||||
|
const kanjiUnique = {};
|
||||||
|
const kanjiList = [];
|
||||||
for (const c of text) {
|
for (const c of text) {
|
||||||
if (!processed[c]) {
|
if (!kanjiUnique.hasOwnProperty(c)) {
|
||||||
definitions.push(...await this.database.findKanji(c, titles));
|
kanjiList.push(c);
|
||||||
processed[c] = true;
|
kanjiUnique[c] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const definitions = await this.database.findKanjiBulk(kanjiList, titles);
|
||||||
|
if (definitions.length === 0) {
|
||||||
|
return definitions;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (definitions.length > 1) {
|
||||||
|
definitions.sort((a, b) => a.index - b.index);
|
||||||
|
}
|
||||||
|
|
||||||
|
const kanjiList2 = [];
|
||||||
for (const definition of definitions) {
|
for (const definition of definitions) {
|
||||||
|
kanjiList2.push(definition.character);
|
||||||
|
|
||||||
const tags = await this.expandTags(definition.tags, definition.dictionary);
|
const tags = await this.expandTags(definition.tags, definition.dictionary);
|
||||||
tags.push(dictTagBuildSource(definition.dictionary));
|
tags.push(dictTagBuildSource(definition.dictionary));
|
||||||
|
|
||||||
definition.tags = dictTagsSort(tags);
|
definition.tags = dictTagsSort(tags);
|
||||||
definition.stats = await this.expandStats(definition.stats, definition.dictionary);
|
definition.stats = await this.expandStats(definition.stats, definition.dictionary);
|
||||||
|
|
||||||
definition.frequencies = [];
|
definition.frequencies = [];
|
||||||
for (const meta of await this.database.findKanjiMeta(definition.character, titles)) {
|
}
|
||||||
if (meta.mode === 'freq') {
|
|
||||||
definition.frequencies.push({
|
for (const meta of await this.database.findKanjiMetaBulk(kanjiList2, titles)) {
|
||||||
character: meta.character,
|
if (meta.mode !== 'freq') { continue; }
|
||||||
frequency: meta.data,
|
definitions[meta.index].frequencies.push({
|
||||||
dictionary: meta.dictionary
|
character: meta.character,
|
||||||
});
|
frequency: meta.data,
|
||||||
}
|
dictionary: meta.dictionary
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return definitions;
|
return definitions;
|
||||||
|
Loading…
Reference in New Issue
Block a user