summaryrefslogtreecommitdiff
path: root/ext/bg/js/api.js
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2019-11-05 15:56:45 +0200
committersiikamiika <siikamiika@users.noreply.github.com>2019-11-23 17:45:44 +0200
commit955e131f9673e006556bc2c5e0b3551a614ccc48 (patch)
treedcabce9d7e6008ef490d7e6316eae99008db1c70 /ext/bg/js/api.js
parent17003189888694da51d840dcf0464355bb342a4c (diff)
add parser selection options
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;
}