diff options
Diffstat (limited to 'api/word.ts')
-rw-r--r-- | api/word.ts | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/api/word.ts b/api/word.ts index 7eba936..3421f9f 100644 --- a/api/word.ts +++ b/api/word.ts @@ -1,14 +1,31 @@ import Glossary from "./glossary.ts"; import APIBase from "./base.ts"; import { ParseToken } from "../language/types.ts"; +import Japanese from "./japanese.ts"; + +import "../util/string.ts"; export default class Word extends APIBase { - public writing = "TODO"; - public reading = "TODO"; - public conjugated = "TODO"; + /** @prop dictionary form of verb if this word is a verb */ + public base: Japanese; + /** @prop word as written in parent sentence */ + public text: Japanese; - constructor() { - super(); + constructor(input: string | ParseToken) { + super(); + if (typeof input === "string") { + input = input as string; + this.text = new Japanese(input, input); + this.base = this.text; + } 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); + } } async glossary() { |