@polycode-projects/the-mechanical-code-talker 5.0.39 → 5.0.41
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/package.json +1 -1
- package/src/domain/ask.mjs +345 -16
- package/src/domain/codegraph.mjs +25 -2
- package/src/domain/interpret/normalize.mjs +52 -16
- package/src/services/chat.mjs +14 -13
- package/src/surfaces/web/memory-ask-browser.bundle.js +118 -118
|
@@ -549,25 +549,57 @@ const CONDITIONAL_KIND_PLURAL = Object.freeze({
|
|
|
549
549
|
});
|
|
550
550
|
const CONDITIONAL_QUALIFIER_SRC =
|
|
551
551
|
"public|private|protected|static|abstract|constant|re-?exported|exported|tested|covered|untested|uncovered";
|
|
552
|
-
/**
|
|
553
|
-
*
|
|
554
|
-
*
|
|
555
|
-
*
|
|
556
|
-
|
|
557
|
-
|
|
552
|
+
/** consequent noun -> the qualifier it states. "has it got tests" and "does it
|
|
553
|
+
* have tests" ask what "is it tested" asks, and the graph answers all three
|
|
554
|
+
* off the same tests edge. Closed on purpose: a noun with no entry leaves the
|
|
555
|
+
* whole conditional unmatched rather than being read as some near qualifier. */
|
|
556
|
+
const CONDITIONAL_HAVE_NOUN_QUALIFIER = Object.freeze({
|
|
557
|
+
tests: "tested", "a test": "tested", "any tests": "tested",
|
|
558
|
+
coverage: "covered", "test coverage": "covered",
|
|
559
|
+
});
|
|
560
|
+
/** "if a/the <kind> <relation-verb> <object>, <consequent>?" ->
|
|
561
|
+
* "<kind plural> <relation-gerund> <object> and <qualifier>". The consequent
|
|
562
|
+
* is one of three closed phrasings: "is/are it <qualifier>", "has/have it got
|
|
563
|
+
* <noun>", "does/do it have <noun>". Closed to the tables above (every end
|
|
564
|
+
* validated), so an unrecognized kind/verb/qualifier/noun simply doesn't
|
|
565
|
+
* match — it falls through to the ordinary grammar, which honestly misses on
|
|
566
|
+
* the untransformed "if …" text rather than risk a wrong composition. */
|
|
558
567
|
const CONDITIONAL_QUALIFIER_RE = new RegExp(
|
|
559
568
|
"^if\\s+(?:a|an|the)?\\s*(" + Object.keys(CONDITIONAL_KIND_PLURAL).join("|") + ")\\s+"
|
|
560
569
|
+ "(" + Object.keys(CONDITIONAL_VERB_GERUND).join("|") + ")\\s+"
|
|
561
|
-
+ "(.+?),\\s*(?:
|
|
562
|
-
+ "(" + CONDITIONAL_QUALIFIER_SRC + ")
|
|
570
|
+
+ "(.+?),\\s*(?:"
|
|
571
|
+
+ "(?:is|are)\\s+(?:it|that|they|this)\\s+(" + CONDITIONAL_QUALIFIER_SRC + ")"
|
|
572
|
+
+ "|(?:has|have)\\s+(?:it|that|they|this)\\s+got\\s+(" + Object.keys(CONDITIONAL_HAVE_NOUN_QUALIFIER).join("|") + ")"
|
|
573
|
+
+ "|(?:does|do)\\s+(?:it|that|they|this)\\s+have\\s+(" + Object.keys(CONDITIONAL_HAVE_NOUN_QUALIFIER).join("|") + ")"
|
|
574
|
+
+ ")\\??$",
|
|
563
575
|
"i",
|
|
564
576
|
);
|
|
565
577
|
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
export const COUNTERFACTUAL_RE =
|
|
570
|
-
|
|
578
|
+
const COUNTERFACTUAL_GONE_SRC = "(?:were|was)\\s+(?:deleted|removed)";
|
|
579
|
+
const COUNTERFACTUAL_BREAK_SRC = "what\\s+(?:would|might|could)\\s+(?:break|fail|be\\s+affected)";
|
|
580
|
+
/** Counterfactual deletion, if-clause first. */
|
|
581
|
+
export const COUNTERFACTUAL_RE = new RegExp(
|
|
582
|
+
"^if\\s+(.+?)\\s+" + COUNTERFACTUAL_GONE_SRC + ",?\\s*" + COUNTERFACTUAL_BREAK_SRC + "\\??$",
|
|
583
|
+
"i",
|
|
584
|
+
);
|
|
585
|
+
/** The same counterfactual with its if-clause last — "what would break if X
|
|
586
|
+
* were removed". English puts a conditional either way round and the reading
|
|
587
|
+
* is identical, so both orders resolve to the same subject. */
|
|
588
|
+
export const COUNTERFACTUAL_POSTPOSED_RE = new RegExp(
|
|
589
|
+
"^" + COUNTERFACTUAL_BREAK_SRC + "\\s+if\\s+(.+?)\\s+" + COUNTERFACTUAL_GONE_SRC + "\\??$",
|
|
590
|
+
"i",
|
|
591
|
+
);
|
|
592
|
+
|
|
593
|
+
/** The entity a counterfactual-deletion question asks about, either word
|
|
594
|
+
* order, or null when the question isn't one. Callers that need to mark the
|
|
595
|
+
* answer hypothetical (chat.mjs) and callers that need to pick the closure
|
|
596
|
+
* the subject actually has (ask.mjs) read the subject through here rather
|
|
597
|
+
* than each matching one of the two orders. */
|
|
598
|
+
export function counterfactualSubjectOf(text) {
|
|
599
|
+
const q = String(text || "").trim();
|
|
600
|
+
const m = q.match(COUNTERFACTUAL_RE) || q.match(COUNTERFACTUAL_POSTPOSED_RE);
|
|
601
|
+
return m ? m[1].trim() : null;
|
|
602
|
+
}
|
|
571
603
|
|
|
572
604
|
/** Apply the two conditional frames, qualifier composition first (more specific). */
|
|
573
605
|
export function applyConditionalFrames(text) {
|
|
@@ -576,10 +608,14 @@ export function applyConditionalFrames(text) {
|
|
|
576
608
|
if (qual) {
|
|
577
609
|
const kind = CONDITIONAL_KIND_PLURAL[qual[1].toLowerCase()];
|
|
578
610
|
const gerund = CONDITIONAL_VERB_GERUND[qual[2].toLowerCase()];
|
|
579
|
-
|
|
611
|
+
const haveNoun = qual[5] || qual[6];
|
|
612
|
+
const qualifier = qual[4]
|
|
613
|
+
? qual[4].toLowerCase()
|
|
614
|
+
: CONDITIONAL_HAVE_NOUN_QUALIFIER[haveNoun.toLowerCase()];
|
|
615
|
+
return `${kind} ${gerund} ${qual[3].trim()} and ${qualifier}`;
|
|
580
616
|
}
|
|
581
|
-
const
|
|
582
|
-
if (
|
|
617
|
+
const subject = counterfactualSubjectOf(q);
|
|
618
|
+
if (subject) return `which modules transitively import ${subject}`;
|
|
583
619
|
return q;
|
|
584
620
|
}
|
|
585
621
|
|
package/src/services/chat.mjs
CHANGED
|
@@ -47,7 +47,7 @@ import {
|
|
|
47
47
|
stripTrailingScopeFiller, stripTrailingDiscourseTag, EDGE_NOUN_TO_METRIC, RELATIONS, LIST_TRIGGERS,
|
|
48
48
|
locativePreposition,
|
|
49
49
|
} from "../domain/ask-vocab.mjs";
|
|
50
|
-
import {
|
|
50
|
+
import { counterfactualSubjectOf, correctMisspellings, applyPreambleFrames, expandContractions, normalizeQuery, stripFillerWords, escapeRegex, kindNounAnaphoraHint, datedTeachSuffix, QUESTION_LEAD_RE, fillerClausePrefix, leadsInterrogative } from "../domain/interpret/normalize.mjs";
|
|
51
51
|
import { setDefaultNlpAdapter } from "../domain/interpret/nlp-registry.mjs";
|
|
52
52
|
import { setConstructionBanks } from "../domain/interpret/strategies/constructions.mjs";
|
|
53
53
|
import { nlpAdapter } from "../adapters/ask-nlp.mjs";
|
|
@@ -16655,19 +16655,20 @@ async function runAsk(query, { config, source, graph, focus, last, templates, me
|
|
|
16655
16655
|
note(trace, "source: local committed corpus slice (licence-cited in the aside itself)");
|
|
16656
16656
|
}
|
|
16657
16657
|
}
|
|
16658
|
-
// Counterfactual marker: "if X were deleted, what would break"
|
|
16659
|
-
//
|
|
16660
|
-
//
|
|
16661
|
-
// traversal answer would over-claim it as
|
|
16662
|
-
// only rewrites the QUESTION;
|
|
16663
|
-
//
|
|
16664
|
-
//
|
|
16665
|
-
//
|
|
16666
|
-
//
|
|
16667
|
-
|
|
16658
|
+
// Counterfactual marker: "if X were deleted, what would break" (either word
|
|
16659
|
+
// order) compiles to a REAL traversal — the reverse dependency closure for a
|
|
16660
|
+
// module, the subclass closure for a class — but the consequent is
|
|
16661
|
+
// hypothetical, so a plain traversal answer would over-claim it as
|
|
16662
|
+
// present-tense fact. interpret/normalize.mjs only rewrites the QUESTION;
|
|
16663
|
+
// this names the SAME raw query shape here (the one seam that sees both the
|
|
16664
|
+
// original text and the final answer) and marks the answer as conditional.
|
|
16665
|
+
// Gated to a genuine non-miss composed traversal — a counterfactual that
|
|
16666
|
+
// happens to miss keeps its ordinary honest-miss wording, never a fabricated
|
|
16667
|
+
// "hypothetically" wrapper around a blank.
|
|
16668
|
+
const counterfactualSubject = counterfactualSubjectOf(query);
|
|
16668
16669
|
if (!recordMiss && via === "composed" && counterfactualSubject) {
|
|
16669
|
-
answer = `hypothetically, if ${counterfactualSubject
|
|
16670
|
-
note(trace, `intermediate:
|
|
16670
|
+
answer = `hypothetically, if ${counterfactualSubject} were removed: ${answer}`;
|
|
16671
|
+
note(trace, `intermediate: counterfactual conditional matched — compiled to a real traversal, wrapped as hypothetical ("${counterfactualSubject}" removed)`);
|
|
16671
16672
|
}
|
|
16672
16673
|
// LIVE SUPPLEMENT (/wiki supplement, and its superset /wiki always): a
|
|
16673
16674
|
// grounded answer also carries what Wikipedia says about its subject —
|