import { useState } from "react"; import { api } from "../api"; import type { ContextAnalysisResponse } from "../types"; import { useApiCall } from "../hooks/useApiCall"; import StatusMessage from "./StatusMessage"; export default function ContextAnalysis() { const [keyword, setKeyword] = useState(""); const { data: result, loading, error, run } = useApiCall(); async function handleAnalyze() { if (!keyword.trim()) return; await run(() => api.analyzeContext({ keyword: keyword.trim() })); } return (

Context Analysis

Enter a keyword to discover what it likely means based on how it's used in the corpus. The engine clusters all occurrences and extracts the most associated words for each meaning.

setKeyword(e.target.value)} onKeyDown={(e) => e.key === "Enter" && handleAnalyze()} placeholder="e.g. Epstein, flight, island" />
{error && } {result && result.total_occurrences === 0 && ( )} {result && result.meanings.length > 0 && (

"{result.keyword}" — {result.total_occurrences} occurrences, {result.meanings.length} meaning{result.meanings.length > 1 ? "s" : ""}

{result.meanings.map((meaning, idx) => (
Meaning {idx + 1}
{meaning.occurrences} occurrence{meaning.occurrences > 1 ? "s" : ""} 0.5 ? "74, 222, 128" : "108, 140, 255"}, 0.15)`, color: meaning.confidence > 0.5 ? "var(--ok)" : "var(--accent)", }} > {(meaning.confidence * 100).toFixed(1)}%
{/* Associated words bar chart */}
{meaning.associated_words.map((aw) => { const maxScore = meaning.associated_words[0]?.score || 1; const pct = Math.round((aw.score / maxScore) * 100); return (
{aw.word}
{(aw.score * 100).toFixed(0)}
); })}
{/* Example snippets */} {meaning.example_contexts.length > 0 && (
Example contexts
{meaning.example_contexts.map((ex, i) => (
{ex.doc_id} {ex.snippet}
))}
)}
))}
)}
); }