aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/mecab.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2020-04-16 17:30:09 -0700
committerAlex Yatskov <alex@foosoft.net>2020-04-16 17:30:09 -0700
commit93c4fb9eab2651da24fb816f20dcb967eae1437e (patch)
treedf8f6d5e04da7e6e78db4712d4d3d92c460454b9 /ext/bg/js/mecab.js
parent3b9a87b2ebe843e30536924639d6c14afef936cd (diff)
parent8c16a6e580bfdd70e27df1816ca90807062cf9b5 (diff)
Merge branch 'master' of https://github.com/FooSoft/yomichan
Diffstat (limited to 'ext/bg/js/mecab.js')
-rw-r--r--ext/bg/js/mecab.js31
1 files changed, 30 insertions, 1 deletions
diff --git a/ext/bg/js/mecab.js b/ext/bg/js/mecab.js
index cd6e6c57..597dceae 100644
--- a/ext/bg/js/mecab.js
+++ b/ext/bg/js/mecab.js
@@ -40,7 +40,36 @@ class Mecab {
}
async parseText(text) {
- return await this.invoke('parse_text', {text});
+ const rawResults = await this.invoke('parse_text', {text});
+ // {
+ // 'mecab-name': [
+ // // line1
+ // [
+ // {str expression: 'expression', str reading: 'reading', str source: 'source'},
+ // {str expression: 'expression2', str reading: 'reading2', str source: 'source2'}
+ // ],
+ // line2,
+ // ...
+ // ],
+ // 'mecab-name2': [...]
+ // }
+ const results = {};
+ for (const [mecabName, parsedLines] of Object.entries(rawResults)) {
+ const result = [];
+ for (const parsedLine of parsedLines) {
+ const line = [];
+ for (const {expression, reading, source} of parsedLine) {
+ line.push({
+ expression: expression || '',
+ reading: reading || '',
+ source: source || ''
+ });
+ }
+ result.push(line);
+ }
+ results[mecabName] = result;
+ }
+ return results;
}
startListener() {