import type { AsyncRes } from "@sortug/lib"; 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 { return await call("/analyze", { word }); } export async function segmentateThai(sentence: string): AsyncRes { return await call("/segmentate", { word: sentence }); } export const POSMAP = { 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", } as const; type POSTYPE = typeof POSMAP; export type POS_CODE = keyof POSTYPE; export type POS = POSTYPE[POS_CODE];