summaryrefslogtreecommitdiff
path: root/packages/prosody-ui/src/thai/logic/thainlp.ts
blob: 031bf4cf88f7c85a6a843ae1fb8a112c50eb6dcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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",
};