diff options
Diffstat (limited to 'api')
-rw-r--r-- | api/word.ts | 21 |
1 files changed, 14 insertions, 7 deletions
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; + } } } |