summaryrefslogtreecommitdiff
path: root/ext/bg
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2020-04-13 22:55:33 +0300
committersiikamiika <siikamiika@users.noreply.github.com>2020-04-13 22:55:33 +0300
commitf93dc857107e9b23ec06f1b568aad2c6f870ba4c (patch)
tree8d691c01e3e6a449c6530402398d60cc0b76cc7e /ext/bg
parent25bc86c3ce44bd7823d0d924e86969310c14dc8c (diff)
assume and propagate strings for text parsing
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/js/backend.js26
-rw-r--r--ext/bg/js/japanese.js10
-rw-r--r--ext/bg/js/search-query-parser-generator.js2
-rw-r--r--ext/bg/js/search-query-parser.js2
4 files changed, 18 insertions, 22 deletions
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index 65e00f28..d5086af2 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -334,7 +334,7 @@ class Backend {
}
text = text.substring(source.length);
} else {
- const reading = jp.convertReading(text[0], null, options.parsing.readingMode);
+ const reading = jp.convertReading(text[0], '', options.parsing.readingMode);
term.push({text: text[0], reading});
text = text.substring(1);
}
@@ -349,24 +349,20 @@ class Backend {
for (const [mecabName, parsedLines] of Object.entries(rawResults)) {
const result = [];
for (const parsedLine of parsedLines) {
- for (const {expression, reading, source} of parsedLine) {
+ for (let {expression, reading, source} of parsedLine) {
const term = [];
- if (expression !== null && reading !== null) {
- for (const {text: text2, furigana} of jp.distributeFuriganaInflected(
- expression,
- jp.convertKatakanaToHiragana(reading),
- source
- )) {
- const reading2 = jp.convertReading(text2, furigana, options.parsing.readingMode);
- term.push({text: text2, reading: reading2});
- }
- } else {
- const reading2 = jp.convertReading(source, null, options.parsing.readingMode);
- term.push({text: source, reading: reading2});
+ if (expression === '') { expression = source; }
+ for (const {text: text2, furigana} of jp.distributeFuriganaInflected(
+ expression,
+ jp.convertKatakanaToHiragana(reading),
+ source
+ )) {
+ const reading2 = jp.convertReading(text2, furigana, options.parsing.readingMode);
+ term.push({text: text2, reading: reading2});
}
result.push(term);
}
- result.push([{text: '\n'}]);
+ result.push([{text: '\n', reading: ''}]);
}
results.push([mecabName, result]);
}
diff --git a/ext/bg/js/japanese.js b/ext/bg/js/japanese.js
index 5fef27a7..c74e4553 100644
--- a/ext/bg/js/japanese.js
+++ b/ext/bg/js/japanese.js
@@ -127,9 +127,9 @@
function convertReading(expressionFragment, readingFragment, readingMode) {
switch (readingMode) {
case 'hiragana':
- return convertKatakanaToHiragana(readingFragment || '');
+ return convertKatakanaToHiragana(readingFragment);
case 'katakana':
- return convertHiraganaToKatakana(readingFragment || '');
+ return convertHiraganaToKatakana(readingFragment);
case 'romaji':
if (readingFragment) {
return convertToRomaji(readingFragment);
@@ -140,7 +140,7 @@
}
return readingFragment;
case 'none':
- return null;
+ return '';
default:
return readingFragment;
}
@@ -300,7 +300,7 @@
const readingLeft = reading2.substring(group.text.length);
const segs = segmentize(readingLeft, groups.splice(1));
if (segs) {
- return [{text: group.text}].concat(segs);
+ return [{text: group.text, furigana: ''}].concat(segs);
}
}
} else {
@@ -368,7 +368,7 @@
}
if (stemLength !== source.length) {
- output.push({text: source.substring(stemLength)});
+ output.push({text: source.substring(stemLength), furigana: ''});
}
return output;
diff --git a/ext/bg/js/search-query-parser-generator.js b/ext/bg/js/search-query-parser-generator.js
index d44829f7..527302ed 100644
--- a/ext/bg/js/search-query-parser-generator.js
+++ b/ext/bg/js/search-query-parser-generator.js
@@ -36,7 +36,7 @@ class QueryParserGenerator {
const termContainer = this._templateHandler.instantiate(preview ? 'term-preview' : 'term');
for (const segment of term) {
if (!segment.text.trim()) { continue; }
- if (!segment.reading || !segment.reading.trim()) {
+ if (!segment.reading.trim()) {
termContainer.appendChild(this.createSegmentText(segment.text));
} else {
termContainer.appendChild(this.createSegment(segment));
diff --git a/ext/bg/js/search-query-parser.js b/ext/bg/js/search-query-parser.js
index da61b045..692fb1a8 100644
--- a/ext/bg/js/search-query-parser.js
+++ b/ext/bg/js/search-query-parser.js
@@ -140,7 +140,7 @@ class QueryParser extends TextScanner {
const previewTerms = [];
for (let i = 0, ii = text.length; i < ii; i += 2) {
const tempText = text.substring(i, i + 2);
- previewTerms.push([{text: tempText}]);
+ previewTerms.push([{text: tempText, reading: ''}]);
}
this.queryParser.textContent = '';
this.queryParser.appendChild(this.queryParserGenerator.createParseResult(previewTerms, true));