From ba2dbc660c229d3e86662d35513dfa7c904d9870 Mon Sep 17 00:00:00 2001 From: polwex Date: Sun, 23 Nov 2025 13:29:28 +0700 Subject: wew --- .../prosody-ui/src/components/word/Semantic.tsx | 184 +++++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100644 packages/prosody-ui/src/components/word/Semantic.tsx (limited to 'packages/prosody-ui/src/components/word/Semantic.tsx') diff --git a/packages/prosody-ui/src/components/word/Semantic.tsx b/packages/prosody-ui/src/components/word/Semantic.tsx new file mode 100644 index 0000000..059194c --- /dev/null +++ b/packages/prosody-ui/src/components/word/Semantic.tsx @@ -0,0 +1,184 @@ +import { useEffect, useState } from "react"; +import type { Example, FullWordData } from "@sortug/langlib"; +import { IconBadgeFilled, IconSparkles } from "@tabler/icons-react"; + +type Tab = "meanings" | "grammar" | "examples"; +function Semantic({ data }: { data: FullWordData }) { + return ( +
+
+
+ {data.senses.map((sense, i) => ( +
+
+ {sense.pos &&
{sense.pos}
} + +
    + {sense.glosses.map((gloss, idx: number) => ( +
  • + {gloss} +
  • + ))} +
+ + {sense.etymology && ( +
+ Etymology: {sense.etymology} +
+ )} + + {sense.categories.length > 0 && ( +
+ Categories: {sense.categories.join(", ")} +
+ )} + {sense.derivation.length > 0 && ( +
+ Derived forms: + {sense.derivation.map((dr, i) => ( +
+ {dr.type}: {dr.text} - {dr.tags} +
+ ))} +
+ )} + {sense.examples.length > 0 && ( + + )} +
+
+ ))} +
+
+
+ ); +} + +export default Semantic; + +function ExamplesTab({ + data, + examples, +}: { + data: FullWordData; + examples: Example[]; +}) { + const [isGenerating, setIsGenerating] = useState(false); + const [generatedExamples, setGeneratedExamples] = useState([]); + + const generateExamples = async () => { + setIsGenerating(true); + + try { + // Get the primary meaning from the first sense + const primaryMeaning = + data.senses?.[0]?.glosses?.[0] || "unknown meaning"; + + const response = await fetch("/api/generate-examples", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + word: data.spelling, + meaning: primaryMeaning, + examples, + }), + }); + + if (!response.ok) { + throw new Error("Failed to generate examples"); + } + + const j = await response.json(); + setGeneratedExamples(j.examples || []); + } catch (err) { + console.error("Error generating examples:", err); + } finally { + setIsGenerating(false); + } + }; + return ( +
+
+

Usage Examples

+ + {/* Generate More Button */} +
+ +
+ + {/* Examples Display */} +
+ {examples.map((example, idx) => ( +
+

+ {example?.text || ""} +

+ {example.ref && ( +

+ Source: {example.ref} +

+ )} +
+ ))} + + {generatedExamples.length > 0 && ( + <> +
+ AI-Generated Examples: +
+ {generatedExamples.map((example, idx) => ( +
+

+ {example.thai} +

+

+ {example.english} +

+ {example.context && ( +

+ Context: {example.context} +

+ )} +
+ ))} + + )} + + {/* No Examples */} + {!moreExamples?.length && !generatedExamples.length && ( +
+

+ No examples available for this word. Click "Generate More + Example Sentences" to get AI-generated examples. +

+
+ )} +
+
+
+ ); +} -- cgit v1.2.3