diff options
Diffstat (limited to 'packages/prosody-ui/src/thai/logic/thainlp.ts')
| -rw-r--r-- | packages/prosody-ui/src/thai/logic/thainlp.ts | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/packages/prosody-ui/src/thai/logic/thainlp.ts b/packages/prosody-ui/src/thai/logic/thainlp.ts new file mode 100644 index 0000000..031bf4c --- /dev/null +++ b/packages/prosody-ui/src/thai/logic/thainlp.ts @@ -0,0 +1,90 @@ +import type { AsyncRes } from "sortug"; +import type { AnalyzeRes } from "../../logic/types"; + +const ENDPOINT = "http://192.168.1.110:8001"; +async function call(path: string, body: any) { + try { + const opts = { + method: "POST", + headers: { "Content-type": "application/json" }, + body: JSON.stringify(body), + }; + const r1 = await fetch(ENDPOINT + path, opts); + // const r2 = await fetch(`http://192.168.1.110:8000/analyze`, opts); + const jj = await r1.json(); + return { ok: jj }; + } catch (e) { + return { error: `${e}` }; + } +} +export async function analyzeTHWord(word: string): AsyncRes<AnalyzeRes> { + return await call("/analyze", { word }); +} +export async function segmentateThai(sentence: string): AsyncRes<AnalyzeRes[]> { + return await call("/segmentate", { word: sentence }); +} + +export const POSMAP: Record<string, string> = { + ADJ: "Adjective", + ADP: "Adposition", + ADV: "Adverb", + AUX: "Auxiliary", + CCONJ: "Coordinating conjunction", + DET: "Determiner", + INTJ: "Interjection", + NOUN: "Noun", + NUM: "Numeral", + PART: "Particle", + PRON: "Pronoun", + PROPN: "Proper noun", + PUNCT: "Punctuation", + SCONJ: "Subordinating conjunction", + VERB: "Verb", + NPRP: "Proper noun", + NCNM: "Cardinal number", + NONM: "Ordinal number", + NLBL: "Label noun", + NCMN: "Common noun", + NTTL: "Title noun", + PPRS: "Personal pronoun", + PDMN: "Demonstrative pronoun", + PNTR: "Interrogative pronoun", + PREL: "Relative pronoun", + VACT: "Active verb", + VSTA: "Stative verb", + VATT: "Attributive verb", + XVBM: "Pre-verb auxiliary, before negator “ไม่”", + XVAM: "Pre-verb auxiliary, after negator “ไม่”", + XVMM: "Pre-verb, before or after negator “ไม่”", + XVBB: "Pre-verb auxiliary, in imperative mood", + XVAE: "Post-verb auxiliary", + DDAN: "classifier in between", + DDAC: "in between", + DDBQ: "classifier or preceding quantitative expression", + DDAQ: "following quantitative expression", + DIAC: "classifier in between", + DIBQ: "classifier or preceding quantitative expression", + DIAQ: "following quantitative expression", + DCNM: "Determiner, cardinal number expression", + DONM: "Determiner, ordinal number expression", + ADVN: "Adverb with normal form", + ADVI: "Adverb with iterative form", + ADVP: "Adverb with prefixed form", + ADVS: "Sentential adverb", + CNIT: "Unit classifier", + CLTV: "Collective classifier", + CMTR: "Measurement classifier", + CFQC: "Frequency classifier", + CVBL: "Verbal classifier", + JCRG: "Coordinating conjunction", + JCMP: "Comparative conjunction", + JSBR: "Subordinating conjunction", + RPRE: "Preposition", + INT: "Interjection", + FIXN: "Nominal prefix", + FIXV: "Adverbial prefix", + EAFF: "Ending for affirmative sentence", + EITT: "Ending for interrogative sentence", + NEG: "Negator", + PUNC: "Punctuation", +}; |
