aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/api.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg/js/api.js')
-rw-r--r--ext/bg/js/api.js37
1 files changed, 21 insertions, 16 deletions
diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js
index 2ab01af3..967bded7 100644
--- a/ext/bg/js/api.js
+++ b/ext/bg/js/api.js
@@ -109,25 +109,30 @@ async function apiTextParseMecab(text, optionsContext) {
const options = await apiOptionsGet(optionsContext);
const mecab = utilBackend().mecab;
- const results = [];
- for (const parsedLine of await mecab.parseText(text)) {
- for (const {expression, reading, source} of parsedLine) {
- const term = [];
- if (expression && reading) {
- for (const {text, furigana} of jpDistributeFuriganaInflected(
- expression,
- jpKatakanaToHiragana(reading),
- source
- )) {
- // can't use 'furigana' in templates
- term.push({text, reading: furigana});
+ const results = {};
+ const rawResults = await mecab.parseText(text);
+ for (const mecabName in rawResults) {
+ const result = [];
+ for (const parsedLine of rawResults[mecabName]) {
+ for (const {expression, reading, source} of parsedLine) {
+ const term = [];
+ if (expression && reading) {
+ for (const {text, furigana} of jpDistributeFuriganaInflected(
+ expression,
+ jpKatakanaToHiragana(reading),
+ source
+ )) {
+ // can't use 'furigana' in templates
+ term.push({text, reading: furigana});
+ }
+ } else {
+ term.push({text: source});
}
- } else {
- term.push({text: source});
+ result.push(term);
}
- results.push(term);
+ result.push([{text: '\n'}]);
}
- results.push([{text: '\n'}]);
+ results[mecabName] = result;
}
return results;
}