diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-07-10 16:26:13 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-07-10 16:26:13 +0200 |
commit | a3a81530a0a30ba02b5253b762e2ccd77d3b01fc (patch) | |
tree | afad1bae0c2f7cb9d4a11b6c1c56bc8bae2f14e5 /api | |
parent | e430d8cb4a30640298b7fae3c93bc6329e2a0382 (diff) |
small restructuring + all deinflection tests working
Diffstat (limited to 'api')
-rw-r--r-- | api/sentence.ts | 16 | ||||
-rw-r--r-- | api/word.ts | 8 | ||||
-rw-r--r-- | api/yomikun.ts | 1 |
3 files changed, 12 insertions, 13 deletions
diff --git a/api/sentence.ts b/api/sentence.ts index cde66a5..1d22be3 100644 --- a/api/sentence.ts +++ b/api/sentence.ts @@ -1,11 +1,11 @@ -import { ParseResult } from "../language/types.ts"; +import { SearchSentenceResult } from "../search/types.ts"; import APIBase from "./base.ts"; import { JapaneseFormatter } from "./japanese.ts"; import Word from "./word.ts"; export default class Sentence extends APIBase { public words: Array<Word> = []; - protected query?: ParseResult; + protected query?: SearchSentenceResult; protected original: string = ""; public ready: Promise<void>; @@ -23,7 +23,7 @@ export default class Sentence extends APIBase { private async fetch(input: string) { this.original = input; - this.query = await (await this.api)["core"].parseSentence(input); + this.query = await (await this.api)["core"].search.sentence(input); await this.updateWords(); this._resolveReady(); } @@ -33,15 +33,15 @@ export default class Sentence extends APIBase { let token = 0; let i = 0; while (i < this.original.length) { - this.words.push(new Word(this.query!.tokens[token]).withParent(await this.api)); + this.words.push(new Word(this.query!.words[token]).withParent(await this.api)); - i += this.query!.tokens[token].source.length; + i += this.query!.words[token].source.length; if (i == this.original.length) break; token++; - // continue if there are no unrecognized gaps between tokens - if (this.query!.tokens[token]?.start == i) continue; - var remainder = this.original.substring(i, this.query!.tokens[token]?.start); + // continue if there are no unrecognized gaps between words + if (this.query!.words[token]?.start == i) continue; + var remainder = this.original.substring(i, this.query!.words[token]?.start); this.words.push(new Word(remainder).withParent(await this.api)); i += remainder.length; diff --git a/api/word.ts b/api/word.ts index b7fc3e6..4dad4a3 100644 --- a/api/word.ts +++ b/api/word.ts @@ -1,10 +1,10 @@ import Glossary from "./glossary.ts"; import APIBase from "./base.ts"; -import { ParseToken } from "../language/types.ts"; import Japanese, { JapaneseFormatter } from "./japanese.ts"; import "../util/string.ts"; -import { Tag, TagGroup } from "../language/tags.ts"; +import { TagGroup } from "../search/tags.ts"; +import { SearchWord } from "../search/types.ts"; export default class Word extends APIBase { /** @prop dictionary form of verb if this word is a verb */ @@ -16,7 +16,7 @@ export default class Word extends APIBase { /** @prop this word represents an unrecognized sentence part between recognized terms */ protected filler: boolean; - constructor(input: string | ParseToken) { + constructor(input: string | SearchWord) { super(); if (typeof input === "string") { this.filler = true; @@ -26,7 +26,7 @@ export default class Word extends APIBase { this.outputKanji = false; } else { this.filler = false; - input = input as ParseToken; + input = input as SearchWord; this.base = new Japanese(input.writing, input.reading); if (input.tags.anyOf(TagGroup.Conjugable as string[])) { var writingCommon = input.writing.cmpLen(input.source); diff --git a/api/yomikun.ts b/api/yomikun.ts index a7f214e..696361f 100644 --- a/api/yomikun.ts +++ b/api/yomikun.ts @@ -1,6 +1,5 @@ import Core from "../core/api.ts"; import RemoteCoreClient from "../core/http/client.ts"; -import { ParseResult } from "../language/types.ts"; import Sentence from "./sentence.ts"; export default class Yomikun { |