diff options
Diffstat (limited to 'src/pages')
-rw-r--r-- | src/pages/api/nlp.ts | 38 | ||||
-rw-r--r-- | src/pages/lesson/[slug].tsx | 9 |
2 files changed, 46 insertions, 1 deletions
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<Response> => { return Response.json({ message: "Failure" }, { status: 500 }); } }; + +type AnalyzeRes = { + word: string; + syllables: string[]; + ipa: string; + pos: string; +}; + +export async function thaiData(word: string): Promise<AnalyzeRes[]> { + const [head, tail] = await Promise.all([ + analyzeTHWord(word), + segmentateThai(word), + ]); + return [head, ...tail]; +} + +export async function analyzeTHWord(word: string): Promise<AnalyzeRes> { + 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<AnalyzeRes[]> { + 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<string, string> = { 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 <p>Error</p>; // console.log({ data }); + const cardComponents = data.ok.cards.map((card) => ({ + id: card.id, + front: <CardFront data={card} />, + back: <CardBack data={card} />, + })); return ( <> <section> <h2 className="text-lg">Thai!</h2> - <Deck data={data.ok} /> + <Deck2 data={data.ok} cards={cardComponents} /> </section> </> ); |