summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2020-04-13 22:14:23 +0300
committersiikamiika <siikamiika@users.noreply.github.com>2020-04-13 22:14:23 +0300
commit25bc86c3ce44bd7823d0d924e86969310c14dc8c (patch)
treead2a50f9fad8eebae1a116994e3e03281526aef9 /ext
parentc613321a735dbf333491ab199b808f30852a8daa (diff)
force empty mecab output properties to strings
Diffstat (limited to 'ext')
-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() {