diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-06-29 14:25:29 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-06-29 14:25:29 +0200 |
commit | 3f7ae147fb969db479c10eaa871a840a30e281b3 (patch) | |
tree | 2e99c35f59f0effb260c26118e9edf3199bb8de7 /language | |
parent | c998e1c0477d51c886f9e4246e102dec4d7ef8dd (diff) |
http proof of concept api
Diffstat (limited to 'language')
-rw-r--r-- | language/parser.ts | 16 | ||||
-rw-r--r-- | language/tags.ts | 6 |
2 files changed, 12 insertions, 10 deletions
diff --git a/language/parser.ts b/language/parser.ts index 9c6bef2..9bfdc4b 100644 --- a/language/parser.ts +++ b/language/parser.ts @@ -52,12 +52,12 @@ export default class Parser { if (!result.tags.anyOf(Object.values(Tag.Class.Verb))) return false; // ignore other wrong deconjugations - if (result.tags.has(Tag.Class.Verb.U) && - !result.tags.has(Tag.Inflection.Reason.U)) return false; - if (result.tags.has(Tag.Class.Verb.Ru) && - !result.tags.has(Tag.Inflection.Reason.Ru)) return false; - if (result.tags.has(Tag.Class.Verb.Suru) && - !result.tags.has(Tag.Inflection.Reason.Suru)) return false; + if (result.tags.includes(Tag.Class.Verb.U) && + !result.tags.includes(Tag.Inflection.Reason.U)) return false; + if (result.tags.includes(Tag.Class.Verb.Ru) && + !result.tags.includes(Tag.Inflection.Reason.Ru)) return false; + if (result.tags.includes(Tag.Class.Verb.Suru) && + !result.tags.includes(Tag.Inflection.Reason.Suru)) return false; } // all other results should be valid grammatically @@ -73,12 +73,12 @@ export default class Parser { const lastTokenName = parseResult.tokens.peek()?.tags.anyOf(Object.values(Tag.Name)); // give higher priority to suffixes when last token was a name, else lower priority - if (result.tags.has(Tag.Class.Suffix)) + if (result.tags.includes(Tag.Class.Suffix)) result.sort *= lastTokenName ? PRIORITY_MOD_HIGHER : PRIORITY_MOD_LOWER; // give lower priority to terms matched only by their readings, and are // usually written in kanji - if (!result.tags.has(Tag.Auxiliary.UsuallyKana) && !result.match.kanji) + if (!result.tags.includes(Tag.Auxiliary.UsuallyKana) && !result.match.kanji) result.sort *= PRIORITY_MOD_LOWER; return result; diff --git a/language/tags.ts b/language/tags.ts index d56ce98..d40904f 100644 --- a/language/tags.ts +++ b/language/tags.ts @@ -1,3 +1,5 @@ +import "../util/array.ts"; + /** @constant Tags that have significant meaning to the parser */ export const Tag = { /** @constant grammatical classes */ @@ -98,7 +100,7 @@ export const Tag = { export type TokenTag = string; // no way around it -export type TokenTags = Set<TokenTag>; +export type TokenTags = Array<TokenTag>; /** @summary parse concatenated tag string to TokenTags */ export function parseTags(input: string) { @@ -111,6 +113,6 @@ export function parseTags(input: string) { filteredTags.push(tag); } - return new Set(filteredTags) as TokenTags; + return filteredTags.set().arr() as TokenTags; // make sure array doesn't contain duplicates } |