@polycode-projects/the-mechanical-code-talker 5.0.25 → 5.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +74 -11
- package/bin/tmct.mjs +81 -0
- package/package.json +5 -1
- package/src/adapters/corpus/courtesy.mjs +91 -28
- package/src/adapters/corpus/dbpedia-lookup-live.mjs +116 -0
- package/src/adapters/corpus/news-sources.mjs +436 -0
- package/src/adapters/corpus/research-source.mjs +16 -3
- package/src/adapters/corpus/wiktionary-live.mjs +158 -0
- package/src/adapters/news-store.mjs +87 -0
- package/src/adapters/toml-config.mjs +18 -0
- package/src/domain/choice-question.mjs +275 -0
- package/src/domain/cli-verbs.mjs +20 -0
- package/src/domain/dialogue-acts.mjs +1 -0
- package/src/domain/el-classify.mjs +569 -0
- package/src/domain/fact-phrase.mjs +70 -0
- package/src/domain/feed-normalize.mjs +224 -0
- package/src/domain/grammar/ace.mjs +223 -7
- package/src/domain/grammar/lexicon-core.json +2 -0
- package/src/domain/memory/trust.mjs +15 -0
- package/src/domain/news-feed.mjs +219 -0
- package/src/domain/reasoning-config.mjs +56 -0
- package/src/domain/sprite-animation.mjs +20 -2
- package/src/domain/tableau.mjs +1225 -0
- package/src/domain/term-ledger.mjs +118 -0
- package/src/services/chat.mjs +420 -20
- package/src/services/extract-facts.mjs +91 -1
- package/src/services/index.mjs +12 -0
- package/src/services/init.mjs +33 -0
- package/src/services/news.mjs +918 -0
- package/src/services/sprite-catalog-viz.mjs +148 -78
- package/src/surfaces/web/memory-ask-browser.bundle.js +132 -132
- package/src/surfaces/web/sprites-browser-entry.mjs +4 -4
|
@@ -149,6 +149,73 @@ function foldEntity(word, lexicon) {
|
|
|
149
149
|
return normFactTerm(noun ? noun.lemma : word);
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
+
// The shortest word ingestText's fact-degree scan treats as a content-noun
|
|
153
|
+
// candidate — long enough to rule out stray abbreviations and pronouns the
|
|
154
|
+
// lexical fallback's stopword set doesn't already carry.
|
|
155
|
+
const CANDIDATE_TERM_MIN_LENGTH = 3;
|
|
156
|
+
|
|
157
|
+
/** Every NOUN/PROPN token `sentences` names, surface-form occurrence-counted —
|
|
158
|
+
* a POS tagger reads unknown words by context, so an unlisted noun ("wombat")
|
|
159
|
+
* counts exactly like a lexicon-known one. */
|
|
160
|
+
function candidateTermOccurrencesPos(sentences, nlp) {
|
|
161
|
+
const counts = new Map();
|
|
162
|
+
for (const sentence of sentences) {
|
|
163
|
+
let values;
|
|
164
|
+
let pos;
|
|
165
|
+
try {
|
|
166
|
+
const doc = nlp.readDoc(String(sentence || ""));
|
|
167
|
+
values = doc.tokens().out(nlp.its.value);
|
|
168
|
+
pos = doc.tokens().out(nlp.its.pos);
|
|
169
|
+
} catch { continue; }
|
|
170
|
+
for (let i = 0; i < values.length; i += 1) {
|
|
171
|
+
if (pos[i] !== "NOUN" && pos[i] !== "PROPN") continue;
|
|
172
|
+
counts.set(values[i], (counts.get(values[i]) || 0) + 1);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return counts;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** The no-wink-model fallback: every word that is neither a closed-class
|
|
179
|
+
* scaffolding token nor a lexicon-known verb/adjective counts as a candidate
|
|
180
|
+
* noun — narrower than the POS tier (no context to lean on), but the same
|
|
181
|
+
* "an unlisted word can still be a content noun" posture. */
|
|
182
|
+
function candidateTermOccurrencesLexical(sentences, lexicon) {
|
|
183
|
+
const counts = new Map();
|
|
184
|
+
for (const sentence of sentences) {
|
|
185
|
+
const words = String(sentence || "").match(/[A-Za-z][A-Za-z'-]*/g) || [];
|
|
186
|
+
for (const word of words) {
|
|
187
|
+
const lower = word.toLowerCase();
|
|
188
|
+
if (lower.length < CANDIDATE_TERM_MIN_LENGTH) continue;
|
|
189
|
+
if (OPTIMISTIC_SKIP.has(lower)) continue;
|
|
190
|
+
if (lookupVerb(lexicon, lower) || lookupAdjective(lexicon, lower)) continue;
|
|
191
|
+
counts.set(word, (counts.get(word) || 0) + 1);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return counts;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** Every fact-ungrounded term `sentences` names: a candidate noun folded to
|
|
198
|
+
* its stored term key (`foldEntity`, so a ledger entry and a stored fact key
|
|
199
|
+
* the same term identically) that `rows` holds zero fact rows for — the
|
|
200
|
+
* fact-degree rule an ungrounded-term ledger admits by, independent of
|
|
201
|
+
* whether the lexicon happens to know the word. Occurrence-counted, so a
|
|
202
|
+
* term named three times outranks one named once. */
|
|
203
|
+
function ungroundedTermOccurrences(sentences, rows, { lexicon, nlp }) {
|
|
204
|
+
const raw = nlp ? candidateTermOccurrencesPos(sentences, nlp) : candidateTermOccurrencesLexical(sentences, lexicon);
|
|
205
|
+
const grounded = new Set();
|
|
206
|
+
for (const row of rows) {
|
|
207
|
+
grounded.add(normFactTerm(row.subject));
|
|
208
|
+
grounded.add(normFactTerm(row.object));
|
|
209
|
+
}
|
|
210
|
+
const counts = new Map();
|
|
211
|
+
for (const [word, n] of raw) {
|
|
212
|
+
const term = foldEntity(word, lexicon);
|
|
213
|
+
if (!term || grounded.has(term)) continue;
|
|
214
|
+
counts.set(term, (counts.get(term) || 0) + n);
|
|
215
|
+
}
|
|
216
|
+
return counts;
|
|
217
|
+
}
|
|
218
|
+
|
|
152
219
|
/** The precise tier: wink POS tags pick out the NOUN/PROPN either side of a
|
|
153
220
|
* copula (→ rdfs:subClassOf) or a lexicon-known relation verb (→ its
|
|
154
221
|
* predicate). Adjectives, determiners and prepositions are never mistaken for
|
|
@@ -567,6 +634,11 @@ export async function ingestText(text, {
|
|
|
567
634
|
const cfg = config || loadConfig(process.env, typeof dir === "string" ? dir : process.cwd());
|
|
568
635
|
const lex = lexicon || loadLexicon();
|
|
569
636
|
const nlp = optimistic ? winkInstance() : null;
|
|
637
|
+
// The fact-degree scan below runs whether or not --optimistic is on, so it
|
|
638
|
+
// reads its own wink handle rather than reusing `nlp` (which stays null off
|
|
639
|
+
// --optimistic, and changing that would also change the strict clause-
|
|
640
|
+
// fallback's own verb detection — a different, wider change than this one).
|
|
641
|
+
const termNlp = winkInstance();
|
|
570
642
|
|
|
571
643
|
const extracted = [];
|
|
572
644
|
const optimisticFacts = [];
|
|
@@ -577,6 +649,10 @@ export async function ingestText(text, {
|
|
|
577
649
|
// the skip count so the summary names the real obstacle instead of blaming
|
|
578
650
|
// the sentence's shape for a shape it actually recognizes.
|
|
579
651
|
const ungroundedTerms = new Set();
|
|
652
|
+
// Every sentence's cleaned text, kept for the fact-degree scan (below) that
|
|
653
|
+
// runs once over the whole text after every fact this call will write has
|
|
654
|
+
// landed.
|
|
655
|
+
const cleanedSentences = [];
|
|
580
656
|
|
|
581
657
|
// One recognized read of some text form: null when the strict recognizer
|
|
582
658
|
// grounds nothing, else the Fact rows it touched.
|
|
@@ -597,6 +673,7 @@ export async function ingestText(text, {
|
|
|
597
673
|
sentenceCount += 1;
|
|
598
674
|
lastDecline = "";
|
|
599
675
|
const cleaned = stripCitationResidue(sentence);
|
|
676
|
+
cleanedSentences.push(cleaned);
|
|
600
677
|
// Whole sentence first, then each closed-marker clause as a fallback.
|
|
601
678
|
let rows = null;
|
|
602
679
|
for (const candidate of clauseCandidates(cleaned, { nlp })) {
|
|
@@ -647,6 +724,18 @@ export async function ingestText(text, {
|
|
|
647
724
|
}
|
|
648
725
|
}
|
|
649
726
|
|
|
727
|
+
const finalRows = readFactRows(await loadMemory(dir));
|
|
728
|
+
// ungroundedCounts widens the legacy ungroundedTerms rule (a lexicon-miss
|
|
729
|
+
// named in a decline) to the fact-degree rule: every term with zero fact
|
|
730
|
+
// rows, lexicon-known or not. ungroundedTerms stays a subset by
|
|
731
|
+
// construction — each of its terms is folded in below even on the rare
|
|
732
|
+
// chance the POS scan itself missed it.
|
|
733
|
+
const ungroundedCounts = ungroundedTermOccurrences(cleanedSentences, finalRows, { lexicon: lex, nlp: termNlp });
|
|
734
|
+
for (const term of ungroundedTerms) {
|
|
735
|
+
const key = normFactTerm(term);
|
|
736
|
+
if (key && !ungroundedCounts.has(key)) ungroundedCounts.set(key, 1);
|
|
737
|
+
}
|
|
738
|
+
|
|
650
739
|
const result = {
|
|
651
740
|
sentences: sentenceCount,
|
|
652
741
|
recognized: recognizedSentences,
|
|
@@ -654,9 +743,10 @@ export async function ingestText(text, {
|
|
|
654
743
|
optimistic: optimisticFacts,
|
|
655
744
|
skipped: sentenceCount - recognizedSentences - optimisticSentences,
|
|
656
745
|
ungroundedTerms: [...ungroundedTerms],
|
|
746
|
+
ungroundedCounts,
|
|
657
747
|
};
|
|
658
748
|
if (canonical) {
|
|
659
|
-
result.canonical = canonicalLines([...extracted, ...optimisticFacts],
|
|
749
|
+
result.canonical = canonicalLines([...extracted, ...optimisticFacts], finalRows);
|
|
660
750
|
}
|
|
661
751
|
return result;
|
|
662
752
|
} finally {
|
package/src/services/index.mjs
CHANGED
|
@@ -64,3 +64,15 @@ export { CONFIG_FILE as TOML_CONFIG_FILE } from "../adapters/toml-config.mjs";
|
|
|
64
64
|
// The "detailed answer" completions pipeline (also reachable as the
|
|
65
65
|
// `./generateCompletion` and `./createCompletionsGraphAdapter` subpath exports).
|
|
66
66
|
export { generateCompletion, createCompletionsGraphAdapter } from "./completions.mjs";
|
|
67
|
+
|
|
68
|
+
// The news capability: scheduled multi-source ingestion, occurrence-ranked
|
|
69
|
+
// grounding gaps, KB enrichment and the fact-churn feed builder — one
|
|
70
|
+
// library contract every surface (news.html, chat's `/news`, the CLI verb,
|
|
71
|
+
// a JS import) consumes the same way.
|
|
72
|
+
export {
|
|
73
|
+
resolveNewsConfig, parseNewsRequest, pollNewsSources, ingestNewsSnapshot,
|
|
74
|
+
enrichTopTerms, reprocessAfterGrounding, isVocabGroundedTerm, isFactGroundedTerm,
|
|
75
|
+
ingestUploadedFactRows, buildFeed, newsTurn,
|
|
76
|
+
} from "./news.mjs";
|
|
77
|
+
export { buildNewsItems } from "../domain/news-feed.mjs";
|
|
78
|
+
export { rankedTerms } from "../domain/term-ledger.mjs";
|
package/src/services/init.mjs
CHANGED
|
@@ -158,6 +158,39 @@ source = ${JSON.stringify(config.research.source)}
|
|
|
158
158
|
`;
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
+
// [news] section — only emitted when a caller actually supplies it.
|
|
162
|
+
if (config.news && Object.keys(config.news).length > 0) {
|
|
163
|
+
out += `
|
|
164
|
+
[news]
|
|
165
|
+
# News feed configuration: contemporary sources (defaults: wikimedia-featured,
|
|
166
|
+
# hacker-news, usgs-quakes), knowledge-base sources (defaults: simple-wikipedia,
|
|
167
|
+
# wikidata, wiktionary), polling cycle minutes, enrichment budgets, and graph
|
|
168
|
+
# retention caps. See PLAN_NEWS_FEED.md section 6.4 for every option.
|
|
169
|
+
# Precedence: chat command > CLI flag > this file > defaults.
|
|
170
|
+
`;
|
|
171
|
+
const newsKeys = [
|
|
172
|
+
"sources", "kb_sources", "extra_sources",
|
|
173
|
+
"poll_minutes", "enrich_minutes",
|
|
174
|
+
"enrich_terms_per_cycle", "negative_cache_ttl_hours",
|
|
175
|
+
"syllogisms_per_ingest",
|
|
176
|
+
"item_cap", "news_fact_cap", "feed_top", "window_hours",
|
|
177
|
+
"min_interval_ms",
|
|
178
|
+
];
|
|
179
|
+
for (const key of newsKeys) {
|
|
180
|
+
if (config.news[key] !== undefined) {
|
|
181
|
+
const val = config.news[key];
|
|
182
|
+
const tomlKey = key.replace(/_/g, "_");
|
|
183
|
+
if (Array.isArray(val)) {
|
|
184
|
+
out += `${tomlKey} = ${JSON.stringify(val)}\n`;
|
|
185
|
+
} else if (typeof val === "string") {
|
|
186
|
+
out += `${tomlKey} = ${JSON.stringify(val)}\n`;
|
|
187
|
+
} else {
|
|
188
|
+
out += `${tomlKey} = ${val}\n`;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
161
194
|
// Extension-pack / bias sections — only emitted when a caller supplies them.
|
|
162
195
|
const extras = {};
|
|
163
196
|
if (config.extensions !== undefined) extras.extensions = config.extensions;
|