From 5c9bebac4078ee053c5048e4de2a3ed5afed4e24 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Mon, 3 Jul 2023 12:46:22 +0200 Subject: fix furigana for known working sentence --- api/word.ts | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'api') diff --git a/api/word.ts b/api/word.ts index 3421f9f..13c7197 100644 --- a/api/word.ts +++ b/api/word.ts @@ -4,6 +4,7 @@ import { ParseToken } from "../language/types.ts"; import Japanese from "./japanese.ts"; import "../util/string.ts"; +import { Tag } from "../language/tags.ts"; export default class Word extends APIBase { /** @prop dictionary form of verb if this word is a verb */ @@ -15,16 +16,22 @@ export default class Word extends APIBase { super(); if (typeof input === "string") { input = input as string; - this.text = new Japanese(input, input); - this.base = this.text; + this.base = new Japanese(input, input); + this.text = this.base; } else { input = input as ParseToken; - var common = Math.max(input.writing.cmpLen(input.source), - input.reading.cmpLen(input.source)); - var conjugation = input.source.substring(common); this.base = new Japanese(input.writing, input.reading); - this.text = new Japanese(input.writing.substring(0, common) + conjugation, - input.reading.substring(0, common) + conjugation); + if (input.tags.anyOf(Object.values(Tag.Class.Verb))) { + var writingCommon = input.writing.cmpLen(input.source); + var readingCommon = input.reading.cmpLen(input.source); + var stemLength = Math.max(writingCommon, readingCommon); + var base = input[writingCommon > readingCommon ? "writing" : "reading"].substring(stemLength); + var conjugation = input.source.substring(stemLength); + this.text = new Japanese(input.writing.replaceLast(base, conjugation), + input.reading.replaceLast(base, conjugation)); + } else { + this.text = this.base; + } } } -- cgit v1.2.3