diff options
Diffstat (limited to 'api')
-rw-r--r-- | api/japanese.ts | 8 | ||||
-rw-r--r-- | api/word.ts | 3 |
2 files changed, 7 insertions, 4 deletions
diff --git a/api/japanese.ts b/api/japanese.ts index add897a..4f176a9 100644 --- a/api/japanese.ts +++ b/api/japanese.ts @@ -107,7 +107,7 @@ export default class Japanese { possibilities.push(path); return; } - // skip until next 'anchor' token + // skip until next 'anchor' token (token with no-kanji characters only) if (tokens[tokenIndex].normalized.length == 0) return match(tokenIndex + 1, searchStart, path); // try all positions where current (anchor) token fits in this.reading @@ -120,14 +120,16 @@ export default class Japanese { // create index slices from possibilities var slices = possibilities .map(match => { // convert start index of anchor to start and stop index (based on anchor length) - var out = [0]; + var out = []; let matchIndex = 0; + if (tokens[0].ruby) out.push(0); for (let tokenIndex = 0; tokenIndex < tokens.length; tokenIndex++) { if (tokens[tokenIndex].normalized.length == 0) continue; out.push(match[matchIndex], match[matchIndex] + tokens[tokenIndex].writing.length); matchIndex++; } - if (out.peek() != this.reading.length) out.push(this.reading.length); + if (tokens.peek().ruby) out.push(this.reading.length); + // if (out.peek() != this.reading.length) out.push(this.reading.length); return out; }) .filter(slice => slice.length == tokens.length + 1) diff --git a/api/word.ts b/api/word.ts index b519789..e92bc19 100644 --- a/api/word.ts +++ b/api/word.ts @@ -104,7 +104,8 @@ export default class Word extends APIBase { // generate conjugated version of verb with kanji this.text = new Japanese(input.source, reading); } else { - this.text = this.base; + // add dictionary reading to this.source as writing (could contain kanji) + this.text = new Japanese(input.source, this.base.reading); } this.id = input.id; } |