cleanup
This commit is contained in:
parent
33d9d6ff57
commit
f5009cd63c
@ -31,7 +31,7 @@ async function apiTermsFind(text) {
|
|||||||
|
|
||||||
const searcher = options.general.groupResults ?
|
const searcher = options.general.groupResults ?
|
||||||
translator.findTermsGrouped.bind(translator) :
|
translator.findTermsGrouped.bind(translator) :
|
||||||
translator.findTerms.bind(translator);
|
translator.findTermsSplit.bind(translator);
|
||||||
|
|
||||||
const {definitions, length} = await searcher(
|
const {definitions, length} = await searcher(
|
||||||
text,
|
text,
|
||||||
|
@ -37,8 +37,26 @@ class Translator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async findTermsGrouped(text, dictionaries, alphanumeric) {
|
async findTermsGrouped(text, dictionaries, alphanumeric) {
|
||||||
|
const titles = Object.keys(dictionaries);
|
||||||
const {length, definitions} = await this.findTerms(text, dictionaries, alphanumeric);
|
const {length, definitions} = await this.findTerms(text, dictionaries, alphanumeric);
|
||||||
return {length, definitions: dictTermsGroup(definitions, dictionaries)};
|
|
||||||
|
const definitionsGrouped = dictTermsGroup(definitions, dictionaries);
|
||||||
|
for (const definition of definitionsGrouped) {
|
||||||
|
this.buildTermFrequencies(definition, titles);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {length, definitions: definitionsGrouped};
|
||||||
|
}
|
||||||
|
|
||||||
|
async findTermsSplit(text, dictionaries, alphanumeric) {
|
||||||
|
const titles = Object.keys(dictionaries);
|
||||||
|
const {length, definitions} = await this.findTerms(text, dictionaries, alphanumeric);
|
||||||
|
|
||||||
|
for (const definition of definitions) {
|
||||||
|
this.buildTermFrequencies(definition, titles);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {length, definitions};
|
||||||
}
|
}
|
||||||
|
|
||||||
async findTerms(text, dictionaries, alphanumeric) {
|
async findTerms(text, dictionaries, alphanumeric) {
|
||||||
@ -63,13 +81,7 @@ class Translator {
|
|||||||
const tags = await this.buildTags(definition.tags, definition.dictionary);
|
const tags = await this.buildTags(definition.tags, definition.dictionary);
|
||||||
tags.push(dictTagBuildSource(definition.dictionary));
|
tags.push(dictTagBuildSource(definition.dictionary));
|
||||||
|
|
||||||
let frequencies = await this.database.findTermFreq(definition.expression, titles);
|
|
||||||
if (frequencies.length === 0) {
|
|
||||||
frequencies = await this.database.findTermFreq(definition.reading, titles);
|
|
||||||
}
|
|
||||||
|
|
||||||
definitions.push({
|
definitions.push({
|
||||||
frequencies,
|
|
||||||
source: deinflection.source,
|
source: deinflection.source,
|
||||||
reasons: deinflection.reasons,
|
reasons: deinflection.reasons,
|
||||||
score: definition.score,
|
score: definition.score,
|
||||||
@ -134,6 +146,13 @@ class Translator {
|
|||||||
return definitions;
|
return definitions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async buildTermFrequencies(definition, titles) {
|
||||||
|
definition.frequencies = await this.database.findTermFreq(definition.expression, titles);
|
||||||
|
if (definition.frequencies.length === 0) {
|
||||||
|
definition.frequencies = await this.database.findTermFreq(definition.reading, titles);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async buildTags(names, title) {
|
async buildTags(names, title) {
|
||||||
const results = [];
|
const results = [];
|
||||||
for (const name of names) {
|
for (const name of names) {
|
||||||
|
Loading…
Reference in New Issue
Block a user