Changed type returned by apiTextParseMecab to avoid using for in

This commit is contained in:
toasted-nutbread 2020-02-25 21:26:56 -05:00
parent 6bd714fec0
commit 7b97138ad1
2 changed files with 6 additions and 6 deletions

View File

@ -357,11 +357,11 @@ class Backend {
async _onApiTextParseMecab({text, optionsContext}) { async _onApiTextParseMecab({text, optionsContext}) {
const options = await this.getOptions(optionsContext); const options = await this.getOptions(optionsContext);
const results = {}; const results = [];
const rawResults = await this.mecab.parseText(text); const rawResults = await this.mecab.parseText(text);
for (const mecabName in rawResults) { for (const [mecabName, parsedLines] of Object.entries(rawResults)) {
const result = []; const result = [];
for (const parsedLine of rawResults[mecabName]) { for (const parsedLine of parsedLines) {
for (const {expression, reading, source} of parsedLine) { for (const {expression, reading, source} of parsedLine) {
const term = []; const term = [];
if (expression !== null && reading !== null) { if (expression !== null && reading !== null) {
@ -381,7 +381,7 @@ class Backend {
} }
result.push([{text: '\n'}]); result.push([{text: '\n'}]);
} }
results[mecabName] = result; results.push([mecabName, result]);
} }
return results; return results;
} }

View File

@ -142,11 +142,11 @@ class QueryParser extends TextScanner {
} }
if (this.search.options.parsing.enableMecabParser) { if (this.search.options.parsing.enableMecabParser) {
const mecabResults = await apiTextParseMecab(text, this.search.getOptionsContext()); const mecabResults = await apiTextParseMecab(text, this.search.getOptionsContext());
for (const mecabDictName in mecabResults) { for (const [mecabDictName, mecabDictResults] of mecabResults) {
results.push({ results.push({
name: `MeCab: ${mecabDictName}`, name: `MeCab: ${mecabDictName}`,
id: `mecab-${mecabDictName}`, id: `mecab-${mecabDictName}`,
parsedText: mecabResults[mecabDictName] parsedText: mecabDictResults
}); });
} }
} }