diff options
author | Alex Yatskov <alex@foosoft.net> | 2020-04-18 11:05:35 -0700 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2020-04-18 11:05:35 -0700 |
commit | f2186c51e4ef219d158735d30a32bbf3e49c4e1a (patch) | |
tree | 61de35513b6182e83b626c1571bc2aa97234e3b0 /ext/bg/js/mecab.js | |
parent | b3e79d0e396353de2cbefb945412bfda4bd6ca99 (diff) | |
parent | 9e7750125c40d1c4121e8d015957606721bede7c (diff) |
Merge branch 'master' into testing
Diffstat (limited to 'ext/bg/js/mecab.js')
-rw-r--r-- | ext/bg/js/mecab.js | 31 |
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() { |