From 9192e6c7747fd2d3f6a6c5c07d886a0982b53f11 Mon Sep 17 00:00:00 2001 From: polwex Date: Wed, 21 May 2025 15:28:03 +0700 Subject: good tandem good tandem of ideas and implementation --- src/pages/api/nlp.ts | 38 ++++++++++++++++++++++++++++++++++++++ src/pages/lesson/[slug].tsx | 9 ++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) (limited to 'src/pages') diff --git a/src/pages/api/nlp.ts b/src/pages/api/nlp.ts index 0e5eacb..27c330d 100644 --- a/src/pages/api/nlp.ts +++ b/src/pages/api/nlp.ts @@ -30,3 +30,41 @@ export const POST = async (request: Request): Promise => { return Response.json({ message: "Failure" }, { status: 500 }); } }; + +type AnalyzeRes = { + word: string; + syllables: string[]; + ipa: string; + pos: string; +}; + +export async function thaiData(word: string): Promise { + const [head, tail] = await Promise.all([ + analyzeTHWord(word), + segmentateThai(word), + ]); + return [head, ...tail]; +} + +export async function analyzeTHWord(word: string): Promise { + 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 { + 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; +} diff --git a/src/pages/lesson/[slug].tsx b/src/pages/lesson/[slug].tsx index 6632838..9e6e6cc 100644 --- a/src/pages/lesson/[slug].tsx +++ b/src/pages/lesson/[slug].tsx @@ -8,6 +8,8 @@ import type { PageProps } from "waku/router"; import db from "@/lib/db"; import { useCookies } from "@/lib/server/cookiebridge"; import Deck from "@/components/Flashcard/Deck"; +import Deck2 from "@/components/Flashcard/Deck2"; +import { CardFront, CardBack } from "@/components/Flashcard/ServerCard"; const flags: Record = { th: "🇹🇭", @@ -34,12 +36,17 @@ export default async function HomePage(props: PageProps<"/lesson/[slug]">) { const data = await getData(Number(props.slug), user.id); if ("error" in data) return

Error

; // console.log({ data }); + const cardComponents = data.ok.cards.map((card) => ({ + id: card.id, + front: , + back: , + })); return ( <>

Thai!

- +
); -- cgit v1.2.3