summaryrefslogtreecommitdiff
path: root/src/lib/calls
diff options
context:
space:
mode:
authorpolwex <polwex@sortug.com>2025-06-03 01:36:36 +0700
committerpolwex <polwex@sortug.com>2025-06-03 01:36:36 +0700
commit2b80f7950df34f2a160135d7e20220a9b2ec3352 (patch)
tree0e2aec09b9aba887419e46c4d2fcaf861391eedc /src/lib/calls
parent249230c8e0e1bdb8ae4f433262997b84ee274904 (diff)
got thai working but this is a bit too specific i think
Diffstat (limited to 'src/lib/calls')
-rw-r--r--src/lib/calls/nlp.ts1
-rw-r--r--src/lib/calls/thainlp.ts106
2 files changed, 107 insertions, 0 deletions
diff --git a/src/lib/calls/nlp.ts b/src/lib/calls/nlp.ts
index 3cff415..f3364ac 100644
--- a/src/lib/calls/nlp.ts
+++ b/src/lib/calls/nlp.ts
@@ -3,6 +3,7 @@ import { SyllableRes } from "../types/cards";
export type ThaiNLPRes = {
word: string;
normalized: string;
+ realSyls: string[];
syllables: string[];
syllablesIpa: string[];
ipa: string;
diff --git a/src/lib/calls/thainlp.ts b/src/lib/calls/thainlp.ts
new file mode 100644
index 0000000..662e984
--- /dev/null
+++ b/src/lib/calls/thainlp.ts
@@ -0,0 +1,106 @@
+import { SyllableRes } from "../types/cards";
+
+export type ThaiNLPRes = {
+ word: string;
+ normalized: string;
+ realSyls: string[];
+ syllables: string[];
+ syllablesIpa: string[];
+ ipa: string;
+ pos: string;
+};
+
+export async function thaiData(word: string): Promise<ThaiNLPRes[]> {
+ const [head, tail] = await Promise.all([
+ analyzeTHWord(word),
+ segmentateThai(word),
+ ]);
+ return [head, ...tail];
+}
+
+export async function analyzeTHWord(word: string): Promise<ThaiNLPRes> {
+ const opts = {
+ method: "POST",
+ headers: { "Content-type": "application/json" },
+ body: JSON.stringify({ word }),
+ };
+ const r1 = await fetch("http://localhost:8001" + "/analyze", opts);
+ // const r2 = await fetch(`http://192.168.1.110:8000/analyze`, opts);
+ const jj = await r1.json();
+ return jj;
+}
+export async function segmentateThai(sentence: string): Promise<ThaiNLPRes[]> {
+ const opts = {
+ method: "POST",
+ headers: { "Content-type": "application/json" },
+ body: JSON.stringify({ word: sentence }),
+ };
+ // const r1 = await fetch(`http://localhost:8000/segmentate`, opts);
+ const r2 = await fetch("http://localhost:8001" + `/segmentate`, opts);
+ const jj = await r2.json();
+ return jj;
+}
+export async function getThaiFreq(word: string): Promise<number> {
+ const opts = {
+ method: "POST",
+ headers: { "Content-type": "application/json" },
+ body: JSON.stringify({ word }),
+ };
+ // const r1 = await fetch(`http://localhost:8000/segmentate`, opts);
+ const r2 = await fetch("http://localhost:8001" + `/freq`, opts);
+ const jj = await r2.json();
+ return jj;
+}
+export async function getThaiNext(word: string): Promise<string[]> {
+ const opts = {
+ method: "POST",
+ headers: { "Content-type": "application/json" },
+ body: JSON.stringify({ word }),
+ };
+ // const r1 = await fetch(`http://localhost:8000/segmentate`, opts);
+ const r2 = await fetch("http://localhost:8001" + `/next`, opts);
+ const jj = await r2.json();
+ return jj;
+}
+
+export async function getThaiPrev(word: string): Promise<string[]> {
+ const opts = {
+ method: "POST",
+ headers: { "Content-type": "application/json" },
+ body: JSON.stringify({ word }),
+ };
+ // const r1 = await fetch(`http://localhost:8000/segmentate`, opts);
+ const r2 = await fetch("http://localhost:8001" + `/prev`, opts);
+ const jj = await r2.json();
+ return jj;
+}
+
+export async function getThaiNext_bi(
+ word1: string,
+ word2: string,
+): Promise<string[]> {
+ const opts = {
+ method: "POST",
+ headers: { "Content-type": "application/json" },
+ body: JSON.stringify({ word1, word2 }),
+ };
+ // const r1 = await fetch(`http://localhost:8000/segmentate`, opts);
+ const r2 = await fetch("http://localhost:8001" + `/next_bi`, opts);
+ const jj = await r2.json();
+ return jj;
+}
+
+export async function getThaiPrev_bi(
+ word1: string,
+ word2: string,
+): Promise<string[]> {
+ const opts = {
+ method: "POST",
+ headers: { "Content-type": "application/json" },
+ body: JSON.stringify({ word1, word2 }),
+ };
+ // const r1 = await fetch(`http://localhost:8000/segmentate`, opts);
+ const r2 = await fetch("http://localhost:8001" + `/prev_bi`, opts);
+ const jj = await r2.json();
+ return jj;
+}