@polycode-projects/the-mechanical-code-talker 5.0.24 → 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/corpus/sprites/src/sprite-facts.jsonl +48 -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/adventure-viz.mjs +89 -7
- package/src/services/chat.mjs +495 -27
- 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
package/src/services/chat.mjs
CHANGED
|
@@ -46,7 +46,7 @@ import { setConstructionBanks } from "../domain/interpret/strategies/constructio
|
|
|
46
46
|
import { nlpAdapter } from "../adapters/ask-nlp.mjs";
|
|
47
47
|
import { readConstructionFiles } from "../adapters/corpus/construction-banks.mjs";
|
|
48
48
|
import { fuzzyMatchInSet, fuzzyBound } from "../domain/interpret/fuzzy.mjs";
|
|
49
|
-
import { loadLexicon, lookupNoun, lookupVerb, lookupAdjective, lookupProperName, readsAsIndividualName } from "../domain/grammar/lexicon.mjs";
|
|
49
|
+
import { loadLexicon, lookupNoun, lookupVerb, lookupAdjective, lookupProperName, readsAsIndividualName, CODE_REF_SHAPE } from "../domain/grammar/lexicon.mjs";
|
|
50
50
|
import { pickPhrase } from "../domain/answer-variants.mjs";
|
|
51
51
|
import {
|
|
52
52
|
REFERENCE_PACK_NAME, cleanMissReferenceTerm, renderReferenceAnswer, referenceProvenanceTag,
|
|
@@ -62,6 +62,7 @@ import { loadResearchQueue, saveResearchQueue } from "../adapters/research-queue
|
|
|
62
62
|
import { CHILD_PACK_NAME, childProvenanceTag } from "../domain/child-pack.mjs";
|
|
63
63
|
import { getChildPackProvider } from "../adapters/corpus/child-pack.mjs";
|
|
64
64
|
import { dialogueActForLane } from "../domain/dialogue-acts.mjs";
|
|
65
|
+
import { splitChoiceQuestion } from "../domain/choice-question.mjs";
|
|
65
66
|
import { subClassParents, subClassChildren, descendantSet, ancestryChain, clusterSenses } from "../domain/sense-split.mjs";
|
|
66
67
|
import { ANSWER_STOP_SET } from "../domain/hub-terms.mjs";
|
|
67
68
|
import { relatedForTerm } from "../domain/skos-view.mjs";
|
|
@@ -3675,6 +3676,40 @@ async function isAnchorableTerm(term, lex, memoryDir, cache = null, graph = null
|
|
|
3675
3676
|
}
|
|
3676
3677
|
export { isAnchorableTerm };
|
|
3677
3678
|
|
|
3679
|
+
/** Per-option grounding for the closed multiple-choice lane (splitChoiceQuestion,
|
|
3680
|
+
* choice-question.mjs): for each option, looks for a stored Fact row whose
|
|
3681
|
+
* {subject, object} pair is {sourceTerm, option} in either direction, under
|
|
3682
|
+
* any predicate. This is PAIR-level grounding, not the term-level check
|
|
3683
|
+
* isAnchorableTerm runs above — almost every option answers "is this term
|
|
3684
|
+
* known at all", but only a stated relation between the source term and THAT
|
|
3685
|
+
* option decides a choice question, which is what this function tests.
|
|
3686
|
+
*
|
|
3687
|
+
* Reads the same rows the rest of chat reads (factRows/factRowsCache), and
|
|
3688
|
+
* pulls the child pack for `sourceTerm` ONCE per turn, only when memory holds
|
|
3689
|
+
* no fact for it yet — the same childPackFactsForKey the learn-on-miss
|
|
3690
|
+
* cascade calls elsewhere in this file. Never pulls per option: seeding the
|
|
3691
|
+
* graph from the question's own distractors would ground every option for
|
|
3692
|
+
* free, which is a slow way to guess rather than an honest probe.
|
|
3693
|
+
*
|
|
3694
|
+
* `chain` stays null on every entry here — a direct-edge probe only. A
|
|
3695
|
+
* bounded findIsaChain chase for an option with no direct edge is later work
|
|
3696
|
+
* (rung 3), which is why `graph` already rides this signature unused. */
|
|
3697
|
+
async function probeChoiceOptions(parsed, { memoryDir, env, cache, graph, synthesisBudget = AUTO_SYNTHESIS_BUDGET }) {
|
|
3698
|
+
const sourceVariants = factTermVariants(normFactTermStatic, parsed.sourceTerm);
|
|
3699
|
+
let rows = await factRows(memoryDir, cache);
|
|
3700
|
+
const hasSourceFacts = rows.some((f) => sourceVariants.has(f.subject) || sourceVariants.has(f.object));
|
|
3701
|
+
if (!hasSourceFacts && memoryDir) {
|
|
3702
|
+
const learned = await childPackFactsForKey(parsed.sourceTerm, { memoryDir, env, cache, synthesisBudget });
|
|
3703
|
+
if (learned) rows = await factRows(memoryDir, cache);
|
|
3704
|
+
}
|
|
3705
|
+
return parsed.options.map((option) => {
|
|
3706
|
+
const optionVariants = factTermVariants(normFactTermStatic, option.text);
|
|
3707
|
+
const facts = rows.filter((f) => (sourceVariants.has(f.subject) && optionVariants.has(f.object))
|
|
3708
|
+
|| (sourceVariants.has(f.object) && optionVariants.has(f.subject)));
|
|
3709
|
+
return { label: option.label, text: option.text, grounds: facts.length > 0, facts, chain: null };
|
|
3710
|
+
});
|
|
3711
|
+
}
|
|
3712
|
+
|
|
3678
3713
|
/** The "both sides ungrounded" grounding NUDGE: reuses teachSuggestion's own
|
|
3679
3714
|
* "compute a hint, APPEND it to the existing honest-miss message, never
|
|
3680
3715
|
* replace/silently guess" pattern (see its docblock, above, and the
|
|
@@ -4319,6 +4354,29 @@ const quantifiedHasObject = (m) => (/^all$/i.test(m[1])
|
|
|
4319
4354
|
* the single noun between the determiner and the verb; a two-token subject stays
|
|
4320
4355
|
* declined, like the preposition-pinned frame, because nothing names its head. */
|
|
4321
4356
|
const DETERMINER_HAS_TEACH_RE = /^(?:the|an?|my|your|our|their|his|her|its)\s+([\w'-]+)\s+(?:has|have|had)\s+(.+?)[.!?]*$/i;
|
|
4357
|
+
/** The quantified LOCATIVE teach ("every disk rests on peg-a", "each disk
|
|
4358
|
+
* rests on peg-a", "all disks rest on peg-a") — QUANTIFIED_HAS_TEACH_RE's own
|
|
4359
|
+
* sibling for the board-fact verb family. The has/have frame can pin the
|
|
4360
|
+
* verb by naming it outright; a locative verb (rests/stands/sits/lies/…) has
|
|
4361
|
+
* no closed set to name, so the PREP_SRC preposition pins the split instead,
|
|
4362
|
+
* the same way GENERAL_VERB_DETERMINER_TEACH_RE's does. Same subject fold as
|
|
4363
|
+
* QUANTIFIED_HAS_TEACH_RE: "every"/"each" keep the singular noun, "all" folds
|
|
4364
|
+
* the plural. */
|
|
4365
|
+
const QUANTIFIED_LOCATIVE_TEACH_RE = new RegExp(
|
|
4366
|
+
`^(every|each|all)\\s+([\\w'-]+)\\s+([a-z]+)\\s+(${PREP_SRC})\\s+(.+?)[.!?]*$`, "i",
|
|
4367
|
+
);
|
|
4368
|
+
const quantifiedLocativeSubject = (m) => (/^all$/i.test(m[1]) ? singularizeSurface(m[2]) : m[2]);
|
|
4369
|
+
/** The counting/indefinite lead that introduces ONE additional, unnamed
|
|
4370
|
+
* individual — "one more"/"another more" mirrors ACK_COUNTING_SRC's own
|
|
4371
|
+
* counting-aside vocabulary (normalize.mjs's ack-preamble arm), and bare
|
|
4372
|
+
* "another" is the ordinary English determiner "a"/"an" already is. None of
|
|
4373
|
+
* the three name WHICH disk, so all three fold onto the exact stored shape
|
|
4374
|
+
* "a disk rests on peg-a" already uses — no quantifier field, same subject,
|
|
4375
|
+
* same predicate. */
|
|
4376
|
+
const LOCATIVE_COUNTING_LEAD_SRC = "(?:just\\s+)?(?:one|another)\\s+more|another";
|
|
4377
|
+
const LOCATIVE_COUNTING_TEACH_RE = new RegExp(
|
|
4378
|
+
`^(?:${LOCATIVE_COUNTING_LEAD_SRC})\\s+([\\w'-]+)\\s+([a-z]+)\\s+(${PREP_SRC})\\s+(.+?)[.!?]*$`, "i",
|
|
4379
|
+
);
|
|
4322
4380
|
/** Verbs owned by an earlier, more specific recognizer in this lane — is/are
|
|
4323
4381
|
* (class-membership/property, above) and owns/maintains (ownership, above).
|
|
4324
4382
|
* generalVerbTeach declines outright on these so it can never race a more
|
|
@@ -4500,14 +4558,24 @@ async function generalVerbTeach(payload) {
|
|
|
4500
4558
|
const m = p.match(GENERAL_VERB_TEACH_RE);
|
|
4501
4559
|
if (!m) return null;
|
|
4502
4560
|
let [, subjectRaw, verbRaw, objectRaw] = m;
|
|
4561
|
+
let quantifier = "";
|
|
4503
4562
|
// A determiner in the subject slot means the single-token subject bound has
|
|
4504
4563
|
// bound the article and misread the real subject's second word as the verb
|
|
4505
4564
|
// ("the small disk rests on…" gives subject="the", verb="small"). Re-read it
|
|
4506
4565
|
// with the preposition pinning the verb; a sentence that frame can't pin
|
|
4507
4566
|
// declines here exactly as it always has.
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
|
|
4567
|
+
//
|
|
4568
|
+
// The locative quantifier leads are checked here too, even though neither
|
|
4569
|
+
// is in GENERAL_VERB_DETERMINER_RE's own single-token set: "another"/"one"
|
|
4570
|
+
// (the first word of "another disk"/"one more disk") aren't articles, so
|
|
4571
|
+
// without this OR the redirect below never triggers and the mis-bound
|
|
4572
|
+
// subjectRaw/verbRaw from GENERAL_VERB_TEACH_RE ("another"/"disk" instead
|
|
4573
|
+
// of "disk"/"rests") stands uncorrected.
|
|
4574
|
+
const quantLoc = p.match(QUANTIFIED_LOCATIVE_TEACH_RE);
|
|
4575
|
+
const countLoc = !quantLoc ? p.match(LOCATIVE_COUNTING_TEACH_RE) : null;
|
|
4576
|
+
if (GENERAL_VERB_DETERMINER_RE.test(subjectRaw) || quantLoc || countLoc) {
|
|
4577
|
+
const quantHas = (!quantLoc && !countLoc) ? p.match(QUANTIFIED_HAS_TEACH_RE) : null;
|
|
4578
|
+
const detHas = (!quantHas && !quantLoc && !countLoc) ? p.match(DETERMINER_HAS_TEACH_RE) : null;
|
|
4511
4579
|
if (quantHas) {
|
|
4512
4580
|
subjectRaw = quantifiedHasSubject(quantHas);
|
|
4513
4581
|
verbRaw = "has";
|
|
@@ -4516,6 +4584,22 @@ async function generalVerbTeach(payload) {
|
|
|
4516
4584
|
subjectRaw = detHas[1];
|
|
4517
4585
|
verbRaw = "has";
|
|
4518
4586
|
objectRaw = detHas[2];
|
|
4587
|
+
} else if (quantLoc) {
|
|
4588
|
+
// Universal locative ("every disk rests on peg-a") — the same
|
|
4589
|
+
// "every"-only quantifier-field convention unknownSubjectFallback's
|
|
4590
|
+
// isa teach already uses: "each"/"all" gate as universal too but
|
|
4591
|
+
// record no quantifier string of their own.
|
|
4592
|
+
subjectRaw = quantifiedLocativeSubject(quantLoc);
|
|
4593
|
+
verbRaw = quantLoc[3];
|
|
4594
|
+
objectRaw = `${quantLoc[4]} ${quantLoc[5]}`;
|
|
4595
|
+
quantifier = /^every$/i.test(quantLoc[1]) ? "every" : "";
|
|
4596
|
+
} else if (countLoc) {
|
|
4597
|
+
// "one more disk"/"another disk" name one additional, unnamed
|
|
4598
|
+
// individual — stored exactly like its bare-article twin "a disk
|
|
4599
|
+
// rests on peg-a" below, no quantifier field.
|
|
4600
|
+
subjectRaw = countLoc[1];
|
|
4601
|
+
verbRaw = countLoc[2];
|
|
4602
|
+
objectRaw = `${countLoc[3]} ${countLoc[4]}`;
|
|
4519
4603
|
} else {
|
|
4520
4604
|
const det = p.match(GENERAL_VERB_DETERMINER_TEACH_RE);
|
|
4521
4605
|
if (!det) return null; // not a bare-name subject, and no preposition to pin the verb
|
|
@@ -4556,7 +4640,10 @@ async function generalVerbTeach(payload) {
|
|
|
4556
4640
|
if (PLACE_ADVERB_OBJECT_RE.test(object)) return null; // a place adverb is never a real object
|
|
4557
4641
|
if (await readsAsNarratedEvent(verb, folded.predicate !== mintedPredicate)) return null;
|
|
4558
4642
|
if (await readsAsUnknownEverywhere(subject, verb, object)) return null;
|
|
4559
|
-
return {
|
|
4643
|
+
return {
|
|
4644
|
+
subject, predicate: negated ? negatedPredicate(folded.predicate) : folded.predicate, object,
|
|
4645
|
+
...(quantifier ? { quantifier } : {}),
|
|
4646
|
+
};
|
|
4560
4647
|
}
|
|
4561
4648
|
|
|
4562
4649
|
/** Does this word read as a WORD at all — the committed lexicon knows it as a
|
|
@@ -4728,7 +4815,13 @@ async function bareTeachWrapperNudgeText(text) {
|
|
|
4728
4815
|
// Wired into factReadBack, gated on an already-true `miss` so a real graph
|
|
4729
4816
|
// query is never shadowed. Reuses generalVerbTeach's own exclude guards and
|
|
4730
4817
|
// generalVerbPredicate, plus the SAME adverb-skip, so the two never disagree. ----
|
|
4731
|
-
|
|
4818
|
+
// The optional every/each/all/any lead lets "does every disk rest on peg-a"
|
|
4819
|
+
// reach the same subject the quantified locative teach stores under
|
|
4820
|
+
// ("disk") instead of mis-binding the quantifier itself as the subject
|
|
4821
|
+
// token — a plain "a"/"an" lead already worked because no article can be
|
|
4822
|
+
// mistaken for a subject noun, but "every"/"each"/"all"/"any" all look like
|
|
4823
|
+
// ordinary single-token subjects to this regex without the carve-out.
|
|
4824
|
+
const GENERAL_VERB_YESNO_RE = new RegExp(`^(?:does|did)\\s+(?:(?:every|each|all|any)\\s+)?([\\w'-]+)\\s+${TEACH_ADVERB_SKIP_SRC}([a-z]+)\\s+(.+?)[?.!\\s]*$`, "i");
|
|
4732
4825
|
const GENERAL_VERB_OPEN_RE = new RegExp(`^what\\s+(?:does|did)\\s+([\\w'-]+)\\s+${TEACH_ADVERB_SKIP_SRC}([a-z]+(?:\\s+(?:${PREP_SRC}))?)[?.!\\s]*$`, "i");
|
|
4733
4826
|
/** GENERAL_VERB_EXCLUDE_RE was written for generalVerbTeach's fully-conjugated
|
|
4734
4827
|
* declarative verb ("X OWNS Y", "X MAINTAINS Y") — but "does/did X <verb> Y"
|
|
@@ -5576,6 +5669,7 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
5576
5669
|
// through to the ordinary cascade exactly as it always has.
|
|
5577
5670
|
if (retractNotMatch) {
|
|
5578
5671
|
const { loadMemory: loadMemForNeg, normFactTerm: normTermForNeg, readFactRows: readRowsForNeg } = await import("../adapters/memory/core.mjs");
|
|
5672
|
+
const { DISJOINT_PREDICATE: NEG_DISJOINT_PREDICATE } = await import("../domain/syllogise.mjs");
|
|
5579
5673
|
const negSubject = normTermForNeg(retractSubject);
|
|
5580
5674
|
const negObject = normTermForNeg(retractObject);
|
|
5581
5675
|
const priorRows = readRowsForNeg(await loadMemForNeg(memoryDir));
|
|
@@ -5605,13 +5699,41 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
5605
5699
|
// declining exactly as it always has — this widens which NOUN pairs
|
|
5606
5700
|
// read as an exclusion, never which property claims do.
|
|
5607
5701
|
const singularNegation = retractSrc.match(SINGULAR_NEGATION_TEACH_RE);
|
|
5608
|
-
if (singularNegation
|
|
5702
|
+
if (singularNegation) {
|
|
5609
5703
|
const [, negationSubject, negationObject] = singularNegation;
|
|
5610
|
-
const
|
|
5611
|
-
|
|
5612
|
-
|
|
5613
|
-
|
|
5614
|
-
|
|
5704
|
+
const objectIsDeclaredNoun = !!lookupNoun(loadLexicon(), negationObject);
|
|
5705
|
+
// WIDENED ARM — an individual-level negative stores with no lexicon
|
|
5706
|
+
// entry required at all, so long as (a) the subject reads as an
|
|
5707
|
+
// individual — a declared proper name, a code-ref shape, or a term
|
|
5708
|
+
// this store already carries as an rdf:type/subClassOf subject — and
|
|
5709
|
+
// (b) the object is a class this store already carries (the object
|
|
5710
|
+
// of a taught isa fact, or either side of a taught disjointness),
|
|
5711
|
+
// never a bare adjective. TAUGHT facts only (never corpus background)
|
|
5712
|
+
// decide both checks, the same discipline isTaughtFact applies
|
|
5713
|
+
// elsewhere in this file — a corpus row mentioning "mortal" must never
|
|
5714
|
+
// be able to smuggle an adjective past the guard "zeus is not mortal"
|
|
5715
|
+
// keeps.
|
|
5716
|
+
const isTaughtRow = (r) => !String(r.provenance || "").includes("corpus:") && !String(r.provenance || "").includes("web:");
|
|
5717
|
+
const normNegationSubject = normTermForNeg(negationSubject);
|
|
5718
|
+
const normNegationObject = normTermForNeg(negationObject);
|
|
5719
|
+
const objectIsStoredClass = !objectIsDeclaredNoun && priorRows.some((r) => isTaughtRow(r) && (
|
|
5720
|
+
(ISA_PREDICATES.has(r.predicate) && r.object === normNegationObject)
|
|
5721
|
+
|| (r.predicate === NEG_DISJOINT_PREDICATE && (r.subject === normNegationObject || r.object === normNegationObject))
|
|
5722
|
+
));
|
|
5723
|
+
const subjectIsIndividual = objectIsStoredClass && (
|
|
5724
|
+
!!lookupProperName(loadLexicon(), negationSubject)
|
|
5725
|
+
|| CODE_REF_SHAPE.test(negationSubject)
|
|
5726
|
+
|| priorRows.some((r) => isTaughtRow(r) && r.subject === normNegationSubject && ISA_PREDICATES.has(r.predicate))
|
|
5727
|
+
);
|
|
5728
|
+
if (objectIsDeclaredNoun || subjectIsIndividual) {
|
|
5729
|
+
const negUniversal = await mintNegativeUniversal(negationSubject, negationObject, {
|
|
5730
|
+
memoryDir, sessionId, observedAt, dateText,
|
|
5731
|
+
ackText: objectIsDeclaredNoun
|
|
5732
|
+
? `noted — remembered: no ${negationSubject} is a ${negationObject}`
|
|
5733
|
+
: `noted — remembered: ${negationSubject} is not a ${negationObject}`,
|
|
5734
|
+
});
|
|
5735
|
+
if (negUniversal) return negUniversal;
|
|
5736
|
+
}
|
|
5615
5737
|
}
|
|
5616
5738
|
|
|
5617
5739
|
// Nothing stored to disagree with. The gate above is right to refuse
|
|
@@ -6364,9 +6486,19 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
6364
6486
|
const detLed = raw.match(GENERAL_VERB_DETERMINER_TEACH_RE);
|
|
6365
6487
|
const detHasLed = detLed ? null : raw.match(DETERMINER_HAS_TEACH_RE);
|
|
6366
6488
|
const quantHasLed = (detLed || detHasLed) ? null : raw.match(QUANTIFIED_HAS_TEACH_RE);
|
|
6489
|
+
// The two locative quantifier leads ("every disk rests…", "one more disk
|
|
6490
|
+
// rests…") need the same override as quantHasLed/detHasLed just below:
|
|
6491
|
+
// their own first word ("every"/"one"/"another") never POS-tags as a
|
|
6492
|
+
// NOUN/PROPN, so without this the bare-sentence POS gate silently drops
|
|
6493
|
+
// them exactly the way it used to drop "every overbid has a gouger".
|
|
6494
|
+
const quantLocLed = (detLed || detHasLed || quantHasLed) ? null : raw.match(QUANTIFIED_LOCATIVE_TEACH_RE);
|
|
6495
|
+
const countLocLed = (detLed || detHasLed || quantHasLed || quantLocLed)
|
|
6496
|
+
? null : raw.match(LOCATIVE_COUNTING_TEACH_RE);
|
|
6367
6497
|
const subjectWord = detLed ? detLed[1].split(/\s+/).pop()
|
|
6368
6498
|
: (detHasLed ? detHasLed[1]
|
|
6369
|
-
: (quantHasLed ? quantifiedHasSubject(quantHasLed)
|
|
6499
|
+
: (quantHasLed ? quantifiedHasSubject(quantHasLed)
|
|
6500
|
+
: (quantLocLed ? quantifiedLocativeSubject(quantLocLed)
|
|
6501
|
+
: (countLocLed ? countLocLed[1] : raw.match(/^([\w'-]+)/)?.[1]))));
|
|
6370
6502
|
// The quantifier lead ("every … has …") is itself a strong declarative
|
|
6371
6503
|
// signal, so it overrides the single-token POS gate: a noun that doubles
|
|
6372
6504
|
// as a verb ("every overbid has a gouger" — wink tags "overbid" VERB)
|
|
@@ -6375,7 +6507,7 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
6375
6507
|
// NON_DECLARATIVE_OPENER_RE runs even for these leads — "every umm has a
|
|
6376
6508
|
// thing" isn't a real quantified sentence, just filler that fits the shape.
|
|
6377
6509
|
if (subjectWord && !NON_DECLARATIVE_OPENER_RE.test(subjectWord)
|
|
6378
|
-
&& (quantHasLed || detHasLed || (await subjectIsNounOrPropn(subjectWord)))) {
|
|
6510
|
+
&& (quantHasLed || detHasLed || quantLocLed || countLocLed || (await subjectIsNounOrPropn(subjectWord)))) {
|
|
6379
6511
|
// A PLURAL explicit-capability surface ("wrens can hum") whose
|
|
6380
6512
|
// SINGULAR is a grounded term stores under the singular first — the
|
|
6381
6513
|
// spelling the grounding fact and every query-side variant fold use —
|
|
@@ -7350,6 +7482,7 @@ export async function helpText(codeDomainActive = false, helpRows = undefined) {
|
|
|
7350
7482
|
["/capabilities", "what /plan can plan over: the built-in graph tools plus your taught actions"],
|
|
7351
7483
|
["/goals", "the goals a trace can be recognized against: the maintenance invariants, the tool goals, this world's objective, and your taught actions"],
|
|
7352
7484
|
["/syllogise <term>", "work out and remember what follows from the facts about a term (needed for chains longer than 2 hops)"],
|
|
7485
|
+
["/classify <term>", "run the EL classifier and remember what follows from a term (reaches restriction-shaped conclusions /syllogise's chains can't)"],
|
|
7353
7486
|
["/export <path>", "write the memory store to a file, as JSONL (the same shape `tmct memory --export` writes)"],
|
|
7354
7487
|
["/ingest <path>", "read a local text file and store every fact the recognizer grounds from it (same recognizer as `tmct extract`)"],
|
|
7355
7488
|
["remember <X> is a <Y>", "teach a fact in plain English (\"every X is a Y\" and a bare \"X is a Y\" work too)"],
|
|
@@ -7518,6 +7651,10 @@ const FACT_PREDICATE_PHRASES = {
|
|
|
7518
7651
|
"mgxneg:subClassOf": "is not a kind of",
|
|
7519
7652
|
"rdf:type": "is a",
|
|
7520
7653
|
"owl:disjointWith": "is not a",
|
|
7654
|
+
"owl:unionOf": "is either",
|
|
7655
|
+
"owl:complementOf": "is anything that is not",
|
|
7656
|
+
"owl:oneOf": "includes exactly",
|
|
7657
|
+
"owl:differentFrom": "is not the same as",
|
|
7521
7658
|
"mgx:partOf": "is part of",
|
|
7522
7659
|
"mgx:memberOf": "is a member of",
|
|
7523
7660
|
"mgx:collectionOf": "is a collection of",
|
|
@@ -7571,6 +7708,15 @@ const WORLD_INTERNAL_PREDICATES = new Set([
|
|
|
7571
7708
|
"mgx:is-container", "mgx:is-open",
|
|
7572
7709
|
]);
|
|
7573
7710
|
|
|
7711
|
+
/** A `<role> rdf:type owl:TransitiveProperty` declaration is role scaffolding,
|
|
7712
|
+
* not a fact about the role a reader wants listed back in English — it never
|
|
7713
|
+
* renders as a plain fact line, the same discipline that keeps the
|
|
7714
|
+
* restriction scaffolding predicates (owl:onProperty, owl:someValuesFrom, …)
|
|
7715
|
+
* out of FACT_PREDICATE_PHRASES. */
|
|
7716
|
+
function isTransitivePropertyDeclaration(f) {
|
|
7717
|
+
return f.predicate === TYPE_PREDICATE && f.object === "transitiveproperty";
|
|
7718
|
+
}
|
|
7719
|
+
|
|
7574
7720
|
/** The world PLACEMENT predicates carry curated phrases above so they render as
|
|
7575
7721
|
* English, but they must stay OUT of the query-marker families derived from
|
|
7576
7722
|
* FACT_PREDICATE_PHRASES — "what is in the study" is a members-of-class query,
|
|
@@ -7737,6 +7883,41 @@ function renderFactLine(f) {
|
|
|
7737
7883
|
return `i learned: ${factPhrase(f)}${cite}`;
|
|
7738
7884
|
}
|
|
7739
7885
|
|
|
7886
|
+
/** A union node's stored triples read back as ONE sentence rather than a
|
|
7887
|
+
* row-per-member dump: "every pet is a cat or a dog (source: …)". `node` is
|
|
7888
|
+
* the `<parent> rdfs:subClassOf <unionNode>` fact row (the parent and the
|
|
7889
|
+
* citation both come from it); `members` are the union node's own
|
|
7890
|
+
* `owl:unionOf` rows, sorted here by member name so the same union always
|
|
7891
|
+
* reads back the same way regardless of the order its rows arrived in.
|
|
7892
|
+
* Pure — takes the fact rows, returns one line. */
|
|
7893
|
+
function renderUnionLine(node, members) {
|
|
7894
|
+
const sorted = [...members].sort((a, b) => a.object.localeCompare(b.object));
|
|
7895
|
+
const cite = node.provenance ? ` (source: ${citationProvenance(node.provenance)})` : "";
|
|
7896
|
+
const arms = sorted.map((m) => `${indefiniteArticleFor(m.object)} ${m.object}`).join(" or ");
|
|
7897
|
+
return `every ${node.subject} is ${arms}${cite}`;
|
|
7898
|
+
}
|
|
7899
|
+
|
|
7900
|
+
/** An enumerated class's stored `owl:oneOf` triples read back as ONE sentence:
|
|
7901
|
+
* "the primary colours are exactly red, yellow and blue (source: …)". `cls`
|
|
7902
|
+
* is the enumerated class's own term; `members` are its `owl:oneOf` rows,
|
|
7903
|
+
* sorted here by member name for the same order-independence renderUnionLine
|
|
7904
|
+
* keeps. The class name pluralizes through the same naive "+s/+es/+ies" fold
|
|
7905
|
+
* thirdPersonSingularSurface already applies to a verb lemma — the same
|
|
7906
|
+
* accepted trade documented there. Pure — takes the fact rows, returns one
|
|
7907
|
+
* line. */
|
|
7908
|
+
function renderEnumerationLine(cls, members) {
|
|
7909
|
+
const sorted = [...members].sort((a, b) => a.object.localeCompare(b.object));
|
|
7910
|
+
const names = sorted.map((m) => m.object);
|
|
7911
|
+
const list = names.length > 1
|
|
7912
|
+
? `${names.slice(0, -1).join(", ")} and ${names[names.length - 1]}`
|
|
7913
|
+
: names.join("");
|
|
7914
|
+
const citeSource = sorted.find((m) => m.provenance)?.provenance;
|
|
7915
|
+
const cite = citeSource ? ` (source: ${citationProvenance(citeSource)})` : "";
|
|
7916
|
+
const plural = thirdPersonSingularSurface(String(cls || "").replace(/-/g, " "));
|
|
7917
|
+
return `the ${plural} are exactly ${list}${cite}`;
|
|
7918
|
+
}
|
|
7919
|
+
export { renderUnionLine, renderEnumerationLine };
|
|
7920
|
+
|
|
7740
7921
|
const SENSE_CITE_RE = / \(source: [^)]*\)$/;
|
|
7741
7922
|
|
|
7742
7923
|
/** Append an is-a object's superclass chain to its rendered fact line, before
|
|
@@ -8358,6 +8539,14 @@ function apposedFactTerm(term, rows, normFactTerm) {
|
|
|
8358
8539
|
* factReadBack(...)` — never both). */
|
|
8359
8540
|
const CAN_ASK_RE = /^(?:can|could)\s+(all\s+|every\s+)?(?:an?\s+)?([\w'-]+(?:\s+[\w'-]+)*?)\s+([a-z]+)[?.!\s]*$/i;
|
|
8360
8541
|
const DOES_HAVE_ASK_RE = /^(?:does|do)\s+(?:an?\s+|the\s+)?(.+?)\s+have\s+(?:an?\s+|the\s+)?(.+?)[?.!\s]*$/i;
|
|
8542
|
+
/** The class-level existential sibling of DOES_HAVE_ASK_RE for a verb OTHER
|
|
8543
|
+
* than "have" — "does a heart contain a hinge". A someValuesFrom
|
|
8544
|
+
* restriction (taught, or EL-entailed by /classify) never cares which
|
|
8545
|
+
* English near-synonym for "has" named it, and the store carries no
|
|
8546
|
+
* per-verb sense distinction for this shape yet, so restrictionExistentialHit
|
|
8547
|
+
* answers on the (subject, filler) SHAPE alone, tried only once
|
|
8548
|
+
* DOES_HAVE_ASK_RE's own literal-"have" reader has already declined. */
|
|
8549
|
+
const DOES_EXISTENTIAL_ASK_RE = /^(?:does|do)\s+(?:an?\s+|the\s+)?(.+?)\s+([a-z]+)\s+(?:an?\s+|the\s+)?(.+?)[?.!\s]*$/i;
|
|
8361
8550
|
const WHAT_CAN_DO_RE = /^what\s+can\s+(?:an?\s+)?(.+?)\s+do[?.!\s]*$/i;
|
|
8362
8551
|
const WHAT_HAS_RE = /^what\s+has\s+(?:an?\s+)?(.+?)[?.!\s]*$/i;
|
|
8363
8552
|
// "what is used for riding" / "what can be used for riding" / "what is for
|
|
@@ -8760,6 +8949,61 @@ function withDeducedGoal(res, envelope, query) {
|
|
|
8760
8949
|
return goal ? { ...res, goal } : res;
|
|
8761
8950
|
}
|
|
8762
8951
|
|
|
8952
|
+
/** The class-level existential mirror of a direct hasA/tmct:has fact: a
|
|
8953
|
+
* stored (taught, or EL-entailed by /classify) someValuesFrom restriction
|
|
8954
|
+
* reachable from the subject names the filler. Runs off `factRows` rather
|
|
8955
|
+
* than the reduced `memoryFacts` shape because the citation needs each
|
|
8956
|
+
* hit's own `justification` — an EL-derived restriction cites the taught
|
|
8957
|
+
* premises it composed (e.g. "heart is a kind of some-has-valve; valve is a
|
|
8958
|
+
* kind of flap"), not just its own single entailed row. Falls back to
|
|
8959
|
+
* citing the hit itself when no subClassOf premise is on record (a directly
|
|
8960
|
+
* taught, unchained restriction). Returns the rendered `{text,
|
|
8961
|
+
* replace: true}` yes turn on a hit. On a miss, `subjectWord` (the surface
|
|
8962
|
+
* text the question named the subject with) decides the reply: the subject
|
|
8963
|
+
* has SOME remembered restriction that just doesn't reach this filler, so
|
|
8964
|
+
* the miss names `/classify` — the one command that can compose further
|
|
8965
|
+
* ("/syllogise" is never offered here, since its plain scm-sco chase never
|
|
8966
|
+
* touches a class expression) — or, with no restriction on the subject at
|
|
8967
|
+
* all, plain null so the caller's own miss cascade stands unchanged. */
|
|
8968
|
+
async function restrictionExistentialHit(memoryDir, cache, subjectVariants, fillerVariants, subjectWord = null) {
|
|
8969
|
+
const { ON_PROPERTY_PREDICATE, SOME_VALUES_FROM_PREDICATE } = await import("../domain/syllogise.mjs");
|
|
8970
|
+
const rows = await factRows(memoryDir, cache);
|
|
8971
|
+
const onPropertyOf = new Map();
|
|
8972
|
+
const someValuesFromOf = new Map();
|
|
8973
|
+
for (const r of rows) {
|
|
8974
|
+
if (r.predicate === ON_PROPERTY_PREDICATE) onPropertyOf.set(r.subject, r.object);
|
|
8975
|
+
else if (r.predicate === SOME_VALUES_FROM_PREDICATE) someValuesFromOf.set(r.subject, r.object);
|
|
8976
|
+
}
|
|
8977
|
+
// Restricted to a genuine someValuesFrom restriction — onProperty alone
|
|
8978
|
+
// also marks a cardinality restriction (owl:maxCardinality/minCardinality/
|
|
8979
|
+
// cardinality, no someValuesFrom row of its own), which classifyEl's EL
|
|
8980
|
+
// rules never touch; offering /classify over one would be wrong advice,
|
|
8981
|
+
// and it would also swallow a query the cardinality live chases
|
|
8982
|
+
// (factReadBackReaders' CARD_AT_LEAST_ASK_RE/CARD_EXISTENCE_ASK_RE) are
|
|
8983
|
+
// the ones meant to answer, including a provable "no".
|
|
8984
|
+
const subjectRestrictions = rows.filter((r) => r.predicate === SUBCLASS_PREDICATE && subjectVariants.has(r.subject)
|
|
8985
|
+
&& onPropertyOf.has(r.object) && someValuesFromOf.has(r.object));
|
|
8986
|
+
const hit = subjectRestrictions
|
|
8987
|
+
.filter((r) => fillerVariants.has(someValuesFromOf.get(r.object)))
|
|
8988
|
+
.sort((a, b) => a.object.localeCompare(b.object))[0];
|
|
8989
|
+
if (hit) {
|
|
8990
|
+
const byId = new Map(rows.map((r) => [r.id, r]));
|
|
8991
|
+
const premises = (hit.justification || [])
|
|
8992
|
+
.map((id) => byId.get(id))
|
|
8993
|
+
.filter((r) => r && r.predicate === SUBCLASS_PREDICATE);
|
|
8994
|
+
const cited = premises.length ? premises : [hit];
|
|
8995
|
+
return { text: `yes — ${cited.map(renderFactLine).join("; ")}`, replace: true };
|
|
8996
|
+
}
|
|
8997
|
+
if (subjectRestrictions.length && subjectWord) {
|
|
8998
|
+
return {
|
|
8999
|
+
text: `I can't confirm that — nothing I remember composes to it yet. Run "/classify ${subjectWord}", then ask me again.`,
|
|
9000
|
+
replace: true,
|
|
9001
|
+
miss: true,
|
|
9002
|
+
};
|
|
9003
|
+
}
|
|
9004
|
+
return null;
|
|
9005
|
+
}
|
|
9006
|
+
|
|
8763
9007
|
async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle = {}, cache = null, focusLabel = null) {
|
|
8764
9008
|
let normFactTerm; let normFactPredicate;
|
|
8765
9009
|
try { ({ normFactTerm, normFactPredicate } = await import("../adapters/memory/core.mjs")); } catch { return null; }
|
|
@@ -9099,7 +9343,7 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
9099
9343
|
// and mechanics predicates are dropped so "what is the letter" never reads
|
|
9100
9344
|
// back where it's hidden or that it's the objective (WORLD_INTERNAL_PREDICATES).
|
|
9101
9345
|
const subjectHits = (await factRows(memoryDir, cache))
|
|
9102
|
-
.filter((f) => variants.has(f.subject) && !WORLD_INTERNAL_PREDICATES.has(f.predicate));
|
|
9346
|
+
.filter((f) => variants.has(f.subject) && !WORLD_INTERNAL_PREDICATES.has(f.predicate) && !isTransitivePropertyDeclaration(f));
|
|
9103
9347
|
// Matched through normFactPredicate, so a fact stored under a minted
|
|
9104
9348
|
// spelling of the same relation ("mgx:used-for", from the participle
|
|
9105
9349
|
// teach frame, in a store written before the spellings converged) is
|
|
@@ -9384,7 +9628,24 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
9384
9628
|
if (!nextFrontier.length) break;
|
|
9385
9629
|
frontier = nextFrontier;
|
|
9386
9630
|
}
|
|
9387
|
-
|
|
9631
|
+
// No direct or ⊑-lifted possession fact — a bare-existential teach or an
|
|
9632
|
+
// EL classification stores the SAME knowledge as a subClassOf-to-
|
|
9633
|
+
// restriction chain rather than a flat possession triple, so try that
|
|
9634
|
+
// shape before declining.
|
|
9635
|
+
return restrictionExistentialHit(memoryDir, cache, subj, obj, doesHave[1].trim());
|
|
9636
|
+
}
|
|
9637
|
+
|
|
9638
|
+
// (b2b-el) "does a heart contain a hinge" — DOES_HAVE_ASK_RE only ever
|
|
9639
|
+
// matches the literal verb "have"; a class-level existential question can
|
|
9640
|
+
// use any near-synonym, so this sibling reader tries the SAME restriction
|
|
9641
|
+
// chase restrictionExistentialHit runs above, keyed on shape alone, once
|
|
9642
|
+
// (b2b)'s own literal-"have" surface has already declined to match at all.
|
|
9643
|
+
const doesExistential = q.match(DOES_EXISTENTIAL_ASK_RE);
|
|
9644
|
+
if (doesExistential) {
|
|
9645
|
+
const subj = factTermVariants(normFactTerm, doesExistential[1]);
|
|
9646
|
+
const obj = factTermVariants(normFactTerm, doesExistential[3]);
|
|
9647
|
+
const hit = await restrictionExistentialHit(memoryDir, cache, subj, obj, doesExistential[1].trim());
|
|
9648
|
+
if (hit) return hit;
|
|
9388
9649
|
}
|
|
9389
9650
|
|
|
9390
9651
|
// (b2c) "do birds fly" — the do-support surface of (b2), same capableOf
|
|
@@ -9705,7 +9966,7 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
9705
9966
|
// objective, and those datatype internals render as garbled non-English
|
|
9706
9967
|
// besides. The adventure's own where/openness readers answer the legitimate
|
|
9707
9968
|
// in-game questions from the world fold.
|
|
9708
|
-
hits = hits.filter((f) => !WORLD_INTERNAL_PREDICATES.has(f.predicate));
|
|
9969
|
+
hits = hits.filter((f) => !WORLD_INTERNAL_PREDICATES.has(f.predicate) && !isTransitivePropertyDeclaration(f));
|
|
9709
9970
|
// A corpus-weak-only result set (every hit resolved ONLY through
|
|
9710
9971
|
// ConceptNet's /r/RelatedTo tier) still composes its hedged "possibly"
|
|
9711
9972
|
// lines below exactly as before — this reader's whole job is showing
|
|
@@ -11055,9 +11316,29 @@ async function factReadBackReaders(memoryDir, query, envelope, miss, graph = nul
|
|
|
11055
11316
|
);
|
|
11056
11317
|
if (knownSubjectIsa.length) {
|
|
11057
11318
|
const shown = knownSubjectIsa.slice(0, 3).map(renderFactLine).join("; ");
|
|
11058
|
-
|
|
11059
|
-
|
|
11060
|
-
|
|
11319
|
+
// A someValuesFrom restriction node among the subject's own remembered
|
|
11320
|
+
// isa facts means the gap is a class expression /syllogise's plain
|
|
11321
|
+
// scm-sco chase never reaches — /classify is the offer that can
|
|
11322
|
+
// actually close it, named instead of /syllogise rather than beside
|
|
11323
|
+
// it, so the offer never points at a command that provably can't help.
|
|
11324
|
+
// A CARDINALITY restriction (owl:maxCardinality/minCardinality/
|
|
11325
|
+
// cardinality, also onProperty-bearing but with no someValuesFrom row
|
|
11326
|
+
// of its own) is excluded on purpose: classifyEl's rules don't touch
|
|
11327
|
+
// that shape either.
|
|
11328
|
+
const { ON_PROPERTY_PREDICATE: RESTRICTION_ON_PROPERTY, SOME_VALUES_FROM_PREDICATE: RESTRICTION_SOME_VALUES_FROM } = await import("../domain/syllogise.mjs");
|
|
11329
|
+
const onPropertyNodes = new Set();
|
|
11330
|
+
const someValuesFromNodes = new Set();
|
|
11331
|
+
for (const f of rows) {
|
|
11332
|
+
if (f.predicate === RESTRICTION_ON_PROPERTY) onPropertyNodes.add(f.subject);
|
|
11333
|
+
else if (f.predicate === RESTRICTION_SOME_VALUES_FROM) someValuesFromNodes.add(f.subject);
|
|
11334
|
+
}
|
|
11335
|
+
const restrictionNodes = new Set([...onPropertyNodes].filter((n) => someValuesFromNodes.has(n)));
|
|
11336
|
+
const involvesRestriction = knownSubjectIsa.some((f) => restrictionNodes.has(f.object));
|
|
11337
|
+
const recovery = involvesRestriction
|
|
11338
|
+
? `The facts to settle it are here, but reaching it means composing a restriction /syllogise doesn't follow. Run "/classify ${subjectWord}", then ask me again.`
|
|
11339
|
+
: deeperChainExists
|
|
11340
|
+
? `The facts to settle it are here, but the chain is longer than I follow while answering. Run "/syllogise ${subjectWord}", then ask me again.`
|
|
11341
|
+
: `If it's true, teach me: "${subjectWord} is a kind of ${kindWord}". If it isn't, teach me: "no ${subjectWord} is a ${kindWord}".`;
|
|
11061
11342
|
return {
|
|
11062
11343
|
text: `I can't confirm that — nothing I remember says ${subjectWord} is a ${kindWord}. I do know: ${shown}. ${recovery}`,
|
|
11063
11344
|
replace: true,
|
|
@@ -12250,26 +12531,107 @@ async function ingestReferenceArticle(memoryDir, key, article, cache, tagFor = r
|
|
|
12250
12531
|
// materialisation, not the whole-store maintenance job /syllogise runs.
|
|
12251
12532
|
const AUTO_SYNTHESIS_BUDGET = 12;
|
|
12252
12533
|
|
|
12534
|
+
/** The `[reasoning]` knobs for a classification pass rooted at `memoryDir` —
|
|
12535
|
+
* the repo's own `tmct.toml` when it sets one, the shipped defaults
|
|
12536
|
+
* otherwise. `resolveReasoningConfig` wants the NORMALIZED sparse pass-
|
|
12537
|
+
* through `normalizeConfig` produces (a bare `loadTomlConfig` object has no
|
|
12538
|
+
* `.reasoning` key of its own), the same load-then-normalize sequence the
|
|
12539
|
+
* CLI's own `resolveRuntimeConfig` already runs. Failure-tolerant: a missing
|
|
12540
|
+
* or unreadable `tmct.toml` degrades to the defaults, never a thrown error. */
|
|
12541
|
+
async function resolveReasoningConfigForRepo(memoryDir) {
|
|
12542
|
+
const { resolveReasoningConfig } = await import("../domain/reasoning-config.mjs");
|
|
12543
|
+
try {
|
|
12544
|
+
const { loadTomlConfig, normalizeConfig } = await import("../adapters/toml-config.mjs");
|
|
12545
|
+
const raw = await loadTomlConfig(memoryDir);
|
|
12546
|
+
const normalized = await normalizeConfig(raw, { configDir: memoryDir });
|
|
12547
|
+
return resolveReasoningConfig(normalized);
|
|
12548
|
+
} catch {
|
|
12549
|
+
return resolveReasoningConfig(null);
|
|
12550
|
+
}
|
|
12551
|
+
}
|
|
12552
|
+
|
|
12553
|
+
/** The focus set classifyEl needs to reach a bare-existential or transitive-
|
|
12554
|
+
* role chain rooted at `seedTerms`: each seed's own `rdfs:subClassOf`
|
|
12555
|
+
* descendant walk, folded through every someValuesFrom restriction it
|
|
12556
|
+
* reaches onto that restriction's own filler, walked again from there — so
|
|
12557
|
+
* a taught "heart ⊑ ∃has.valve, valve ⊑ ∃has.hinge" reaches both `valve`
|
|
12558
|
+
* and `hinge` from a focus seeded on `heart` alone. classifyEl's own focus
|
|
12559
|
+
* gate takes its input as given (unlike syllogise's `expandFocus`, it has no
|
|
12560
|
+
* expansion step of its own), so this walk runs here rather than inside the
|
|
12561
|
+
* classifier. Bounded by `hops`. Pure. */
|
|
12562
|
+
function elClassifyFocus(rows, seedTerms, onPropertyPredicate, someValuesFromPredicate, hops = 8) {
|
|
12563
|
+
const subClassOf = new Map();
|
|
12564
|
+
const onPropertyOf = new Map();
|
|
12565
|
+
const someValuesFromOf = new Map();
|
|
12566
|
+
for (const r of rows) {
|
|
12567
|
+
if (r.predicate === SUBCLASS_PREDICATE) {
|
|
12568
|
+
if (!subClassOf.has(r.subject)) subClassOf.set(r.subject, []);
|
|
12569
|
+
subClassOf.get(r.subject).push(r.object);
|
|
12570
|
+
} else if (r.predicate === onPropertyPredicate) {
|
|
12571
|
+
onPropertyOf.set(r.subject, r.object);
|
|
12572
|
+
} else if (r.predicate === someValuesFromPredicate) {
|
|
12573
|
+
someValuesFromOf.set(r.subject, r.object);
|
|
12574
|
+
}
|
|
12575
|
+
}
|
|
12576
|
+
const focus = new Set(seedTerms);
|
|
12577
|
+
let frontier = [...focus];
|
|
12578
|
+
for (let hop = 0; hop < hops && frontier.length; hop += 1) {
|
|
12579
|
+
const next = [];
|
|
12580
|
+
for (const t of frontier) {
|
|
12581
|
+
for (const obj of subClassOf.get(t) || []) {
|
|
12582
|
+
if (!focus.has(obj)) { focus.add(obj); next.push(obj); }
|
|
12583
|
+
const filler = onPropertyOf.has(obj) ? someValuesFromOf.get(obj) : null;
|
|
12584
|
+
if (filler && !focus.has(filler)) { focus.add(filler); next.push(filler); }
|
|
12585
|
+
}
|
|
12586
|
+
}
|
|
12587
|
+
frontier = next;
|
|
12588
|
+
}
|
|
12589
|
+
return focus;
|
|
12590
|
+
}
|
|
12591
|
+
|
|
12253
12592
|
/** After a learn-on-miss load stored new facts about `term`, run a bounded,
|
|
12254
12593
|
* focus-scoped forward-chaining pass so the new facts connect to what's
|
|
12255
|
-
* already remembered — the auto sibling of the /syllogise command
|
|
12594
|
+
* already remembered — the auto sibling of the /syllogise command, plus its
|
|
12595
|
+
* EL sibling (the auto sibling of /classify): the same seed focus feeds
|
|
12596
|
+
* both, syllogise expanding it through its own `expandFocus`, classifyEl
|
|
12597
|
+
* through `elClassifyFocus` since it has no such option of its own. Derived
|
|
12256
12598
|
* facts carry entailed:* provenance at their discounted trust and are
|
|
12257
|
-
* retractable.
|
|
12258
|
-
*
|
|
12599
|
+
* retractable. Both passes are failure-tolerated and independent of each
|
|
12600
|
+
* other: neither a syllogise miss nor an EL miss disturbs the answer the
|
|
12601
|
+
* load already composed, or the other pass's own result. Returns the total
|
|
12602
|
+
* count derived across both. */
|
|
12259
12603
|
async function synthesiseAroundTerm(memoryDir, term, cache, budget = AUTO_SYNTHESIS_BUDGET) {
|
|
12260
12604
|
if (!memoryDir || !term || budget <= 0) return 0;
|
|
12605
|
+
let count = 0;
|
|
12261
12606
|
try {
|
|
12262
12607
|
const { syllogise } = await import("../domain/syllogise.mjs");
|
|
12263
12608
|
const { loadMemory, readFactRows, appendFacts, normFactTerm } = await import("../adapters/memory/core.mjs");
|
|
12609
|
+
const seedFocus = [...factTermVariants(normFactTerm, term)];
|
|
12264
12610
|
const res = await syllogise(memoryDir, {
|
|
12265
|
-
focus:
|
|
12611
|
+
focus: seedFocus,
|
|
12266
12612
|
expandFocus: true,
|
|
12267
12613
|
budget,
|
|
12268
12614
|
store: { loadMemory, readFactRows, appendFacts },
|
|
12269
12615
|
});
|
|
12270
|
-
if (res?.count
|
|
12271
|
-
|
|
12272
|
-
|
|
12616
|
+
if (res?.count) { count += res.count; if (cache) cache.rows = null; }
|
|
12617
|
+
} catch { /* a syllogise miss never disturbs the answer the load already composed */ }
|
|
12618
|
+
try {
|
|
12619
|
+
const { classifyEl } = await import("../domain/el-classify.mjs");
|
|
12620
|
+
const { ON_PROPERTY_PREDICATE, SOME_VALUES_FROM_PREDICATE } = await import("../domain/syllogise.mjs");
|
|
12621
|
+
const { loadMemory, readFactRows, appendFacts, normFactTerm } = await import("../adapters/memory/core.mjs");
|
|
12622
|
+
const seedFocus = [...factTermVariants(normFactTerm, term)];
|
|
12623
|
+
const rows = readFactRows(await loadMemory(memoryDir));
|
|
12624
|
+
const focus = elClassifyFocus(rows, seedFocus, ON_PROPERTY_PREDICATE, SOME_VALUES_FROM_PREDICATE);
|
|
12625
|
+
const reasoning = await resolveReasoningConfigForRepo(memoryDir);
|
|
12626
|
+
const elRes = await classifyEl(memoryDir, {
|
|
12627
|
+
budget: reasoning.classifyBudget,
|
|
12628
|
+
rounds: reasoning.classifyRounds,
|
|
12629
|
+
focus,
|
|
12630
|
+
store: { loadMemory, readFactRows, appendFacts },
|
|
12631
|
+
});
|
|
12632
|
+
if (elRes?.count) { count += elRes.count; if (cache) cache.rows = null; }
|
|
12633
|
+
} catch { /* an EL pass miss never disturbs the answer the load already composed */ }
|
|
12634
|
+
return count;
|
|
12273
12635
|
}
|
|
12274
12636
|
|
|
12275
12637
|
/** The term an explicit "ask Wikipedia" phrasing names — "what does wikipedia
|
|
@@ -15880,6 +16242,54 @@ async function runCommand(line, { config, source, graph, focus, memoryDir, trace
|
|
|
15880
16242
|
}
|
|
15881
16243
|
}
|
|
15882
16244
|
|
|
16245
|
+
// /classify <term> — run one bounded EL saturation pass (src/domain/el-
|
|
16246
|
+
// classify.mjs) over what's remembered about a term and WRITE the entailed
|
|
16247
|
+
// facts it closes over. /syllogise's own rule set only chains
|
|
16248
|
+
// rdfs:subClassOf/rdf:type edges; /classify's seven EL completion rules
|
|
16249
|
+
// additionally reach class expressions the graph never declared as a node
|
|
16250
|
+
// (an owl:someValuesFrom restriction), so the two commands cover different
|
|
16251
|
+
// ground rather than one superseding the other. Same posture as
|
|
16252
|
+
// /syllogise: an explicit request, a required term (the whole-store pass
|
|
16253
|
+
// spends its budget on facts nobody asked about), and every written fact
|
|
16254
|
+
// carries entailed:el-* provenance, a justification and a trust discounted
|
|
16255
|
+
// below the premises it rode.
|
|
16256
|
+
if (name === "classify") {
|
|
16257
|
+
note(trace, "goal: classify what's remembered about one term under the EL completion rules, writing what follows");
|
|
16258
|
+
if (!memoryDir) return mk("no memory store here — /classify works inside a repo session.", { miss: true });
|
|
16259
|
+
if (!argText) {
|
|
16260
|
+
return mk('/classify needs a term, e.g. `/classify heart` — it closes over what I remember about that term.', { miss: true });
|
|
16261
|
+
}
|
|
16262
|
+
try {
|
|
16263
|
+
const { classifyEl } = await import("../domain/el-classify.mjs");
|
|
16264
|
+
const { loadMemory, readFactRows, appendFacts, normFactTerm } = await import("../adapters/memory/core.mjs");
|
|
16265
|
+
const { SUBCLASS_PREDICATE, ON_PROPERTY_PREDICATE, SOME_VALUES_FROM_PREDICATE } = await import("../domain/syllogise.mjs");
|
|
16266
|
+
const reasoning = await resolveReasoningConfigForRepo(memoryDir);
|
|
16267
|
+
const rows = readFactRows(await loadMemory(memoryDir));
|
|
16268
|
+
const focus = elClassifyFocus(rows, [...factTermVariants(normFactTerm, argText)], ON_PROPERTY_PREDICATE, SOME_VALUES_FROM_PREDICATE);
|
|
16269
|
+
const res = await classifyEl(memoryDir, {
|
|
16270
|
+
budget: reasoning.classifyBudget,
|
|
16271
|
+
rounds: reasoning.classifyRounds,
|
|
16272
|
+
focus,
|
|
16273
|
+
store: { loadMemory, readFactRows, appendFacts },
|
|
16274
|
+
});
|
|
16275
|
+
note(trace, `result: derived ${res.count} entailed fact(s) (rounds ${res.rounds}, budget ${res.budget})`);
|
|
16276
|
+
if (!res.count) {
|
|
16277
|
+
return mk(`nothing new classifies from what I remember about "${argText}" — no entailed facts derived (rounds ${res.rounds}, budget ${res.budget}).`, { miss: true });
|
|
16278
|
+
}
|
|
16279
|
+
const lines = [`derived ${res.count} entailed fact(s) classifying "${argText}":`];
|
|
16280
|
+
for (const d of res.derived) lines.push(` ${d.subject} ${SUBCLASS_PREDICATE} ${d.object} (${d.rule})`);
|
|
16281
|
+
// Same reasoning as /syllogise's own budget-wall line: a truncated pass
|
|
16282
|
+
// that still can't answer the question is worse than no offer at all.
|
|
16283
|
+
if (res.truncated) {
|
|
16284
|
+
lines.push(`budget of ${res.budget} reached — more may follow; run \`tmct classify --budget <n>\` for a wider pass.`);
|
|
16285
|
+
}
|
|
16286
|
+
lines.push("These are derived, not taught — /memory shows each one's provenance and premises.");
|
|
16287
|
+
return mk(lines.join("\n"));
|
|
16288
|
+
} catch (e) {
|
|
16289
|
+
return mk(String(e?.message || e), { miss: true }); // a broken store reads as its own clean error
|
|
16290
|
+
}
|
|
16291
|
+
}
|
|
16292
|
+
|
|
15883
16293
|
// /export <path> — write the whole memory store as JSONL, the SAME shape
|
|
15884
16294
|
// `tmct memory --export` and the tmct_export cold tool already emit
|
|
15885
16295
|
// (serializeFactsJsonl, export-jsonl.mjs) — so a chat session can take its
|
|
@@ -17465,6 +17875,64 @@ async function dispatchTurn(input, { config, source = defaultSource, graph = nul
|
|
|
17465
17875
|
}
|
|
17466
17876
|
|
|
17467
17877
|
if (workingLine.startsWith("/")) return withLast(await runCommand(workingLine, ctx), "use a specific tool/command directly");
|
|
17878
|
+
// CLOSED MULTIPLE-CHOICE — "is a whale a fish or a mammal", "A) ... B) ...".
|
|
17879
|
+
// Recognized and answered ENTIRELY here, before the write boundary just
|
|
17880
|
+
// below (assertTurn/bareTaxonomyTeach): a choice question's own object slot
|
|
17881
|
+
// carries "or", and falling through would hand that slot to the teach-offer
|
|
17882
|
+
// cascade, which reads it as a thing to be taught — the same failure mode
|
|
17883
|
+
// TEMPORAL_COMPARISON_RE (runAsk, above) exists to dodge for its own shape.
|
|
17884
|
+
// Placed here rather than beside the temporal lanes in runAsk (the closer
|
|
17885
|
+
// stylistic precedent) because runAsk's own band sits AFTER this boundary —
|
|
17886
|
+
// a choice question routed there would still pass through assertTurn first,
|
|
17887
|
+
// resting the write-boundary guarantee on teachLane's own stand-down gates
|
|
17888
|
+
// rather than on control flow. Every branch below resolves the turn; none
|
|
17889
|
+
// falls through, so the boundary holds structurally.
|
|
17890
|
+
{
|
|
17891
|
+
const parsed = splitChoiceQuestion(workingLine);
|
|
17892
|
+
if (parsed) {
|
|
17893
|
+
const choiceGoal = "pick the option a stated relation grounds, among a closed set of alternatives";
|
|
17894
|
+
const refMiss = (text) => {
|
|
17895
|
+
note(trace, `goal: ${choiceGoal}`);
|
|
17896
|
+
note(trace, `lane: splitChoiceQuestion — "${workingLine}" parsed as a ${parsed.shape} choice question but could not compose an answer`);
|
|
17897
|
+
return withLast(plainTurn(workingLine, text, { via: "miss", miss: true, focus, goal: choiceGoal }), choiceGoal);
|
|
17898
|
+
};
|
|
17899
|
+
if (!parsed.sourceTerm) {
|
|
17900
|
+
return refMiss(`I can't tell what these options are alternatives about — nothing in "${parsed.stem}" reads as a subject term to check them against.`);
|
|
17901
|
+
}
|
|
17902
|
+
const probed = await probeChoiceOptions(parsed, { memoryDir, env, cache: factRowsCache, graph, synthesisBudget });
|
|
17903
|
+
const grounded = probed.filter((o) => o.grounds);
|
|
17904
|
+
note(trace, `goal: ${choiceGoal}`);
|
|
17905
|
+
if (grounded.length === 0) {
|
|
17906
|
+
note(trace, `lane: splitChoiceQuestion — no stated relation between "${parsed.sourceTerm}" and any of ${probed.length} options; the honest miss, never a guess`);
|
|
17907
|
+
return refMiss(`I don't know how "${parsed.sourceTerm}" relates to any of ${joinOr(probed.map((o) => o.text))}. Nothing I hold connects it to one of them.`);
|
|
17908
|
+
}
|
|
17909
|
+
if (grounded.length > 1) {
|
|
17910
|
+
// A tie is reported, never broken — whatever the grounded options'
|
|
17911
|
+
// own edge weights, this branch fires on COUNT alone.
|
|
17912
|
+
note(trace, `lane: splitChoiceQuestion — ${grounded.length} of ${probed.length} options ground against "${parsed.sourceTerm}"; reported as a tie`);
|
|
17913
|
+
const text = `More than one of those grounds: ${joinOr(grounded.map((o) => o.text))}. I have a stated relation from ${parsed.sourceTerm} to each, so nothing in what I hold picks between them.`;
|
|
17914
|
+
const turn = plainTurn(workingLine, text, { via: "composed", miss: false, focus, goal: choiceGoal });
|
|
17915
|
+
turn.lane = "ask-choice";
|
|
17916
|
+
turn.detail = {
|
|
17917
|
+
traversal: `${grounded.length} of ${probed.length} options grounded against "${parsed.sourceTerm}"`,
|
|
17918
|
+
matches: grounded.flatMap((o) => o.facts),
|
|
17919
|
+
};
|
|
17920
|
+
return withLast(turn, choiceGoal);
|
|
17921
|
+
}
|
|
17922
|
+
const winner = grounded[0];
|
|
17923
|
+
const fact = winner.facts.slice().sort((a, b) => b.trust - a.trust)[0];
|
|
17924
|
+
note(trace, `lane: splitChoiceQuestion — exactly one option ("${winner.label}") grounds against "${parsed.sourceTerm}"; cited the deciding fact`);
|
|
17925
|
+
const text = `${winner.text} — ${factPhrase(fact)} (source: ${citationProvenance(fact.provenance)}).`;
|
|
17926
|
+
const turn = plainTurn(workingLine, text, { via: "composed", miss: false, focus, goal: choiceGoal });
|
|
17927
|
+
turn.lane = "ask-choice";
|
|
17928
|
+
turn.detail = {
|
|
17929
|
+
traversal: `option "${winner.label}" grounded against "${parsed.sourceTerm}" via ${fact.predicate}`,
|
|
17930
|
+
matches: winner.facts,
|
|
17931
|
+
selectedLabel: winner.label,
|
|
17932
|
+
};
|
|
17933
|
+
return withLast(turn, choiceGoal);
|
|
17934
|
+
}
|
|
17935
|
+
}
|
|
17468
17936
|
// Declarative ACE sentences ("every module is a artifact") ASSERT into tmct's
|
|
17469
17937
|
// own memory and confirm — they are statements to remember, not graph queries.
|
|
17470
17938
|
// Gated on memoryDir: only a session shell provides a write target, so a bare
|