// Deep-tech interactive section — TF-IDF, Correlative Queries, Query Path, Co-occurrence // These demos give a glimpse into the actual semantic engineering work. const { useState: useStateDT, useMemo: useMemoDT, useEffect: useEffectDT, useRef: useRefDT } = React; // ============================================================ // SHARED CORPUS — what "your page" and the top 3 competitors look like // ============================================================ const DT_CORPUS = { yours: "Our CRM helps sales teams close more deals. We offer pipeline management, contact tracking, and email automation. Try our CRM today and grow your sales pipeline.", c1: "A modern CRM platform built for B2B sales teams. Manage your pipeline, automate outreach sequences, qualify leads with intent signals, forecast revenue, and integrate with your existing stack. SOC2 compliant.", c2: "Sales CRM software with built-in deal scoring, multi-channel sequences, conversation intelligence, revenue forecasting, lead routing, account-based workflows, and native integrations with Salesforce, Hubspot, and Outreach.", c3: "The revenue operations platform. Pipeline hygiene, deal inspection, win/loss analytics, forecast accuracy, sequence automation, intent data enrichment, ICP targeting, and territory planning , all in one system of record.", }; // Tiny tokenizer function tokenize(text) { return (text || "") .toLowerCase() .replace(/[^a-z0-9\s\-]/g, " ") .split(/\s+/) .filter(t => t.length > 2 && !DT_STOPWORDS.has(t)); } const DT_STOPWORDS = new Set(["the","and","for","with","our","you","your","are","not","but","this","that","from","its","has","have","more","one","all","any","into","out","off","can","will","try","get","use","big","new","old","help","helps","today","grow"]); // TF-IDF: term frequency in doc × log(N / df) function tfidf(docs) { const tokenized = docs.map(tokenize); const N = tokenized.length; const df = {}; tokenized.forEach(doc => { new Set(doc).forEach(t => { df[t] = (df[t] || 0) + 1; }); }); return tokenized.map(doc => { const tf = {}; doc.forEach(t => { tf[t] = (tf[t] || 0) + 1; }); const len = doc.length || 1; const scores = {}; Object.keys(tf).forEach(t => { const idf = Math.log((N + 1) / (df[t] + 1)) + 1; scores[t] = (tf[t] / len) * idf; }); return scores; }); } // ============================================================ // TF-IDF VISUALIZER // ============================================================ function TFIDFDemo() { const [editable, setEditable] = useStateDT(DT_CORPUS.yours); const docs = [editable, DT_CORPUS.c1, DT_CORPUS.c2, DT_CORPUS.c3]; const scores = useMemoDT(() => tfidf(docs), [editable]); // Union of competitor important terms (avg of top across c1-c3) — what "Google expects" const expected = useMemoDT(() => { const merged = {}; [1,2,3].forEach(i => { Object.entries(scores[i] || {}).forEach(([k,v]) => { merged[k] = (merged[k] || 0) + v; }); }); return Object.entries(merged) .sort((a,b) => b[1] - a[1]) .slice(0, 16) .map(([term, score]) => ({ term, score })); }, [scores]); const yoursScores = scores[0] || {}; const maxExpected = Math.max(...expected.map(e => e.score), 0.01); const yoursTopTerms = Object.entries(yoursScores).sort((a,b) => b[1]-a[1]).slice(0,8).map(([t]) => t); const coverage = expected.filter(e => yoursScores[e.term] && yoursScores[e.term] > 0).length; const coveragePct = Math.round((coverage / expected.length) * 100); return (
↳ YOUR PAGE COPY · EDIT TO SEE LIVE RECALCULATION