@polycode-projects/the-mechanical-code-talker 5.0.25 → 5.0.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,224 @@
1
+ // feed-normalize.mjs — turns raw feed text (RSS 2.0, Atom, JSON Feed 1.1) into
2
+ // normalized item snapshots. String scanning throughout: a domain module may
3
+ // import nothing beyond another domain module (test/estate/import-layers.test.mjs),
4
+ // which rules out DOMParser and any XML package, so every parser here reads a
5
+ // feed the same way both sibling repos already do (PLAN_NEWS_FEED.md section 5).
6
+ // The parsers are lenient by construction — an unparseable block is skipped,
7
+ // never thrown — because a feed on the open internet is never fully well-formed.
8
+
9
+ import { sha256Bytes } from "./hash.mjs";
10
+
11
+ const NAMED_ENTITIES = { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'", nbsp: " " };
12
+
13
+ function decodeEntities(text) {
14
+ return text.replace(/&(#x[0-9a-f]+|#[0-9]+|[a-z]+);/gi, (whole, body) => {
15
+ if (body[0] === "#") {
16
+ const isHex = body[1] === "x" || body[1] === "X";
17
+ const codePoint = Number.parseInt(body.slice(isHex ? 2 : 1), isHex ? 16 : 10);
18
+ return Number.isFinite(codePoint) ? String.fromCodePoint(codePoint) : whole;
19
+ }
20
+ const key = body.toLowerCase();
21
+ return Object.hasOwn(NAMED_ENTITIES, key) ? NAMED_ENTITIES[key] : whole;
22
+ });
23
+ }
24
+
25
+ /** Strips tags and CDATA wrappers, decodes entities, collapses whitespace.
26
+ * The first half of the two-layer sanitisation rule (constitution section 3):
27
+ * strip at parse time, escape again at render time. A `<script>` block loses
28
+ * its tags here same as any other markup; what is left is inert plain text. */
29
+ export function stripMarkup(text) {
30
+ let s = String(text ?? "");
31
+ s = s.replace(/<!\[CDATA\[([\s\S]*?)\]\]>/g, "$1");
32
+ // Decoded BEFORE tags are stripped: an Atom summary/content declared
33
+ // type="html" carries its markup entity-escaped ("&lt;p&gt;"), and only
34
+ // decoding first turns that back into real tags this function can then
35
+ // remove. Literal markup (the CDATA-unwrapped case above) is unaffected by
36
+ // the ordering, since it has no entities standing in for its tags.
37
+ s = decodeEntities(s);
38
+ s = s.replace(/<!--[\s\S]*?-->/g, " ");
39
+ s = s.replace(/<[^>]*>/g, " ");
40
+ s = s.replace(/\s+/g, " ").trim();
41
+ return s;
42
+ }
43
+
44
+ /** "rss" | "atom" | "jsonfeed" | null, decided from the text's own shape. */
45
+ export function detectFeedFormat(text) {
46
+ const s = String(text ?? "");
47
+ const trimmed = s.trim();
48
+ if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
49
+ try {
50
+ const parsed = JSON.parse(trimmed);
51
+ const version = typeof parsed?.version === "string" ? parsed.version : "";
52
+ if (version.startsWith("https://jsonfeed.org/")) return "jsonfeed";
53
+ } catch {
54
+ // not JSON at all — fall through to the XML checks below
55
+ }
56
+ }
57
+ if (/<feed\b[^>]*xmlns\s*=\s*["']http:\/\/www\.w3\.org\/2005\/Atom["']/i.test(s)) return "atom";
58
+ if (/<rss\b/i.test(s) || /<channel\b/i.test(s)) return "rss";
59
+ return null;
60
+ }
61
+
62
+ function sha256HexPrefix(str, nBytes) {
63
+ const bytes = sha256Bytes(str);
64
+ let hex = "";
65
+ for (let i = 0; i < nBytes; i += 1) hex += bytes[i].toString(16).padStart(2, "0");
66
+ return hex;
67
+ }
68
+
69
+ /** `news-item:${sha256Hex(sourceId\0guidOrUrl, 8)}` — content-addressed so
70
+ * re-fetching the same item across polls upserts rather than duplicating. */
71
+ export function feedItemId(sourceId, guidOrUrl) {
72
+ return `news-item:${sha256HexPrefix(`${sourceId}\0${guidOrUrl}`, 8)}`;
73
+ }
74
+
75
+ function firstTagContent(block, tagNames) {
76
+ for (const name of tagNames) {
77
+ const match = new RegExp(`<${name}\\b[^>]*>([\\s\\S]*?)<\\/${name}>`, "i").exec(block);
78
+ if (match) return match[1];
79
+ }
80
+ return "";
81
+ }
82
+
83
+ function normalizeDate(raw) {
84
+ const s = String(raw ?? "").trim();
85
+ if (!s) return "";
86
+ const t = Date.parse(s);
87
+ return Number.isFinite(t) ? new Date(t).toISOString() : "";
88
+ }
89
+
90
+ /** [{ guid, title, url, summary, publishedAt }], document order, capped at
91
+ * `limit`. Reads `<guid>`, `<title>`, `<link>`, `<description>`, `<pubDate>`
92
+ * else `<dc:date>` off each `<item>` block — the RSS 2.0 core plus the one
93
+ * Dublin Core fallback real-world feeds actually carry. */
94
+ export function parseRss(text, { limit = 50 } = {}) {
95
+ const items = [];
96
+ const blockRe = /<item\b[^>]*>([\s\S]*?)<\/item>/gi;
97
+ let match;
98
+ while (items.length < limit && (match = blockRe.exec(String(text ?? "")))) {
99
+ try {
100
+ const block = match[1];
101
+ items.push({
102
+ guid: stripMarkup(firstTagContent(block, ["guid"])),
103
+ title: stripMarkup(firstTagContent(block, ["title"])),
104
+ url: stripMarkup(firstTagContent(block, ["link"])),
105
+ summary: stripMarkup(firstTagContent(block, ["description"])),
106
+ publishedAt: normalizeDate(stripMarkup(firstTagContent(block, ["pubDate", "dc:date"]))),
107
+ });
108
+ } catch {
109
+ // a malformed <item> block is skipped, never thrown
110
+ }
111
+ }
112
+ return items;
113
+ }
114
+
115
+ function extractAtomLink(block) {
116
+ const linkRe = /<link\b([^>]*?)\/?>/gi;
117
+ let fallback = "";
118
+ let match;
119
+ while ((match = linkRe.exec(block))) {
120
+ const attrs = match[1];
121
+ const hrefMatch = /href\s*=\s*["']([^"']*)["']/i.exec(attrs);
122
+ if (!hrefMatch) continue;
123
+ const relMatch = /rel\s*=\s*["']([^"']*)["']/i.exec(attrs);
124
+ const rel = relMatch ? relMatch[1] : "alternate";
125
+ if (rel === "alternate") return hrefMatch[1];
126
+ if (!fallback) fallback = hrefMatch[1];
127
+ }
128
+ return fallback;
129
+ }
130
+
131
+ /** [{ guid, title, url, summary, publishedAt }], document order, capped at
132
+ * `limit`. Reads `<id>`, `<title>`, `<link href>` (rel="alternate" preferred),
133
+ * `<summary>` else `<content>`, `<updated>` else `<published>` off each
134
+ * `<entry>` block. */
135
+ export function parseAtom(text, { limit = 50 } = {}) {
136
+ const items = [];
137
+ const blockRe = /<entry\b[^>]*>([\s\S]*?)<\/entry>/gi;
138
+ let match;
139
+ while (items.length < limit && (match = blockRe.exec(String(text ?? "")))) {
140
+ try {
141
+ const block = match[1];
142
+ items.push({
143
+ guid: stripMarkup(firstTagContent(block, ["id"])),
144
+ title: stripMarkup(firstTagContent(block, ["title"])),
145
+ url: stripMarkup(extractAtomLink(block)),
146
+ summary: stripMarkup(firstTagContent(block, ["summary", "content"])),
147
+ publishedAt: normalizeDate(stripMarkup(firstTagContent(block, ["updated", "published"]))),
148
+ });
149
+ } catch {
150
+ // a malformed <entry> block is skipped, never thrown
151
+ }
152
+ }
153
+ return items;
154
+ }
155
+
156
+ /** [{ guid, title, url, summary, publishedAt }], document order, capped at
157
+ * `limit`. JSON Feed 1.1's own field names; `content_text` wins over
158
+ * `stripMarkup(content_html)` over `summary`, per the spec's own precedence. */
159
+ export function parseJsonFeed(text, { limit = 50 } = {}) {
160
+ let parsed;
161
+ try {
162
+ parsed = JSON.parse(String(text ?? ""));
163
+ } catch {
164
+ return [];
165
+ }
166
+ const rawItems = Array.isArray(parsed?.items) ? parsed.items : [];
167
+ const items = [];
168
+ for (const raw of rawItems) {
169
+ if (items.length >= limit) break;
170
+ if (!raw || typeof raw !== "object") continue;
171
+ const summary = raw.content_text
172
+ ?? (raw.content_html ? stripMarkup(raw.content_html) : "")
173
+ ?? raw.summary
174
+ ?? "";
175
+ items.push({
176
+ guid: String(raw.id ?? ""),
177
+ title: stripMarkup(String(raw.title ?? "")),
178
+ url: String(raw.url ?? ""),
179
+ summary: stripMarkup(String(summary)),
180
+ publishedAt: normalizeDate(raw.date_published),
181
+ });
182
+ }
183
+ return items;
184
+ }
185
+
186
+ /** Dispatches to the right parser, auto-detecting the format when none is
187
+ * given. An unrecognised format yields an empty list, never a throw. */
188
+ export function parseFeed(text, { format = null, limit = 50 } = {}) {
189
+ const fmt = format || detectFeedFormat(text);
190
+ if (fmt === "rss") return parseRss(text, { limit });
191
+ if (fmt === "atom") return parseAtom(text, { limit });
192
+ if (fmt === "jsonfeed") return parseJsonFeed(text, { limit });
193
+ return [];
194
+ }
195
+
196
+ /** Raw parsed items -> snapshot records (PLAN_NEWS_FEED.md section 6.2),
197
+ * `fetchedAt` stamped from the caller's `now`, deduped by content-addressed
198
+ * id, document order kept, capped at `limit`. */
199
+ export function normalizeFeedItems(sourceId, rawItems, { now = "", limit = Infinity } = {}) {
200
+ const seen = new Set();
201
+ const out = [];
202
+ for (const raw of rawItems ?? []) {
203
+ if (out.length >= limit) break;
204
+ const guidOrUrl = raw?.guid || raw?.url || "";
205
+ if (!guidOrUrl) continue;
206
+ const id = feedItemId(sourceId, guidOrUrl);
207
+ if (seen.has(id)) continue;
208
+ seen.add(id);
209
+ out.push({
210
+ id,
211
+ sourceId,
212
+ title: raw.title || "",
213
+ url: raw.url || "",
214
+ summary: raw.summary || "",
215
+ publishedAt: raw.publishedAt || "",
216
+ fetchedAt: now,
217
+ bytes: 0,
218
+ processedRounds: 0,
219
+ factIds: [],
220
+ extras: null,
221
+ });
222
+ }
223
+ return out;
224
+ }
@@ -1,5 +1,5 @@
1
1
  // grammar/ace.mjs — tmct's deterministic ACE-OWL sub-fragment parser.
2
- // Implements the 9 controlled-English sentence patterns of
2
+ // Implements the 17 controlled-English sentence patterns of
3
3
  // docs/references/schemas/ace-owl-fragment.md and nothing more: fitting the
4
4
  // grammar is a strong signal, missing it is a FEATURE — parseAce returns null
5
5
  // (or an empty-triples result carrying the unknown words as `residue`) and the
@@ -47,12 +47,22 @@ const PATTERN_DISJOINT_WITH = "disjointWith";
47
47
  const PATTERN_POSSESSIVE = "possessive";
48
48
  const PATTERN_ADJECTIVE = "adjective";
49
49
  const PATTERN_CAPABILITY = "capability";
50
+ const PATTERN_UNION = "union";
51
+ const PATTERN_COMPLEMENT = "complement";
52
+ const PATTERN_NEGATIVE_TYPE = "negativeType";
53
+ const PATTERN_ENUMERATION = "enumeration";
54
+ const PATTERN_DIFFERENT_FROM = "differentFrom";
55
+ const PATTERN_BARE_EXISTENTIAL = "bareExistential";
56
+ const PATTERN_TRANSITIVE_ROLE = "transitiveRole";
57
+ const PATTERN_INVERSE_ROLE = "inverseRole";
50
58
 
51
59
  /** The pattern field's full domain, in the README's table order. */
52
60
  const PATTERNS = Object.freeze([
53
61
  PATTERN_SUB_CLASS_OF, PATTERN_TYPE_ASSERTION, PATTERN_RELATION, PATTERN_SOME_VALUES_FROM,
54
62
  PATTERN_CARDINALITY, PATTERN_DISJOINT_WITH, PATTERN_POSSESSIVE, PATTERN_ADJECTIVE,
55
- PATTERN_CAPABILITY,
63
+ PATTERN_CAPABILITY, PATTERN_UNION, PATTERN_COMPLEMENT, PATTERN_NEGATIVE_TYPE,
64
+ PATTERN_ENUMERATION, PATTERN_DIFFERENT_FROM, PATTERN_BARE_EXISTENTIAL, PATTERN_TRANSITIVE_ROLE,
65
+ PATTERN_INVERSE_ROLE,
56
66
  ]);
57
67
 
58
68
  const DET = new Set(["a", "an", "the"]);
@@ -395,7 +405,81 @@ function parseCardinality(lexicon, toks, lower, hasIdx) {
395
405
  ], { n });
396
406
  }
397
407
 
398
- /** Patterns 1, 4, 5 and 8's "every …" arm. */
408
+ /** Pattern 10 — "every N1 is a N2 or a N3 [or a N4 …]" → owl:unionOf, arms
409
+ * sorted by local name so "a cat or a dog" and "a dog or a cat" mint the
410
+ * identical union node and re-teaching the sentence stays idempotent. */
411
+ function parseUnion(lexicon, toks, isIdx) {
412
+ const ns = lexicon.ns;
413
+ const rest = toks.slice(isIdx + 1);
414
+ const restLower = rest.map((t) => t.toLowerCase());
415
+ const orAt = [];
416
+ restLower.forEach((t, i) => { if (t === "or") orAt.push(i); });
417
+ if (!orAt.length) return null;
418
+ const np1 = resolveNP(lexicon, toks.slice(1, isIdx));
419
+ const arms = [];
420
+ let start = 0;
421
+ for (const pos of [...orAt, rest.length]) {
422
+ arms.push(resolveNP(lexicon, rest.slice(start, pos)));
423
+ start = pos + 1;
424
+ }
425
+ const allNps = [np1, ...arms];
426
+ if (allNps.some((np) => np.term == null)) return missOrNull(PATTERN_UNION, allNps);
427
+ if (allNps.some((np) => np.individual)) return null;
428
+ const sortedArms = [...arms].sort((a, b) => {
429
+ const la = local(lexicon, a.term);
430
+ const lb = local(lexicon, b.term);
431
+ return la < lb ? -1 : la > lb ? 1 : 0;
432
+ });
433
+ const u = `${ns}${sortedArms.map((a) => local(lexicon, a.term)).join("-or-")}`;
434
+ return hit(PATTERN_UNION, allNps, [
435
+ { subject: u, predicate: "rdf:type", object: "owl:Class", kind: "owl:unionOf" },
436
+ ...sortedArms.map((a) => ({ subject: u, predicate: "owl:unionOf", object: a.term, kind: "owl:unionOf" })),
437
+ { subject: np1.term, predicate: "rdfs:subClassOf", object: u, kind: "owl:unionOf" },
438
+ ]);
439
+ }
440
+
441
+ /** Pattern 15 — "every N1 VERB [det] N2" → someValuesFrom bare existential
442
+ * restriction: "every heart has a valve" (the `has` verb), and the general
443
+ * verb form "every heart contains a valve". Tried after the `that` and
444
+ * cardinality arms — `parseCardinality` already claims the sentence when the
445
+ * token after "has" is "at"/"exactly". No compound object (matches
446
+ * `parseRestriction`/`parseCardinality`'s own convention), so a two-noun
447
+ * object phrase a curated has-a teach owns ("a render method") stays
448
+ * declined here and falls through untouched. */
449
+ function parseBareExistential(lexicon, toks, lower) {
450
+ const ns = lexicon.ns;
451
+ for (let i = 2; i < toks.length - 1; i += 1) {
452
+ const verb = lookupVerb(lexicon, lower[i]);
453
+ if (!verb) continue;
454
+ let objStart = i + 1;
455
+ if (verb.prep) {
456
+ if (lower[objStart] !== verb.prep) continue;
457
+ objStart += 1;
458
+ if (objStart >= toks.length) continue;
459
+ }
460
+ const np1 = resolveNP(lexicon, toks.slice(1, i));
461
+ // A subject that fails to resolve at THIS verb position means the word at
462
+ // `i` is a coincidental noun/verb homonym ("test" in "every flaky test is
463
+ // a risk") sitting inside a sentence this arm was never meant to claim —
464
+ // try the next candidate verb position rather than committing to a miss
465
+ // that would shadow whichever OTHER pattern actually fits.
466
+ if (np1.term == null) continue;
467
+ const np2 = resolveNP(lexicon, toks.slice(objStart));
468
+ if (np2.term == null) return missOrNull(PATTERN_BARE_EXISTENTIAL, [np1, np2]);
469
+ if (np1.individual || np2.individual) return null;
470
+ const pred = predicateOf(verb, ns);
471
+ const r = `${ns}some-${local(lexicon, pred)}-${local(lexicon, np2.term)}`;
472
+ return hit(PATTERN_BARE_EXISTENTIAL, [np1, np2], [
473
+ { subject: r, predicate: "rdf:type", object: "owl:Restriction", kind: "owl:someValuesFrom" },
474
+ { subject: r, predicate: "owl:onProperty", object: pred, kind: "owl:someValuesFrom" },
475
+ { subject: r, predicate: "owl:someValuesFrom", object: np2.term, kind: "owl:someValuesFrom" },
476
+ { subject: np1.term, predicate: "rdfs:subClassOf", object: r, kind: "owl:someValuesFrom" },
477
+ ]);
478
+ }
479
+ return null;
480
+ }
481
+
482
+ /** Patterns 1, 4, 5, 8, 10 and 15's "every …" arm. */
399
483
  function parseEvery(lexicon, toks, lower) {
400
484
  const thatIdx = lower.indexOf("that");
401
485
  if (thatIdx > 1) return parseRestriction(lexicon, toks, lower, thatIdx);
@@ -403,8 +487,12 @@ function parseEvery(lexicon, toks, lower) {
403
487
  if (hasIdx > 1 && (lower[hasIdx + 1] === "at" || lower[hasIdx + 1] === "exactly")) {
404
488
  return parseCardinality(lexicon, toks, lower, hasIdx);
405
489
  }
490
+ const bareExistential = parseBareExistential(lexicon, toks, lower);
491
+ if (bareExistential) return bareExistential;
406
492
  const isIdx = lower.indexOf("is");
407
493
  if (isIdx <= 1 || isIdx === toks.length - 1) return null;
494
+ const union = parseUnion(lexicon, toks, isIdx);
495
+ if (union) return union;
408
496
  const rest = toks.slice(isIdx + 1);
409
497
  const everyAdjOnly = rest.length === 1 ? lookupAdjective(lexicon, rest[0]) : null;
410
498
  const subjectToks = toks.slice(1, isIdx);
@@ -439,6 +527,117 @@ function parseDisjoint(lexicon, toks, lower) {
439
527
  ]);
440
528
  }
441
529
 
530
+ /** Pattern 11 — "everything that is not N1 is N2" → owl:complementOf. Also
531
+ * accepts an articled N1 ("everything that is not a N1 is a N2"). */
532
+ function parseComplement(lexicon, toks, lower) {
533
+ const ns = lexicon.ns;
534
+ if (lower[2] !== "is" || lower[3] !== "not") return null;
535
+ const isIdx = lower.indexOf("is", 4);
536
+ if (isIdx < 5) return null;
537
+ const np1 = resolveNP(lexicon, toks.slice(4, isIdx));
538
+ const np2 = resolveNP(lexicon, toks.slice(isIdx + 1));
539
+ if (np1.term == null || np2.term == null) return missOrNull(PATTERN_COMPLEMENT, [np1, np2]);
540
+ if (np1.individual || np2.individual) return null;
541
+ const c = `${ns}not-${local(lexicon, np1.term)}`;
542
+ return hit(PATTERN_COMPLEMENT, [np1, np2], [
543
+ { subject: c, predicate: "rdf:type", object: "owl:Class", kind: "owl:complementOf" },
544
+ { subject: c, predicate: "owl:complementOf", object: np1.term, kind: "owl:complementOf" },
545
+ { subject: c, predicate: "rdfs:subClassOf", object: np2.term, kind: "owl:complementOf" },
546
+ ]);
547
+ }
548
+
549
+ /** Patterns 12 and 14 — "SUBJECT is not OBJECT" where the subject resolves as
550
+ * an individual (a declared proper name or a code-ref shape — resolveNP's
551
+ * own `individual` flag, deliberately narrower than `readsAsIndividualName`,
552
+ * so an undeclared bare word stays the class-level pattern 6's territory,
553
+ * never silently reinterpreted here): owl:disjointWith when the object is a
554
+ * declared class, owl:differentFrom when the object is another individual. */
555
+ function parseNegation(lexicon, toks, lower, isIdx) {
556
+ if (lower[isIdx + 1] !== "not") return null;
557
+ const rest = toks.slice(isIdx + 2);
558
+ if (!rest.length) return null;
559
+ const np1 = resolveNP(lexicon, toks.slice(0, isIdx));
560
+ const np2 = resolveNP(lexicon, rest);
561
+ if (np1.term == null || np2.term == null) return missOrNull(PATTERN_NEGATIVE_TYPE, [np1, np2]);
562
+ if (!np1.individual) return null;
563
+ if (np2.individual) {
564
+ return hit(PATTERN_DIFFERENT_FROM, [np1, np2], [
565
+ { subject: np1.term, predicate: "owl:differentFrom", object: np2.term, kind: "owl:differentFrom" },
566
+ ]);
567
+ }
568
+ return hit(PATTERN_NEGATIVE_TYPE, [np1, np2], [
569
+ { subject: np1.term, predicate: "owl:disjointWith", object: np2.term, kind: "owl:disjointWith" },
570
+ ]);
571
+ }
572
+
573
+ /** Pattern 13 — "the N1 N2s are exactly M1, M2 [and M3 …]" → owl:oneOf, with
574
+ * the positive rdf:type half and the pairwise owl:differentFrom closure
575
+ * UNA-lite's merge machinery needs. `tokenize` already drops commas, so the
576
+ * member list is the token run with "and" as the only separator left.
577
+ * Members sort lexicographically before emission, so re-teaching the same
578
+ * sentence re-emits the identical triple list. */
579
+ function parseEnumeration(lexicon, toks, lower) {
580
+ const areIdx = lower.indexOf("are");
581
+ if (areIdx < 2 || lower[areIdx + 1] !== "exactly") return null;
582
+ const memberToks = toks.slice(areIdx + 2).filter((t) => t.toLowerCase() !== "and");
583
+ if (!memberToks.length) return null;
584
+ const subject = resolveNP(lexicon, toks.slice(1, areIdx));
585
+ const members = memberToks.map((t) => resolveNP(lexicon, [t]));
586
+ const allNps = [subject, ...members];
587
+ if (allNps.some((np) => np.term == null)) return missOrNull(PATTERN_ENUMERATION, allNps);
588
+ if (subject.individual || members.some((m) => m.individual)) return null;
589
+ const sorted = [...members].sort((a, b) => (a.term < b.term ? -1 : a.term > b.term ? 1 : 0));
590
+ const triples = [
591
+ ...sorted.map((m) => ({ subject: subject.term, predicate: "owl:oneOf", object: m.term, kind: "owl:oneOf" })),
592
+ ...sorted.map((m) => ({ subject: m.term, predicate: "rdf:type", object: subject.term, kind: "owl:oneOf" })),
593
+ ];
594
+ for (let i = 0; i < sorted.length; i += 1) {
595
+ for (let j = i + 1; j < sorted.length; j += 1) {
596
+ triples.push({ subject: sorted[i].term, predicate: "owl:differentFrom", object: sorted[j].term, kind: "owl:differentFrom" });
597
+ }
598
+ }
599
+ return hit(PATTERN_ENUMERATION, allNps, triples);
600
+ }
601
+
602
+ /** A declared verb's minted predicate from a bare surface form: the 3sg
603
+ * surface ("contains") through the existing `lookupVerb` fold, or its
604
+ * gerund ("containing") through a small local ing-stripping fold — the
605
+ * lexicon's own morphology never folds gerunds, since patterns 16 and 17
606
+ * are the only ones that need one. Returns null for an undeclared verb. */
607
+ function verbPredicateFromSurface(lexicon, surface) {
608
+ let verb = lookupVerb(lexicon, surface);
609
+ if (!verb && surface.length > 4 && /ing$/.test(surface)) {
610
+ const stem = surface.slice(0, -3);
611
+ verb = lookupVerb(lexicon, stem) || lookupVerb(lexicon, `${stem}e`);
612
+ }
613
+ return verb ? predicateOf(verb, lexicon.ns) : null;
614
+ }
615
+
616
+ /** Pattern 16 — "VERB is transitive" → owl:TransitiveProperty on the verb's
617
+ * minted predicate. */
618
+ function parseTransitiveRole(lexicon, toks, lower) {
619
+ const pred = verbPredicateFromSurface(lexicon, lower[0]);
620
+ if (!pred) return null;
621
+ return hit(PATTERN_TRANSITIVE_ROLE, [], [
622
+ { subject: pred, predicate: "rdf:type", object: "owl:TransitiveProperty", kind: "owl:TransitiveProperty" },
623
+ ]);
624
+ }
625
+
626
+ /** Pattern 17 — "V1 is the inverse of V2" → owl:inverseOf between the two
627
+ * verbs' minted predicates, both directions (unlike owl:differentFrom's
628
+ * one-direction storage), so either verb's forward walk finds the other
629
+ * with no extra graph hop. Each side accepts the same 3sg-or-gerund fold
630
+ * pattern 16 does. */
631
+ function parseInverseRole(lexicon, toks, lower) {
632
+ const p1 = verbPredicateFromSurface(lexicon, lower[0]);
633
+ const p2 = verbPredicateFromSurface(lexicon, lower[5]);
634
+ if (!p1 || !p2) return null;
635
+ return hit(PATTERN_INVERSE_ROLE, [], [
636
+ { subject: p1, predicate: "owl:inverseOf", object: p2, kind: "owl:inverseOf" },
637
+ { subject: p2, predicate: "owl:inverseOf", object: p1, kind: "owl:inverseOf" },
638
+ ]);
639
+ }
640
+
442
641
  /** Pattern 7 — "N1's N2 is VALUE" / "the N2 of N1 is VALUE": data or object
443
642
  * property assertion per the possessive noun's DECLARED typing (undeclared
444
643
  * typing defaults to data — a literal value is the honest floor). */
@@ -522,21 +721,38 @@ function parseCopula(lexicon, toks, lower, isIdx) {
522
721
  ]);
523
722
  }
524
723
 
525
- /** Parse one sentence against the 9-pattern ACE-OWL sub-fragment. See the file
526
- * header for the result contract; `lexicon` defaults to the committed core
527
- * under the library's own neutral DEFAULT_NS ("ex:") when the caller doesn't
528
- * supply one. */
724
+ /** Parse one sentence against the 17-pattern ACE-OWL sub-fragment. See the
725
+ * file header for the result contract; `lexicon` defaults to the committed
726
+ * core under the library's own neutral DEFAULT_NS ("ex:") when the caller
727
+ * doesn't supply one. */
529
728
  export function parseAce(sentence, lexicon = loadLexicon()) {
530
729
  const toks = tokenize(sentence);
531
730
  if (toks.length < 3) return null;
532
731
  const lower = toks.map((t) => t.toLowerCase());
732
+ if (toks.length === 3 && lower[1] === "is" && lower[2] === "transitive") {
733
+ const transitive = parseTransitiveRole(lexicon, toks, lower);
734
+ if (transitive) return transitive;
735
+ }
736
+ if (toks.length === 6 && lower[1] === "is" && lower[2] === "the" && lower[3] === "inverse" && lower[4] === "of") {
737
+ const inverse = parseInverseRole(lexicon, toks, lower);
738
+ if (inverse) return inverse;
739
+ }
740
+ if (lower[0] === "everything" && lower[1] === "that") return parseComplement(lexicon, toks, lower);
533
741
  if (lower[0] === "every") return parseEvery(lexicon, toks, lower);
534
742
  if (lower[0] === "no") return parseDisjoint(lexicon, toks, lower);
535
743
  if (/'s$/.test(lower[0]) && lower[0].length > 2) return parsePossessive(lexicon, toks, lower);
536
744
  if (lower[0] === "the" && lower.includes("of") && lower.includes("is")) {
537
745
  return parseOfForm(lexicon, toks, lower);
538
746
  }
747
+ if (lower[0] === "the" && lower.includes("are") && lower.includes("exactly")) {
748
+ const enumeration = parseEnumeration(lexicon, toks, lower);
749
+ if (enumeration) return enumeration;
750
+ }
539
751
  const isIdx = lower.indexOf("is");
752
+ if (isIdx > 0 && lower[isIdx + 1] === "not") {
753
+ const negation = parseNegation(lexicon, toks, lower, isIdx);
754
+ if (negation) return negation;
755
+ }
540
756
  if (isIdx > 0) return parseCopula(lexicon, toks, lower, isIdx);
541
757
  const canIdx = lower.indexOf("can");
542
758
  if (canIdx > 0 && canIdx < toks.length - 1) {
@@ -5467,6 +5467,7 @@
5467
5467
  "sloe": {},
5468
5468
  "taro": {},
5469
5469
  "teal": {},
5470
+ "yellow": {},
5470
5471
  "titi": {},
5471
5472
  "twig": {},
5472
5473
  "amber": {},
@@ -5561,6 +5562,7 @@
5561
5562
  },
5562
5563
  "apricot": {},
5563
5564
  "aquatic": {},
5565
+ "terrestrial": {},
5564
5566
  "asphalt": {},
5565
5567
  "avocado": {},
5566
5568
  "beebalm": {},
@@ -160,6 +160,21 @@ export function provenanceTagToSource(tag) {
160
160
  }
161
161
  if (head.startsWith("web:")) return { kind: "web", url: head.slice("web:".length) };
162
162
  if (head.startsWith("url:")) return { kind: "web", url: head.slice("url:".length) };
163
+ // news-fixture:<sourceId>@<itemId> — the shipped demo buttons replaying a
164
+ // recorded fixture through the live pipeline, scored at the corpus tier so
165
+ // a fixture-replayed item never reads as a live claim.
166
+ if (head.startsWith("news-fixture:")) return { kind: "corpus", name: head.slice("news-fixture:".length).split("@")[0] || "unknown" };
167
+ // extracted:news:<sourceId>@<itemId> — the news capability's own
168
+ // strict-tier writes (a poll's contemporary items), routed through the
169
+ // same ingestText audit-tag wrapper every extracted: caller shares. Scored
170
+ // at the web-page tier rather than the generic extracted: tier, so a live
171
+ // news fetch never outranks the shipped reference packs. Checked ahead of
172
+ // the bare extracted: fallback below, which still catches every other
173
+ // extracted: caller unchanged. A bare news:<sourceId>@<itemId> tag (a
174
+ // future caller that writes it directly, with no extracted: wrapper)
175
+ // scores the same way.
176
+ if (head.startsWith("extracted:news:")) return { kind: "web", url: head.slice("extracted:".length) };
177
+ if (head.startsWith("news:")) return { kind: "web", url: head };
163
178
  if (head.startsWith("optimistic-extract:")) return { kind: "optimisticExtract", name: head.slice("optimistic-extract:".length) || "unknown" };
164
179
  if (head.startsWith("extracted:")) return { kind: "extracted", name: head.slice("extracted:".length) || "unknown" };
165
180
  if (head.startsWith("entailed:")) return { kind: "entailed", rule: head.slice("entailed:".length) };