@polycode-projects/the-mechanical-code-talker 5.0.45 → 5.0.46
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/bin/tmct.mjs +11 -10
- package/package.json +2 -1
- package/src/adapters/corpus/research-source.mjs +4 -2
- package/src/adapters/corpus/simple-wikipedia-pack.mjs +138 -0
- package/src/domain/cli-verbs.mjs +2 -2
- package/src/domain/fact-phrase.mjs +130 -13
- package/src/domain/memory/capability.mjs +1 -1
- package/src/domain/phrase-exports.mjs +29 -0
- package/src/domain/reference-pack.mjs +46 -0
- package/src/services/chat.mjs +49 -98
- package/src/services/index.mjs +2 -0
- package/src/services/init.mjs +2 -1
- package/src/services/news-viz.mjs +2 -3
- package/src/surfaces/web/memory-ask-browser.bundle.js +105 -104
package/bin/tmct.mjs
CHANGED
|
@@ -709,11 +709,11 @@ async function main() {
|
|
|
709
709
|
let researchSource;
|
|
710
710
|
try {
|
|
711
711
|
memoryBackend = enumFlag(rest, ["--memory-backend"], ["default", "memory", "sqlite"]);
|
|
712
|
-
// `--research-source <wikipedia|wikidata>`: the
|
|
713
|
-
// research lane's source precedence (below
|
|
714
|
-
// above tmct.toml's [research] source).
|
|
715
|
-
// lower tiers still apply unchanged.
|
|
716
|
-
researchSource = enumFlag(rest, ["--research-source"], ["wikipedia", "wikidata"]);
|
|
712
|
+
// `--research-source <wikipedia|wikidata|simple-wikipedia-pack>`: the
|
|
713
|
+
// CLI's flag tier of the research lane's source precedence (below
|
|
714
|
+
// /wikipedia|/wikidata in chat, above tmct.toml's [research] source).
|
|
715
|
+
// Omitted when absent so the lower tiers still apply unchanged.
|
|
716
|
+
researchSource = enumFlag(rest, ["--research-source"], ["wikipedia", "wikidata", "simple-wikipedia-pack"]);
|
|
717
717
|
} catch (e) {
|
|
718
718
|
process.stderr.write(`tmct: ${e?.message || e}\n`);
|
|
719
719
|
process.exit(2);
|
|
@@ -888,13 +888,14 @@ async function main() {
|
|
|
888
888
|
process.exit(2);
|
|
889
889
|
}
|
|
890
890
|
|
|
891
|
-
// `--research-source <wikipedia|wikidata>`: written
|
|
892
|
-
// `[research] source` (src/services/init.mjs's
|
|
893
|
-
// flag name `tmct chat` reads at its own
|
|
894
|
-
// once here needs no flag on a later
|
|
891
|
+
// `--research-source <wikipedia|wikidata|simple-wikipedia-pack>`: written
|
|
892
|
+
// into tmct.toml's `[research] source` (src/services/init.mjs's
|
|
893
|
+
// renderTomlConfig), the same flag name `tmct chat` reads at its own
|
|
894
|
+
// precedence tier — a repo set up once here needs no flag on a later
|
|
895
|
+
// `tmct chat` in it.
|
|
895
896
|
let researchSourceVal;
|
|
896
897
|
try {
|
|
897
|
-
researchSourceVal = enumFlag(rest, ["--research-source"], ["wikipedia", "wikidata"]);
|
|
898
|
+
researchSourceVal = enumFlag(rest, ["--research-source"], ["wikipedia", "wikidata", "simple-wikipedia-pack"]);
|
|
898
899
|
} catch (e) {
|
|
899
900
|
process.stderr.write(`tmct init: ${e?.message || e}\n`);
|
|
900
901
|
process.exit(2);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polycode-projects/the-mechanical-code-talker",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.46",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "The Mechanical Code Talker (tmct) — a tolerant, offline, $0 chat surface that guides you toward precision queries about a software repository. ELIZA/PARRY-style but domain-obsessed with code. No model calls; indexes a repo on request (tmct index) or reads any producer's graph.",
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"./conformance": "./src/tools/conformance.mjs",
|
|
53
53
|
"./ask-browser": "./src/surfaces/web/graph-ask-browser-entry.mjs",
|
|
54
54
|
"./news": "./src/services/news-exports.mjs",
|
|
55
|
+
"./phrase": "./src/domain/phrase-exports.mjs",
|
|
55
56
|
"./envelope": "./test-benchmarks/agentbench/envelope-reader.mjs"
|
|
56
57
|
},
|
|
57
58
|
"files": [
|
|
@@ -124,9 +124,10 @@ export function researchSources() {
|
|
|
124
124
|
* same registered source, "wikipedia" for backward compatibility with the
|
|
125
125
|
* original single-source config, "simple-wikipedia" so the news `kb_sources`
|
|
126
126
|
* list (news-sources.mjs) can name every source by the same id its own
|
|
127
|
-
* registry uses.
|
|
127
|
+
* registry uses. "simple-wikipedia-pack" names its offline sibling — the
|
|
128
|
+
* shipped reference pack read as a research source, no network at all. */
|
|
128
129
|
export const RESEARCH_SOURCE_CHOICES = Object.freeze([
|
|
129
|
-
"wikipedia", "wikidata", "simple-wikipedia", "wiktionary", "dbpedia",
|
|
130
|
+
"wikipedia", "wikidata", "simple-wikipedia", "simple-wikipedia-pack", "wiktionary", "dbpedia",
|
|
130
131
|
]);
|
|
131
132
|
export const DEFAULT_RESEARCH_SOURCE_CHOICE = "wikipedia";
|
|
132
133
|
|
|
@@ -134,6 +135,7 @@ const CHOICE_TO_SOURCE_NAME = Object.freeze({
|
|
|
134
135
|
wikipedia: "simple-wikipedia",
|
|
135
136
|
wikidata: "wikidata",
|
|
136
137
|
"simple-wikipedia": "simple-wikipedia",
|
|
138
|
+
"simple-wikipedia-pack": "simple-wikipedia-pack",
|
|
137
139
|
wiktionary: "wiktionary",
|
|
138
140
|
dbpedia: "dbpedia-lookup",
|
|
139
141
|
});
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// corpus/simple-wikipedia-pack.mjs — the offline research source: the SAME
|
|
2
|
+
// shipped reference pack the reference lane serves
|
|
3
|
+
// (src/domain/reference-pack.mjs's shape, src/adapters/corpus/
|
|
4
|
+
// reference-pack.mjs's lazy fs loader), read as a research-source.mjs
|
|
5
|
+
// adapter so "research <topic>" can ground a turn with no network at all.
|
|
6
|
+
//
|
|
7
|
+
// Registered under its own name, "simple-wikipedia-pack" — deliberately
|
|
8
|
+
// distinct from the live "simple-wikipedia" source, so a fact stamped
|
|
9
|
+
// through researchFacts() (the news lane, the contract tests) still tells
|
|
10
|
+
// the pack apart from a live fetch at the provenance-tag layer. The
|
|
11
|
+
// interactive "research <topic>" chat lane stamps its own source-agnostic
|
|
12
|
+
// research:<topic>@<depth> tag regardless of which source grounded the
|
|
13
|
+
// turn (src/services/research.mjs); that tag is unaffected by this module
|
|
14
|
+
// and stays exactly as it already is for every other research source.
|
|
15
|
+
//
|
|
16
|
+
// "Linked" topics: the pack carries no link graph, so linkedTitles reads the
|
|
17
|
+
// pack's OWN cross-references instead — other terms the pack's index
|
|
18
|
+
// already knows, found as whole words inside this article's text, in the
|
|
19
|
+
// order they first occur. It is the offline analogue of a live source's
|
|
20
|
+
// lead-section links, built entirely from data already on disk.
|
|
21
|
+
//
|
|
22
|
+
// No network, ever — every read goes through the pack's own lazy, cached fs
|
|
23
|
+
// loader. Node-only, unlike the browser-shipped live adapters: the pack's fs
|
|
24
|
+
// layout is not available in the browser bundle, so this module is not
|
|
25
|
+
// imported there.
|
|
26
|
+
|
|
27
|
+
import { normFactTerm } from "../../domain/hash.mjs";
|
|
28
|
+
import { loadLexicon, lookupNoun } from "../../domain/grammar/lexicon.mjs";
|
|
29
|
+
import { isContentToken } from "../../domain/prose.mjs";
|
|
30
|
+
import { isReferenceArticleRow } from "../../domain/reference-pack.mjs";
|
|
31
|
+
import { loadReferenceIndex, loadReferenceArticle, referencePackDir } from "./reference-pack.mjs";
|
|
32
|
+
import { registerResearchSource, researchSourceTag } from "./research-source.mjs";
|
|
33
|
+
|
|
34
|
+
export const SIMPLE_WIKIPEDIA_PACK_ORIGIN = "https://simple.wikipedia.org";
|
|
35
|
+
export const SIMPLE_WIKIPEDIA_PACK_SOURCE_NAME = "simple-wikipedia-pack";
|
|
36
|
+
|
|
37
|
+
const WORD_RE = /[A-Za-z][A-Za-z'-]*/g;
|
|
38
|
+
const MAX_LINKED_TITLES = 25;
|
|
39
|
+
|
|
40
|
+
/** A text word folded to the pack index's own key: the lexicon's lemma when
|
|
41
|
+
* the word is a known noun ("birds" -> "bird"), else its own normFactTerm
|
|
42
|
+
* fold — the same fallback reference-pack.mjs's isaOf extraction uses. */
|
|
43
|
+
function packIndexKey(word, lexicon) {
|
|
44
|
+
const entry = lookupNoun(lexicon, word);
|
|
45
|
+
return entry ? normFactTerm(entry.lemma) : normFactTerm(word);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const capitalize = (key) => key.charAt(0).toUpperCase() + key.slice(1);
|
|
49
|
+
|
|
50
|
+
/** Other pack terms this article's text mentions, in the order they first
|
|
51
|
+
* occur, excluding the article's own term. The pack's index keys an alias
|
|
52
|
+
* ("prey") on whatever article it redirects to ("predator"), and carries no
|
|
53
|
+
* reverse title index — so the WORD found in the text, not that article's
|
|
54
|
+
* own (possibly unrelated-looking) title, is what round-trips back through
|
|
55
|
+
* lookup()/pageByTitle() correctly; capitalized for display only, since
|
|
56
|
+
* normFactTerm folds case away on the way back in. Every candidate is
|
|
57
|
+
* confirmed against a real row before it queues, so a stale index entry
|
|
58
|
+
* never queues a fetch that would fail. */
|
|
59
|
+
function packLinkedTitles(dir, text, ownKey, index, lexicon, limit) {
|
|
60
|
+
if (!index || limit <= 0) return [];
|
|
61
|
+
const seen = new Set([ownKey]);
|
|
62
|
+
const out = [];
|
|
63
|
+
for (const match of String(text ?? "").matchAll(WORD_RE)) {
|
|
64
|
+
if (out.length >= limit) break;
|
|
65
|
+
const key = packIndexKey(match[0], lexicon);
|
|
66
|
+
if (!key || !isContentToken(key) || seen.has(key) || !index[key]) continue;
|
|
67
|
+
seen.add(key);
|
|
68
|
+
if (!loadReferenceArticle(dir, key)) continue;
|
|
69
|
+
out.push(capitalize(key));
|
|
70
|
+
}
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The offline pack-backed research source: { name, origin, lookup(term),
|
|
76
|
+
* pageByTitle(title), linkedTitles(title, {limit}), provenanceTag(term) } —
|
|
77
|
+
* the research-source.mjs contract, satisfied entirely from the shipped
|
|
78
|
+
* reference pack on disk.
|
|
79
|
+
*
|
|
80
|
+
* `dir` defaults to the pack's own resolution order (TMCT_REFERENCE_PACK_DIR
|
|
81
|
+
* env, else the package's shipped corpus/reference/ — referencePackDir()).
|
|
82
|
+
* `lexicon` defaults to the shared lexicon, lazily loaded and cached the same
|
|
83
|
+
* way every other reference/research reader does.
|
|
84
|
+
*/
|
|
85
|
+
export function createSimpleWikipediaPackSource({
|
|
86
|
+
dir,
|
|
87
|
+
lexicon = null,
|
|
88
|
+
sourceName = SIMPLE_WIKIPEDIA_PACK_SOURCE_NAME,
|
|
89
|
+
} = {}) {
|
|
90
|
+
const packDir = dir || referencePackDir();
|
|
91
|
+
let lex = lexicon;
|
|
92
|
+
function activeLexicon() {
|
|
93
|
+
if (lex) return lex;
|
|
94
|
+
try { lex = loadLexicon(); } catch { lex = null; }
|
|
95
|
+
return lex;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function rowFor(term) {
|
|
99
|
+
const key = normFactTerm(term ?? "");
|
|
100
|
+
if (!key) return null;
|
|
101
|
+
const article = loadReferenceArticle(packDir, key);
|
|
102
|
+
if (!article) return null;
|
|
103
|
+
const row = { ...article, term: key };
|
|
104
|
+
return isReferenceArticleRow(row) ? row : null;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
name: sourceName,
|
|
109
|
+
origin: SIMPLE_WIKIPEDIA_PACK_ORIGIN,
|
|
110
|
+
|
|
111
|
+
provenanceTag(term) {
|
|
112
|
+
return researchSourceTag(sourceName, term);
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
async lookup(term) {
|
|
116
|
+
return rowFor(term);
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
/** The pack row for an exact title — the pack's own term index already
|
|
120
|
+
* resolves a title's canonical key in one lookup, so this is the same
|
|
121
|
+
* read `lookup` performs, no round trip either way. */
|
|
122
|
+
async pageByTitle(title) {
|
|
123
|
+
return rowFor(title);
|
|
124
|
+
},
|
|
125
|
+
|
|
126
|
+
async linkedTitles(title, { limit = MAX_LINKED_TITLES } = {}) {
|
|
127
|
+
const article = rowFor(title);
|
|
128
|
+
if (!article) return null;
|
|
129
|
+
const index = loadReferenceIndex(packDir);
|
|
130
|
+
return packLinkedTitles(packDir, article.text, article.term, index, activeLexicon(), Math.max(0, limit));
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
registerResearchSource({
|
|
136
|
+
name: SIMPLE_WIKIPEDIA_PACK_SOURCE_NAME,
|
|
137
|
+
create: createSimpleWikipediaPackSource,
|
|
138
|
+
});
|
package/src/domain/cli-verbs.mjs
CHANGED
|
@@ -37,7 +37,7 @@ export const CLI_VERBS = [
|
|
|
37
37
|
{ flag: "[--live-wikipedia]", prose: ["start with the live Wikipedia supplement on — a question", "nothing local can answer also tries en.wikipedia.org,", "cited (network; also TMCT_LIVE_WIKIPEDIA=1 or tmct.toml", "corpus tier3; toggle mid-session with /wiki on|off)"] },
|
|
38
38
|
{ flag: "[--plain]", prose: ["force the plain readline shell (the default when", "stdin/stdout is not a terminal)"] },
|
|
39
39
|
{ flag: "[--memory-backend <default|memory|sqlite>]", prose: ["storage backend for taught facts this", "session (CLI flag > TMCT_MEMORY_BACKEND env > tmct.toml's", "[memory] backend > sqlite, .tmct/memory/graph.sqlite)"] },
|
|
40
|
-
{ flag: "[--research-source <wikipedia|wikidata>]", prose: ["where \"research <topic>\" fetches from this session", "(/wikipedia|/wikidata in chat > this flag > tmct.toml's", "[research] source > wikipedia)"] },
|
|
40
|
+
{ flag: "[--research-source <wikipedia|wikidata|simple-wikipedia-pack>]", prose: ["where \"research <topic>\" fetches from this session", "(/wikipedia|/wikidata in chat > this flag > tmct.toml's", "[research] source > wikipedia)"] },
|
|
41
41
|
],
|
|
42
42
|
},
|
|
43
43
|
{
|
|
@@ -67,7 +67,7 @@ export const CLI_VERBS = [
|
|
|
67
67
|
{ flag: "[--with-persona <name>]", prose: ["write an explicit [extensions]/[bias] preset into tmct.toml", "(\"code\" — today's implicit default, made explicit)"] },
|
|
68
68
|
{ flag: "[--persona-size <medium|large>]", prose: ["grow the default \"human\" persona's fact count", "beyond Small (the default): \"medium\" activates", "human-medium.jsonl (~1,608 facts total), \"large\" also", "activates human-large.jsonl (~13,600 facts total,", "with genuine multi-hop hypernym chains) — additive", "size tiers of the SAME bundle, not separate personas"] },
|
|
69
69
|
{ flag: "[--memory-backend <default|memory|sqlite>]", prose: ["write tmct.toml's [memory] backend", "(same flag name as `tmct chat`) — a later `tmct chat`", "in this repo picks it up with no flag needed"] },
|
|
70
|
-
{ flag: "[--research-source <wikipedia|wikidata>]", prose: ["write tmct.toml's [research] source", "(same flag name as `tmct chat`) — a later `tmct chat`", "in this repo picks it up with no flag needed"] },
|
|
70
|
+
{ flag: "[--research-source <wikipedia|wikidata|simple-wikipedia-pack>]", prose: ["write tmct.toml's [research] source", "(same flag name as `tmct chat`) — a later `tmct chat`", "in this repo picks it up with no flag needed"] },
|
|
71
71
|
],
|
|
72
72
|
},
|
|
73
73
|
{
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
// fact-phrase.mjs — the one predicate -> English-phrase table
|
|
2
|
-
// news paraphrase renderer
|
|
3
|
-
//
|
|
4
|
-
//
|
|
1
|
+
// fact-phrase.mjs — the one predicate -> English-phrase table AND the one
|
|
2
|
+
// reader over it. The news paraphrase renderer, the news page's own inline
|
|
3
|
+
// script and chat.mjs's answer path all render a stored fact through the
|
|
4
|
+
// functions below, so no two surfaces can disagree about what a predicate
|
|
5
|
+
// says in English.
|
|
5
6
|
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
7
|
+
// The reader is layered: a curated table hit first, then the mechanical
|
|
8
|
+
// surface forms for the predicates tmct MINTS at teach time (polarity flips,
|
|
9
|
+
// comparatives, participle + preposition, "same <attribute> as", and the
|
|
10
|
+
// "mgx:<lemma>[-<prep>]" verb fold), and last the predicate's bare local
|
|
11
|
+
// name. Every layer is mechanical — a phrase is derived from the predicate or
|
|
12
|
+
// it is the predicate's own local name. Nothing here guesses.
|
|
10
13
|
|
|
11
14
|
export const FACT_PREDICATE_PHRASES = Object.freeze({
|
|
12
15
|
"rdfs:subClassOf": "is a kind of",
|
|
@@ -58,16 +61,130 @@ export const FACT_PREDICATE_PHRASES = Object.freeze({
|
|
|
58
61
|
"mgx:guards": "guards",
|
|
59
62
|
});
|
|
60
63
|
|
|
61
|
-
/**
|
|
62
|
-
*
|
|
64
|
+
/** The closed participle set the relational teach frames read as "X is
|
|
65
|
+
* <participle> <prep> Y" — a past participle whose own form is the word, so it
|
|
66
|
+
* reads back with no morphology. Closed by list (templates over general
|
|
67
|
+
* grammar), so the frame can never widen onto an arbitrary "-ed" adjective.
|
|
68
|
+
* The teach parser mints predicates from this list and the reader below turns
|
|
69
|
+
* them back into English, so both read the one vocabulary. */
|
|
70
|
+
export const TEACH_PARTICIPLE_SRC = "connected|related|associated|linked|based|derived|composed|made|used|known|located|found|involved|concerned";
|
|
71
|
+
|
|
72
|
+
/** The MECHANICAL fallback for a predicate the table has no curated entry
|
|
73
|
+
* for — specifically the minted "mgx:<lemma>" predicates ("mgx:eat",
|
|
74
|
+
* "mgx:drive", …) — the mechanical INVERSE of the naive -s/-es/-ies fold the
|
|
75
|
+
* teach lane's own singularizer uses, same accepted-limitation trade (no real
|
|
76
|
+
* morphology; a handful of doubly-irregular verbs render slightly off but
|
|
77
|
+
* never wrong-MEANING). "has"/"have" never reach this fallback — the teach
|
|
78
|
+
* lane special-cases them onto the CURATED mgx:hasA entry above before a
|
|
79
|
+
* predicate is ever minted. */
|
|
80
|
+
export function thirdPersonSingularSurface(lemma) {
|
|
81
|
+
const w = String(lemma || "");
|
|
82
|
+
// "have" should never reach this naive fallback at all (the teach lane
|
|
83
|
+
// special-cases it onto mgx:hasA before a predicate is ever minted), but if
|
|
84
|
+
// some OTHER path ever reaches here with it as typed — e.g. wink-nlp
|
|
85
|
+
// unavailable so the lemma degrades to the raw verb — the naive "+s" rule
|
|
86
|
+
// would produce the wrong-MEANING "haves" instead of the correct "has".
|
|
87
|
+
if (/^have$/i.test(w)) return "has";
|
|
88
|
+
if (/[a-z]y$/i.test(w) && !/[aeiou]y$/i.test(w)) return `${w.slice(0, -1)}ies`;
|
|
89
|
+
if (/(?:s|x|z|ch|sh|o)$/i.test(w)) return `${w}es`;
|
|
90
|
+
return `${w}s`;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** The INVERSE of thirdPersonSingularSurface — "eats" -> "eat", "flies" ->
|
|
94
|
+
* "fly", "has" -> "have". Do-support wants the bare infinitive after it
|
|
95
|
+
* ("does not EAT", never "does not eats"), and so does every derived
|
|
96
|
+
* forward yes/no reader ("does X cause Y"), so both fold through this one
|
|
97
|
+
* function and can never drift apart on a verb. */
|
|
98
|
+
export function baseVerbSurface(verb) {
|
|
99
|
+
const w = String(verb || "");
|
|
100
|
+
if (/^has$/i.test(w)) return "have";
|
|
101
|
+
if (/[a-z]ies$/i.test(w) && !/[aeiou]ies$/i.test(w)) return `${w.slice(0, -3)}y`;
|
|
102
|
+
if (/(?:ss|zz|x|ch|sh|o)es$/i.test(w)) return w.slice(0, -2);
|
|
103
|
+
// A SINGLE s or z before "es" means the base already ended in "e" and took a
|
|
104
|
+
// plain "s": cause/use/raise/size, not caus/us/rais/siz. Only the doubled
|
|
105
|
+
// sibilants above ("passes", "buzzes") really carry an "-es" ending.
|
|
106
|
+
if (/[sz]es$/i.test(w)) return w.slice(0, -1);
|
|
107
|
+
return w.replace(/s$/i, "");
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** The gerund surface of a 3sg-minted role predicate — "contains" ->
|
|
111
|
+
* "containing", "touches" -> "touching" — the naive INVERSE of the
|
|
112
|
+
* "-ing"-stripping fold the ACE parser already accepts alongside a 3sg
|
|
113
|
+
* surface. Same accepted naive-morphology trade as its two siblings above. */
|
|
114
|
+
export function gerundVerbSurface(verb) {
|
|
115
|
+
const base = baseVerbSurface(verb);
|
|
116
|
+
return /[^aeiou]e$/i.test(base) && base.length > 2 ? `${base.slice(0, -1)}ing` : `${base}ing`;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* How a stored predicate reads in English: a curated table hit, else the
|
|
121
|
+
* mechanical surface form of a minted predicate, else the predicate's local
|
|
122
|
+
* name (the segment after its first colon, or the whole string when there is
|
|
123
|
+
* none). The local-name tail is what keeps a namespace tmct itself mints —
|
|
124
|
+
* `tmct:needs`, stamped by the lexicon — out of a public-facing sentence.
|
|
125
|
+
*
|
|
126
|
+
* Self-contained on purpose: the news page runs this exact function in the
|
|
127
|
+
* browser (phraseRendererSource below stringifies it and its two helpers), so
|
|
128
|
+
* it reaches for nothing outside this module.
|
|
129
|
+
*/
|
|
63
130
|
export function predicatePhrase(predicate) {
|
|
64
131
|
if (FACT_PREDICATE_PHRASES[predicate]) return FACT_PREDICATE_PHRASES[predicate];
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
132
|
+
const p = String(predicate ?? "");
|
|
133
|
+
// NEGATIVE polarity renders as its own positive phrase, negated — ONE branch
|
|
134
|
+
// for every predicate that can carry a polarity, curated or minted. The
|
|
135
|
+
// negative twins are deliberately absent from FACT_PREDICATE_PHRASES: chat's
|
|
136
|
+
// query-marker families all derive their vocabulary from that table, so an
|
|
137
|
+
// entry there would auto-mint readers for "what cannot X" and "does X cannot
|
|
138
|
+
// Y" that nobody wrote and nothing pins. The prefix swap is the whole rule
|
|
139
|
+
// here because the one polarity pair that ISN'T a prefix swap
|
|
140
|
+
// (mgxneg:subClassOf / rdfs:subClassOf) carries its own curated entry above
|
|
141
|
+
// and returns before this branch.
|
|
142
|
+
// The three surface shapes split as the forward yes/no readers split them,
|
|
143
|
+
// for the same reason: a modal, a copula and a plain verb take different
|
|
144
|
+
// negations, and nothing else does.
|
|
145
|
+
if (p.startsWith("mgxneg:")) {
|
|
146
|
+
const phrase = predicatePhrase(`mgx:${p.slice("mgxneg:".length)}`);
|
|
147
|
+
if (phrase === "can") return "cannot";
|
|
148
|
+
if (phrase === "can be") return "cannot be";
|
|
149
|
+
if (phrase === "is" || phrase.startsWith("is ")) return `is not${phrase.slice(2)}`;
|
|
150
|
+
const [head, ...tail] = phrase.split(" ");
|
|
151
|
+
return ["does not", baseVerbSurface(head), ...tail].join(" ");
|
|
152
|
+
}
|
|
153
|
+
// a comparative renders as its copula surface: mgx:smaller-than ->
|
|
154
|
+
// "is smaller than" (never a 3sg fold — "smallers" isn't a word)
|
|
155
|
+
const comp = /^mgx:([a-z]+(?:-[a-z]+)*)-than$/i.exec(p);
|
|
156
|
+
if (comp) return `is ${comp[1].replace(/-/g, " ")} than`;
|
|
157
|
+
// a participle + preposition renders as its copula surface: mgx:connected-with
|
|
158
|
+
// -> "is connected with" (the participle is already a participle, so no 3sg
|
|
159
|
+
// fold — "connecteds" isn't a word)
|
|
160
|
+
const part = new RegExp(`^mgx:(${TEACH_PARTICIPLE_SRC})-([a-z]+)$`, "i").exec(p);
|
|
161
|
+
if (part) return `is ${part[1].toLowerCase()} ${part[2].toLowerCase()}`;
|
|
162
|
+
// a shared-attribute predicate: mgx:same-goal-as -> "has the same goal as"
|
|
163
|
+
const same = /^mgx:same-([a-z]+)-as$/i.exec(p);
|
|
164
|
+
if (same) return `has the same ${same[1].toLowerCase()} as`;
|
|
165
|
+
// a folded preposition renders back naturally: mgx:rest-on -> "rests on"
|
|
166
|
+
const minted = /^mgx:([a-z]+)(?:-([a-z]+))?$/i.exec(p);
|
|
167
|
+
if (minted) return `${thirdPersonSingularSurface(minted[1])}${minted[2] ? ` ${minted[2]}` : ""}`;
|
|
168
|
+
const colon = p.indexOf(":");
|
|
169
|
+
return colon === -1 ? p : p.slice(colon + 1);
|
|
68
170
|
}
|
|
69
171
|
|
|
70
172
|
/** "a heart has a valve" from one { subject, predicate, object } fact row. */
|
|
71
173
|
export function factSentence(row) {
|
|
72
174
|
return `${row.subject} ${predicatePhrase(row.predicate)} ${row.object}`;
|
|
73
175
|
}
|
|
176
|
+
|
|
177
|
+
/** The phrase layer as browser source, for a generated page that renders fact
|
|
178
|
+
* rows in its own inline script. The page supplies FACT_PREDICATE_PHRASES
|
|
179
|
+
* (it embeds the table as JSON) and this supplies everything the reader
|
|
180
|
+
* above stands on, so a new branch here reaches the page without the page
|
|
181
|
+
* being edited. */
|
|
182
|
+
export function phraseRendererSource() {
|
|
183
|
+
return [
|
|
184
|
+
`const TEACH_PARTICIPLE_SRC = ${JSON.stringify(TEACH_PARTICIPLE_SRC)};`,
|
|
185
|
+
`const thirdPersonSingularSurface = ${thirdPersonSingularSurface};`,
|
|
186
|
+
`const baseVerbSurface = ${baseVerbSurface};`,
|
|
187
|
+
`const predicatePhrase = ${predicatePhrase};`,
|
|
188
|
+
`const factSentence = ${factSentence};`,
|
|
189
|
+
].join("\n ");
|
|
190
|
+
}
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
import { findIsaChain, buildSubClassSuccessors, SUBCLASS_PREDICATE, TYPE_PREDICATE } from "../syllogise.mjs";
|
|
22
22
|
|
|
23
23
|
/** The negative-polarity CURIE prefix. A separate prefix, never an
|
|
24
|
-
* "mgx:not-<lemma>" mint:
|
|
24
|
+
* "mgx:not-<lemma>" mint: fact-phrase.mjs's predicatePhrase reads "mgx:not-fly" as
|
|
25
25
|
* lemma "not" plus tail "fly" and renders "nots fly", and its preposition fold
|
|
26
26
|
* is guarded on /^mgx:[a-z]+$/, which a hyphenated mint fails — so
|
|
27
27
|
* "a penguin cannot rest on water" would strand "on water" inside the object
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// phrase-exports.mjs — the package's `./phrase` export subpath: how tmct
|
|
2
|
+
// renders a stored fact and its provenance, reachable without pulling in the
|
|
3
|
+
// chat engine the "." entry carries. An embedding host that shows tmct's own
|
|
4
|
+
// answers back to its users renders the same rows the same way tmct does,
|
|
5
|
+
// rather than re-deriving English from raw CURIEs.
|
|
6
|
+
//
|
|
7
|
+
// Everything here is pure and synchronous: no graph, no store, no I/O.
|
|
8
|
+
|
|
9
|
+
// The predicate -> English reader the answer path itself uses, plus the table
|
|
10
|
+
// behind it and the verb-surface folds it stands on.
|
|
11
|
+
export {
|
|
12
|
+
FACT_PREDICATE_PHRASES,
|
|
13
|
+
predicatePhrase,
|
|
14
|
+
factSentence,
|
|
15
|
+
thirdPersonSingularSurface,
|
|
16
|
+
baseVerbSurface,
|
|
17
|
+
gerundVerbSurface,
|
|
18
|
+
} from "./fact-phrase.mjs";
|
|
19
|
+
|
|
20
|
+
// Provenance: the `reference:<pack>:<Title>@<revid>` tag a reference-grounded
|
|
21
|
+
// fact carries, turned back into the revision-pinned article link tmct cites.
|
|
22
|
+
export {
|
|
23
|
+
referenceTagToUrl,
|
|
24
|
+
articleUrlFor,
|
|
25
|
+
REFERENCE_PACK_NAME,
|
|
26
|
+
REFERENCE_PACK_ORIGIN,
|
|
27
|
+
LIVE_PACK_NAME,
|
|
28
|
+
LIVE_PACK_ORIGIN,
|
|
29
|
+
} from "./reference-pack.mjs";
|
|
@@ -87,6 +87,16 @@ export function referenceProvenanceTag(article) {
|
|
|
87
87
|
return `reference:${REFERENCE_PACK_NAME}:${article.title}@${article.revid}`;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
/** Wikimedia titles are underscored and percent-encoded in a wiki URL. The
|
|
91
|
+
* build script (scripts/fetch-reference-pack.mjs) stamps every shipped row's
|
|
92
|
+
* `url` with this, and referenceTagToUrl below rebuilds the same link from a
|
|
93
|
+
* stored fact's provenance tag. */
|
|
94
|
+
export const REFERENCE_PACK_ORIGIN = "https://simple.wikipedia.org";
|
|
95
|
+
|
|
96
|
+
export function articleUrlFor(origin, title) {
|
|
97
|
+
return `${origin}/wiki/${encodeURIComponent(String(title).replace(/ /g, "_"))}`;
|
|
98
|
+
}
|
|
99
|
+
|
|
90
100
|
/** The pure half of the clean-miss gate: is this term even a pack-lookup
|
|
91
101
|
* candidate, and under which key? Returns the pack key (the lexicon entry's
|
|
92
102
|
* lemma, normFactTerm-folded) or null when the term is empty, not plain
|
|
@@ -115,6 +125,42 @@ export function liveProvenanceTag(article) {
|
|
|
115
125
|
return `reference:${LIVE_PACK_NAME}:${article.title}@${article.revid}`;
|
|
116
126
|
}
|
|
117
127
|
|
|
128
|
+
export const LIVE_PACK_ORIGIN = "https://en.wikipedia.org";
|
|
129
|
+
const ORIGIN_BY_PACK = new Map([
|
|
130
|
+
[REFERENCE_PACK_NAME, REFERENCE_PACK_ORIGIN],
|
|
131
|
+
[LIVE_PACK_NAME, LIVE_PACK_ORIGIN],
|
|
132
|
+
]);
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* The revision-pinned article a `reference:<pack>:<Title>@<revid>` provenance
|
|
136
|
+
* tag names: `{ pack, title, revid, url }`, or null. Null covers every tag
|
|
137
|
+
* this cannot place — a tag from another source kind, a pack with no known
|
|
138
|
+
* origin, a missing or non-numeric revision — because a consumer showing
|
|
139
|
+
* provenance needs a link it can follow or nothing at all, never one assembled
|
|
140
|
+
* out of a guess about where the article might live.
|
|
141
|
+
*
|
|
142
|
+
* The `?oldid=` query pins the revision the fact was read from, exactly as
|
|
143
|
+
* renderReferenceAnswer cites it in chat.
|
|
144
|
+
*/
|
|
145
|
+
export function referenceTagToUrl(tag) {
|
|
146
|
+
const t = String(tag ?? "").trim();
|
|
147
|
+
if (!t.startsWith("reference:")) return null;
|
|
148
|
+
const rest = t.slice("reference:".length);
|
|
149
|
+
const colon = rest.indexOf(":");
|
|
150
|
+
if (colon < 0) return null;
|
|
151
|
+
const origin = ORIGIN_BY_PACK.get(rest.slice(0, colon));
|
|
152
|
+
if (!origin) return null;
|
|
153
|
+
// The article segment keeps its spaces and may contain "@" itself, so the
|
|
154
|
+
// revision splits off the LAST one and only counts when it is all digits.
|
|
155
|
+
const article = rest.slice(colon + 1);
|
|
156
|
+
const at = article.lastIndexOf("@");
|
|
157
|
+
if (at < 1) return null;
|
|
158
|
+
const revid = article.slice(at + 1);
|
|
159
|
+
if (!/^\d+$/.test(revid)) return null;
|
|
160
|
+
const title = article.slice(0, at);
|
|
161
|
+
return { pack: rest.slice(0, colon), title, revid, url: `${articleUrlFor(origin, title)}?oldid=${revid}` };
|
|
162
|
+
}
|
|
163
|
+
|
|
118
164
|
/** The cited answer for a clean miss the live lookup could ground: the
|
|
119
165
|
* article's summary with its title, the LIVE source named, the licence and
|
|
120
166
|
* the revision-pinned URL always visible. */
|