@ontology-kit/okb 0.1.0 → 0.3.0-alpha.210
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 +1 -1
- package/dist/check.d.ts +43 -0
- package/dist/check.js +83 -0
- package/dist/checks.d.ts +1 -1
- package/dist/checks.js +4 -4
- package/dist/cli.js +11 -705
- package/dist/clidocs.d.ts +0 -2
- package/dist/clidocs.js +5 -27
- package/dist/clock.js +1 -1
- package/dist/command-table.d.ts +134 -0
- package/dist/command-table.js +82 -0
- package/dist/commands/documents.d.ts +3 -0
- package/dist/commands/documents.js +250 -0
- package/dist/commands/getting-started.d.ts +3 -0
- package/dist/commands/getting-started.js +135 -0
- package/dist/commands/housekeeping.d.ts +3 -0
- package/dist/commands/housekeeping.js +203 -0
- package/dist/commands/modeling.d.ts +3 -0
- package/dist/commands/modeling.js +433 -0
- package/dist/commands/planning.d.ts +3 -0
- package/dist/commands/planning.js +212 -0
- package/dist/commands/reviewing.d.ts +3 -0
- package/dist/commands/reviewing.js +177 -0
- package/dist/commands/skills.d.ts +3 -0
- package/dist/commands/skills.js +52 -0
- package/dist/commands.d.ts +10 -22
- package/dist/commands.js +15 -622
- package/dist/diff.d.ts +85 -0
- package/dist/diff.js +323 -0
- package/dist/export.d.ts +1 -1
- package/dist/export.js +1 -1
- package/dist/families.d.ts +1 -1
- package/dist/families.js +1 -1
- package/dist/help.d.ts +11 -2
- package/dist/help.js +51 -57
- package/dist/kbdocs.d.ts +18 -0
- package/dist/kbdocs.js +393 -0
- package/dist/metakb.d.ts +1 -1
- package/dist/metakb.js +1 -1
- package/dist/naming.d.ts +2 -2
- package/dist/naming.js +2 -2
- package/dist/ontology-ref.d.ts +20 -0
- package/dist/ontology-ref.js +108 -0
- package/dist/ops/admin.d.ts +1 -1
- package/dist/ops/admin.js +24 -7
- package/dist/ops/classes.d.ts +1 -1
- package/dist/ops/classes.js +13 -5
- package/dist/ops/instances.d.ts +2 -1
- package/dist/ops/instances.js +7 -1
- package/dist/ops/links.d.ts +1 -1
- package/dist/ops/links.js +1 -1
- package/dist/ops/naming.d.ts +1 -1
- package/dist/ops/naming.js +3 -1
- package/dist/ops/scope.d.ts +5 -1
- package/dist/ops/scope.js +19 -1
- package/dist/ops/slots.d.ts +1 -1
- package/dist/ops/slots.js +15 -2
- package/dist/ops/values.d.ts +1 -1
- package/dist/ops/values.js +5 -1
- package/dist/provenance.d.ts +4 -2
- package/dist/provenance.js +58 -17
- package/dist/release.d.ts +52 -0
- package/dist/release.js +337 -0
- package/dist/render.d.ts +64 -1
- package/dist/render.js +240 -3
- package/dist/resync.d.ts +98 -0
- package/dist/resync.js +234 -0
- package/dist/review.d.ts +1 -1
- package/dist/review.js +1 -1
- package/dist/reviewdocs.d.ts +42 -0
- package/dist/reviewdocs.js +263 -0
- package/dist/runner.d.ts +3 -0
- package/dist/runner.js +79 -0
- package/dist/skills.js +1 -1
- package/dist/status.d.ts +1 -1
- package/dist/status.js +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.js +1 -1
- package/dist/verifynote.d.ts +18 -0
- package/dist/verifynote.js +92 -0
- package/dist/workflows.d.ts +256 -0
- package/dist/workflows.js +223 -0
- package/meta-kb/data/manifest.json +2 -2
- package/meta-kb/data/nodes.json +8 -8
- package/package.json +9 -4
- package/schema/edge.schema.json +68 -0
- package/schema/edges.schema.json +9 -0
- package/schema/node.schema.json +893 -0
- package/schema/nodes.schema.json +9 -0
- package/schema/okb.schema.json +41 -0
- package/skills/build-domain-kb-from-docs/SKILL.md +20 -2
- package/skills/ontology-coach/SKILL.md +6 -2
- package/skills/ontology-maintainer/SKILL.md +152 -0
- package/skills/ontology-review/SKILL.md +3 -1
- package/skills/ontology-signoff/SKILL.md +182 -0
- package/templates/okb-check.yml +132 -0
- package/templates/pull_request_template.md +16 -0
package/dist/kbdocs.js
ADDED
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `okb docs`: reference pages for a domain ontology, so people can read its structure and rules
|
|
3
|
+
* without the CLI. `kbDocs` is a pure function from a loaded `Ontology` to a map of file name to
|
|
4
|
+
* Markdown (no disk, no clock), so the same ontology always gives the same pages and they can be
|
|
5
|
+
* committed and checked for drift. `writeKbDocs` writes them.
|
|
6
|
+
*
|
|
7
|
+
* Layout: `index.md` (scope, questions, class tree, decisions), `classes/<anchor>.md` (one per
|
|
8
|
+
* class), `rules.md`, `sources.md`. Every item gets an `<a id>` from its node id with `.` replaced
|
|
9
|
+
* by `-` (`rule.breve-uses` → `rule-breve-uses`), the scheme gendocs.ts uses for the meta-KB docs.
|
|
10
|
+
* Links are relative, so they work on GitHub and in a content collection that keeps the folder.
|
|
11
|
+
*/
|
|
12
|
+
import { mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
13
|
+
import { dirname, join } from "node:path";
|
|
14
|
+
import { OkbError, nameOrText } from "@ontology-kit/reader";
|
|
15
|
+
import { anchorId } from "./site.js";
|
|
16
|
+
export const BANNER = "<!-- Generated by okb docs. Do not edit: change the knowledge base and run okb docs again. -->";
|
|
17
|
+
const byText = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|
|
18
|
+
const byName = (a, b) => byText((nameOrText(a) ?? a.id).toLowerCase(), (nameOrText(b) ?? b.id).toLowerCase()) || byText(a.id, b.id);
|
|
19
|
+
const anchor = (id) => `<a id="${anchorId(id)}"></a>`;
|
|
20
|
+
const cell = (s) => s.replace(/\|/g, "\\|").replace(/\s*\n\s*/g, " ");
|
|
21
|
+
const oneLine = (s) => s.replace(/\s*\n\s*/g, " ").trim();
|
|
22
|
+
const plural = (n, w) => `${n} ${w}${n === 1 ? "" : "s"}`;
|
|
23
|
+
/** Where a page lives, relative to the docs root. */
|
|
24
|
+
const classFile = (id) => `classes/${anchorId(id)}.md`;
|
|
25
|
+
const HERE = { index: "", class: "../", rules: "", sources: "" };
|
|
26
|
+
class Links {
|
|
27
|
+
ont;
|
|
28
|
+
page;
|
|
29
|
+
root;
|
|
30
|
+
constructor(ont, page) {
|
|
31
|
+
this.ont = ont;
|
|
32
|
+
this.page = page;
|
|
33
|
+
this.root = HERE[page];
|
|
34
|
+
}
|
|
35
|
+
index = () => `${this.root}index.md`;
|
|
36
|
+
rules = (id) => `${this.root}rules.md${id ? `#${anchorId(id)}` : ""}`;
|
|
37
|
+
sources = (id) => `${this.root}sources.md${id ? `#${anchorId(id)}` : ""}`;
|
|
38
|
+
/** A class page, from this page: siblings in classes/ link without the folder. */
|
|
39
|
+
cls = (id) => (this.page === "class" ? `${anchorId(id)}.md` : classFile(id));
|
|
40
|
+
/** A link to a node's page, or its plain name when it has none. */
|
|
41
|
+
node(id) {
|
|
42
|
+
const n = this.ont.get(id);
|
|
43
|
+
if (!n)
|
|
44
|
+
return `\`${id}\``;
|
|
45
|
+
const name = nameOrText(n) ?? id;
|
|
46
|
+
if (n.type === "Class")
|
|
47
|
+
return `[${name}](${this.cls(id)})`;
|
|
48
|
+
if (n.type === "Instance") {
|
|
49
|
+
const home = [...this.ont.targets(id, "INSTANCE_OF")].sort(byText)[0];
|
|
50
|
+
return home && this.ont.get(home)?.type === "Class" ? `[${name}](${this.cls(home)}#${anchorId(id)})` : name;
|
|
51
|
+
}
|
|
52
|
+
if (n.type === "Rule")
|
|
53
|
+
return `[${name}](${this.rules(id)})`;
|
|
54
|
+
return name;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const slotName = (ont, id) => nameOrText(ont.require(id)) ?? id;
|
|
58
|
+
function valueText(ont, l, v) {
|
|
59
|
+
if (typeof v === "string" && ont.get(v))
|
|
60
|
+
return l.node(v);
|
|
61
|
+
return String(v);
|
|
62
|
+
}
|
|
63
|
+
function listValues(ont, l, vs) {
|
|
64
|
+
return vs.map((v) => valueText(ont, l, v)).join(", ");
|
|
65
|
+
}
|
|
66
|
+
/** The quote behind a rule or other node, as links to the sources page (and the source's own link when it has one). */
|
|
67
|
+
function quoteLines(ont, l, nodeId) {
|
|
68
|
+
const locs = ont.targets(nodeId, "CITES").map((id) => ont.get(id)).filter((n) => n?.type === "SourceLocation");
|
|
69
|
+
if (!locs.length)
|
|
70
|
+
return ["- Source: none cited."];
|
|
71
|
+
return locs.flatMap((loc) => {
|
|
72
|
+
const where = loc.locator ?? loc.id;
|
|
73
|
+
const ext = loc.sourceLink ?? loc.pageLink;
|
|
74
|
+
return [`- Source: [${where}${loc.lines ? `, line ${loc.lines}` : loc.page !== undefined ? `, page ${loc.page}` : ""}](${l.sources(loc.id)})${ext ? ` ([original](${ext}))` : ""}`, ` > ${oneLine(loc.quote)}`];
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function ruleBlock(ont, l, rule, level, opts = {}) {
|
|
78
|
+
const out = [anchor(rule.id), `${"#".repeat(level)} ${rule.name}`, "", `**${rule.modality.replace("_", " ")}.** ${rule.statement}`, ""];
|
|
79
|
+
const bullets = [];
|
|
80
|
+
const governs = ont.targets(rule.id, "GOVERNS");
|
|
81
|
+
if (opts.governs && governs.length)
|
|
82
|
+
bullets.push(`- Governs: ${governs.map((g) => l.node(g)).join(", ")}`);
|
|
83
|
+
const v = rule.verification?.status;
|
|
84
|
+
bullets.push(`- Verification: ${v ? v.toLowerCase() : "not verified"}${rule.authored ? " (written by the owner)" : ""}`);
|
|
85
|
+
for (const [slotId, val] of Object.entries(rule.values ?? {}))
|
|
86
|
+
bullets.push(`- ${slotName(ont, slotId)}: ${[val].flat().join(", ")}`);
|
|
87
|
+
const refines = ont.targets(rule.id, "REFINES");
|
|
88
|
+
if (refines.length)
|
|
89
|
+
bullets.push(`- Refines: ${refines.map((r) => l.node(r)).join(", ")}`);
|
|
90
|
+
bullets.push(...quoteLines(ont, l, rule.id));
|
|
91
|
+
return [...out, ...bullets, ""];
|
|
92
|
+
}
|
|
93
|
+
function rulesGoverning(ont, classId) {
|
|
94
|
+
return ont.ofType("Rule").filter((r) => ont.targets(r.id, "GOVERNS").includes(classId));
|
|
95
|
+
}
|
|
96
|
+
function decisionsAbout(ont, id) {
|
|
97
|
+
return ont.ofType("DesignDecision").filter((d) => ont.targets(d.id, "ABOUT").includes(id)).sort(byName);
|
|
98
|
+
}
|
|
99
|
+
function decisionBlock(d, level) {
|
|
100
|
+
const out = [anchor(d.id), `${"#".repeat(level)} ${d.title}`, "", `**Decision.** ${d.decision}`, ""];
|
|
101
|
+
if (d.question)
|
|
102
|
+
out.push(`**Question.** ${d.question}`, "");
|
|
103
|
+
if (d.rationale)
|
|
104
|
+
out.push(`**Why.** ${d.rationale}`, "");
|
|
105
|
+
if (d.alternatives?.length)
|
|
106
|
+
out.push(`**Alternatives considered.** ${d.alternatives.join("; ")}`, "");
|
|
107
|
+
if (d.metaRules?.length)
|
|
108
|
+
out.push(`**Explains the rules:** ${d.metaRules.map((r) => `\`${r}\``).join(", ")}`, "");
|
|
109
|
+
out.push(`Date: ${d.date}`, "");
|
|
110
|
+
return out;
|
|
111
|
+
}
|
|
112
|
+
function classTree(ont, l, ids, seen, depth = 0) {
|
|
113
|
+
const out = [];
|
|
114
|
+
for (const id of ids.map((i) => ont.require(i, "Class")).sort(byName).map((c) => c.id)) {
|
|
115
|
+
const again = seen.has(id);
|
|
116
|
+
out.push(`${" ".repeat(depth)}- ${l.node(id)}${again ? " (see above)" : ""}`);
|
|
117
|
+
if (again)
|
|
118
|
+
continue;
|
|
119
|
+
seen.add(id);
|
|
120
|
+
out.push(...classTree(ont, l, ont.children(id), seen, depth + 1));
|
|
121
|
+
}
|
|
122
|
+
return out;
|
|
123
|
+
}
|
|
124
|
+
function indexPage(ont) {
|
|
125
|
+
const l = new Links(ont, "index");
|
|
126
|
+
const m = ont.meta;
|
|
127
|
+
const out = [BANNER, "", `# ${m.name}`, ""];
|
|
128
|
+
if (m.purpose)
|
|
129
|
+
out.push(m.purpose, "");
|
|
130
|
+
out.push("## Scope", "");
|
|
131
|
+
const row = (k, v) => {
|
|
132
|
+
const text = Array.isArray(v) ? v.join(", ") : v;
|
|
133
|
+
if (text)
|
|
134
|
+
out.push(`- **${k}:** ${text}`);
|
|
135
|
+
};
|
|
136
|
+
row("Domain", m.domain);
|
|
137
|
+
row("Users", m.users);
|
|
138
|
+
row("Maintainers", m.maintainers);
|
|
139
|
+
row("Out of scope", m.outOfScope);
|
|
140
|
+
row("Kind", m.kind);
|
|
141
|
+
if (ont.manifest.version)
|
|
142
|
+
row("Version", ont.manifest.version);
|
|
143
|
+
out.push("");
|
|
144
|
+
const cqs = ont.numbered("CompetencyQuestion");
|
|
145
|
+
if (cqs.length) {
|
|
146
|
+
out.push("## Competency questions", "");
|
|
147
|
+
cqs.forEach((q, i) => out.push(`${i + 1}. ${nameOrText(q)}`));
|
|
148
|
+
out.push("");
|
|
149
|
+
}
|
|
150
|
+
const rules = ont.ofType("Rule").length;
|
|
151
|
+
const sources = ont.ofType("Source").length;
|
|
152
|
+
out.push("## Classes", "");
|
|
153
|
+
const seen = new Set();
|
|
154
|
+
out.push(...classTree(ont, l, ont.roots(), seen));
|
|
155
|
+
const orphans = ont.ofType("Class").filter((c) => !seen.has(c.id)).map((c) => c.id);
|
|
156
|
+
if (orphans.length)
|
|
157
|
+
out.push(...classTree(ont, l, orphans, seen));
|
|
158
|
+
if (!ont.ofType("Class").length)
|
|
159
|
+
out.push("No classes yet.");
|
|
160
|
+
out.push("");
|
|
161
|
+
const decisions = ont.numbered("DesignDecision");
|
|
162
|
+
if (decisions.length) {
|
|
163
|
+
out.push("## Design decisions", "");
|
|
164
|
+
for (const d of decisions) {
|
|
165
|
+
const about = ont.targets(d.id, "ABOUT").filter((a) => ont.get(a)?.type === "Class");
|
|
166
|
+
out.push(`- ${d.title}: ${d.decision}${about.length ? ` (about ${about.map((a) => l.node(a)).join(", ")})` : ""}`);
|
|
167
|
+
}
|
|
168
|
+
out.push("");
|
|
169
|
+
}
|
|
170
|
+
out.push("## More", "", `- [Rules](rules.md): ${plural(rules, "rule")}`, `- [Sources](sources.md): ${plural(sources, "source")}`, "");
|
|
171
|
+
return out.join("\n");
|
|
172
|
+
}
|
|
173
|
+
function classPage(ont, c) {
|
|
174
|
+
const l = new Links(ont, "class");
|
|
175
|
+
const out = [BANNER, "", anchor(c.id), `# ${c.name}`, ""];
|
|
176
|
+
out.push(`[Index](${l.index()}) · [Rules](${l.rules()}) · [Sources](${l.sources()})`, "");
|
|
177
|
+
if (c.description)
|
|
178
|
+
out.push(c.description, "");
|
|
179
|
+
const bullets = [];
|
|
180
|
+
if (c.synonyms?.length)
|
|
181
|
+
bullets.push(`- Also called: ${c.synonyms.join(", ")}`);
|
|
182
|
+
if (c.formerNames?.length)
|
|
183
|
+
bullets.push(`- Formerly: ${c.formerNames.join(", ")}`);
|
|
184
|
+
if (c.abstract)
|
|
185
|
+
bullets.push("- Abstract: it has no members of its own, only its subclasses do.");
|
|
186
|
+
const parents = ont.parents(c.id).sort(byText);
|
|
187
|
+
if (parents.length)
|
|
188
|
+
bullets.push(`- Is a: ${parents.map((p) => l.node(p)).join(", ")}`);
|
|
189
|
+
const kids = ont.children(c.id).sort(byText);
|
|
190
|
+
if (kids.length)
|
|
191
|
+
bullets.push(`- Subclasses: ${kids.map((k) => l.node(k)).join(", ")}`);
|
|
192
|
+
const disjoint = [...ont.targets(c.id, "DISJOINT_WITH"), ...ont.sources(c.id, "DISJOINT_WITH")].sort(byText);
|
|
193
|
+
if (disjoint.length)
|
|
194
|
+
bullets.push(`- Disjoint with: ${disjoint.map((d) => l.node(d)).join(", ")}`);
|
|
195
|
+
if (bullets.length)
|
|
196
|
+
out.push(...bullets, "");
|
|
197
|
+
// Slots: own first, then inherited from the nearest ancestors.
|
|
198
|
+
const nearest = [...ont.ancestors(c.id)]; // nearest first: it decides which class's value applies
|
|
199
|
+
const ancestors = [...nearest].sort(byText);
|
|
200
|
+
const context = [c.id, ...nearest];
|
|
201
|
+
const slotIds = ont.applicableSlots(c.id);
|
|
202
|
+
if (slotIds.length) {
|
|
203
|
+
out.push("## Slots", "", "| Slot | Kind | From | Type | Allowed values | Count | Class value |", "| --- | --- | --- | --- | --- | --- | --- |");
|
|
204
|
+
const rows = slotIds.map((sid) => ({ sid, s: ont.require(sid, "Slot") })).sort((a, b) => Number(ont.ownSlots(c.id).includes(b.sid)) - Number(ont.ownSlots(c.id).includes(a.sid)) || byName(a.s, b.s));
|
|
205
|
+
for (const { sid, s } of rows) {
|
|
206
|
+
const own = ont.ownSlots(c.id).includes(sid);
|
|
207
|
+
const from = own ? "own" : "inherited from " + ont.domain(sid).filter((d) => ancestors.includes(d)).sort(byText).map((d) => l.node(d)).join(", ");
|
|
208
|
+
const f = ont.effectiveFacets(sid, context);
|
|
209
|
+
const rel = f.valueType === "Instance";
|
|
210
|
+
const type = rel ? `link to ${f.range.length ? f.range.map((r) => l.node(r)).join(" or ") : "anything"}` : (f.valueType ?? "unset");
|
|
211
|
+
const count = `${f.min}..${f.max ?? "*"}`;
|
|
212
|
+
const note = f.overriddenBy.length ? ` (narrowed by ${f.overriddenBy.map((o) => l.node(o)).join(", ")})` : "";
|
|
213
|
+
const fixed = ont.statedValues(c.id, sid);
|
|
214
|
+
const inheritedFixed = fixed.length ? null : ont.inheritedFixed(sid, ancestors);
|
|
215
|
+
const classValue = fixed.length ? listValues(ont, l, fixed) : inheritedFixed ? `${listValues(ont, l, inheritedFixed.values)} (from ${l.node(inheritedFixed.cls)})` : "";
|
|
216
|
+
out.push(`| ${cell(`${anchor(`${c.id}.${sid}`)}${s.name}`)} | ${rel ? "relationship" : "property"} | ${cell(from)} | ${cell(type)} | ${cell(f.allowedValues ? f.allowedValues.join(", ") + note : note.trim())} | ${count} | ${cell(classValue)} |`);
|
|
217
|
+
}
|
|
218
|
+
out.push("");
|
|
219
|
+
const described = rows.filter(({ s }) => s.description);
|
|
220
|
+
if (described.length) {
|
|
221
|
+
for (const { s } of described)
|
|
222
|
+
out.push(`- **${s.name}:** ${s.description}`);
|
|
223
|
+
out.push("");
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
// Rules: this class's own, then those inherited from ancestors.
|
|
227
|
+
const own = rulesGoverning(ont, c.id).sort(byName);
|
|
228
|
+
const inherited = ancestors.flatMap((a) => rulesGoverning(ont, a).map((r) => ({ r, a }))).sort((x, y) => byName(x.r, y.r));
|
|
229
|
+
if (own.length || inherited.length) {
|
|
230
|
+
out.push("## Rules", "");
|
|
231
|
+
for (const r of own)
|
|
232
|
+
out.push(...ruleSummary(ont, l, r));
|
|
233
|
+
for (const { r, a } of inherited)
|
|
234
|
+
out.push(...ruleSummary(ont, l, r, a));
|
|
235
|
+
}
|
|
236
|
+
const members = ont.ofType("Instance").filter((i) => ont.targets(i.id, "INSTANCE_OF").includes(c.id)).sort(byName);
|
|
237
|
+
if (members.length) {
|
|
238
|
+
out.push("## Instances", "");
|
|
239
|
+
for (const i of members) {
|
|
240
|
+
const parts = [];
|
|
241
|
+
for (const sid of ont.applicableSlots(i.id)) {
|
|
242
|
+
const vals = ont.statedValues(i.id, sid);
|
|
243
|
+
if (vals.length)
|
|
244
|
+
parts.push(`${slotName(ont, sid)}: ${listValues(ont, l, vals)}`);
|
|
245
|
+
}
|
|
246
|
+
out.push(`- ${anchor(i.id)}**${i.name}**${i.description ? `. ${i.description}` : ""}${parts.length ? ` (${parts.join("; ")})` : ""}`);
|
|
247
|
+
}
|
|
248
|
+
out.push("");
|
|
249
|
+
}
|
|
250
|
+
const decisions = decisionsAbout(ont, c.id);
|
|
251
|
+
if (decisions.length) {
|
|
252
|
+
out.push("## Decisions", "");
|
|
253
|
+
for (const d of decisions)
|
|
254
|
+
out.push(...decisionBlock(d, 3));
|
|
255
|
+
}
|
|
256
|
+
return out.join("\n").replace(/\n{3,}/g, "\n\n").trimEnd() + "\n";
|
|
257
|
+
}
|
|
258
|
+
/** A rule on a class page: modality, statement and the link to its quote. */
|
|
259
|
+
function ruleSummary(ont, l, rule, from) {
|
|
260
|
+
const loc = ont.targets(rule.id, "CITES").map((id) => ont.get(id)).find((n) => n?.type === "SourceLocation");
|
|
261
|
+
const quote = loc ? ` Source: [${loc.locator ?? loc.id}${loc.lines ? `, line ${loc.lines}` : ""}](${l.sources(loc.id)}).` : " Source: none cited.";
|
|
262
|
+
return [`- [${rule.name}](${l.rules(rule.id)}) (${from ? `inherited from ${l.node(from)}, ` : ""}${rule.modality.replace("_", " ")}): ${rule.statement}${quote}`, ...(loc ? [` > ${oneLine(loc.quote)}`] : []), ""];
|
|
263
|
+
}
|
|
264
|
+
function rulesPage(ont) {
|
|
265
|
+
const l = new Links(ont, "rules");
|
|
266
|
+
const rules = ont.ofType("Rule").sort(byName);
|
|
267
|
+
const out = [BANNER, "", "# Rules", "", `[Index](index.md) · [Sources](sources.md)`, ""];
|
|
268
|
+
if (!rules.length)
|
|
269
|
+
return [...out, "This knowledge base has no rules yet.", ""].join("\n");
|
|
270
|
+
out.push(`${plural(rules.length, "rule")}. Each one links to the quote it rests on.`, "");
|
|
271
|
+
for (const r of rules)
|
|
272
|
+
out.push(...ruleBlock(ont, l, r, 2, { governs: true }));
|
|
273
|
+
return out.join("\n").trimEnd() + "\n";
|
|
274
|
+
}
|
|
275
|
+
function sourcesPage(ont) {
|
|
276
|
+
const l = new Links(ont, "sources");
|
|
277
|
+
const out = [BANNER, "", "# Sources", "", `[Index](index.md) · [Rules](rules.md)`, ""];
|
|
278
|
+
const sources = ont.ofType("Source").sort(byName);
|
|
279
|
+
if (!sources.length)
|
|
280
|
+
return [...out, "This knowledge base has no registered sources yet.", ""].join("\n");
|
|
281
|
+
const locsOf = (s) => ont.sources(s.id, "PART_OF").map((id) => ont.get(id)).filter((n) => n?.type === "SourceLocation")
|
|
282
|
+
.sort((a, b) => (a.startLine ?? Infinity) - (b.startLine ?? Infinity) || byText(a.id, b.id));
|
|
283
|
+
for (const s of sources) {
|
|
284
|
+
out.push(anchor(s.id), `## ${s.title}`, "");
|
|
285
|
+
const meta = [];
|
|
286
|
+
if (s.localPath)
|
|
287
|
+
meta.push(`- File: \`${s.localPath}\``);
|
|
288
|
+
if (s.format)
|
|
289
|
+
meta.push(`- Format: ${s.format}`);
|
|
290
|
+
if (s.url)
|
|
291
|
+
meta.push(`- URL: <${s.url}>`);
|
|
292
|
+
if (s.repoUrl)
|
|
293
|
+
meta.push(`- Repository: <${s.repoUrl}>`);
|
|
294
|
+
if (meta.length)
|
|
295
|
+
out.push(...meta, "");
|
|
296
|
+
for (const loc of locsOf(s)) {
|
|
297
|
+
out.push(anchor(loc.id), `### ${loc.locator ?? loc.id}`, "");
|
|
298
|
+
const ext = loc.sourceLink ?? loc.pageLink;
|
|
299
|
+
out.push(`> ${oneLine(loc.quote)}`, "");
|
|
300
|
+
const facts = [loc.lines ? `line ${loc.lines}` : null, loc.page !== undefined ? `page ${loc.page}` : null, loc.blockKind ?? null].filter(Boolean).join(", ");
|
|
301
|
+
if (facts || ext)
|
|
302
|
+
out.push(`${facts}${ext ? `${facts ? " · " : ""}[original](${ext})` : ""}`, "");
|
|
303
|
+
const citing = ont.sources(loc.id, "CITES").map((id) => ont.require(id)).sort(byName);
|
|
304
|
+
if (citing.length)
|
|
305
|
+
out.push(`Cited by: ${citing.map((n) => (n.type === "Rule" ? `rule ${l.node(n.id)}` : `${n.type.toLowerCase()} ${l.node(n.id)}`)).join(", ")}`, "");
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
// Quotes whose source is missing from the file still need a landing place for rule links.
|
|
309
|
+
const loose = ont.ofType("SourceLocation").filter((loc) => !ont.targets(loc.id, "PART_OF").some((id) => ont.get(id)?.type === "Source"));
|
|
310
|
+
if (loose.length) {
|
|
311
|
+
out.push("## Quotes without a source", "");
|
|
312
|
+
for (const loc of loose.sort(byName))
|
|
313
|
+
out.push(anchor(loc.id), `### ${loc.locator ?? loc.id}`, "", `> ${oneLine(loc.quote)}`, "");
|
|
314
|
+
}
|
|
315
|
+
return out.join("\n").trimEnd() + "\n";
|
|
316
|
+
}
|
|
317
|
+
/** Every page for the ontology: file name (relative to the docs folder) → Markdown. */
|
|
318
|
+
export function kbDocs(ont) {
|
|
319
|
+
const files = {
|
|
320
|
+
"index.md": indexPage(ont),
|
|
321
|
+
"rules.md": rulesPage(ont),
|
|
322
|
+
"sources.md": sourcesPage(ont),
|
|
323
|
+
};
|
|
324
|
+
for (const c of ont.ofType("Class"))
|
|
325
|
+
files[classFile(c.id)] = classPage(ont, c);
|
|
326
|
+
return files;
|
|
327
|
+
}
|
|
328
|
+
/** Write the pages into `dir`, removing pages an earlier run wrote (they carry the banner) that no longer exist. Other files stay. Returns the file names. */
|
|
329
|
+
export function writeKbDocs(ont, dir) {
|
|
330
|
+
const files = kbDocs(ont);
|
|
331
|
+
return replacePages(dir, files, (old) => !(old in files));
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Write pages into `dir` (creating folders) and leave every other file alone. A page never replaces a file
|
|
335
|
+
* okb didn't write (no banner): that file is named in the error and nothing is written. Returns the file names.
|
|
336
|
+
*/
|
|
337
|
+
export function writePages(dir, files) {
|
|
338
|
+
return replacePages(dir, files, () => false);
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Check that no page would replace a file okb didn't write, then remove the earlier pages (banner) that `drop`
|
|
342
|
+
* picks, then write. The check comes first, so a refused run removes nothing.
|
|
343
|
+
*/
|
|
344
|
+
function replacePages(dir, files, drop) {
|
|
345
|
+
const yours = Object.keys(files).filter((name) => {
|
|
346
|
+
try {
|
|
347
|
+
return !readFileSync(join(dir, name), "utf8").startsWith(BANNER);
|
|
348
|
+
}
|
|
349
|
+
catch {
|
|
350
|
+
return false; // not there yet
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
if (yours.length) {
|
|
354
|
+
throw new OkbError(`${dir} already has ${yours.join(", ")}, and okb didn't write ${yours.length === 1 ? "it" : "them"}, so okb docs won't replace ${yours.length === 1 ? "it" : "them"}. Write the pages to an empty or new folder (--out <folder>).`);
|
|
355
|
+
}
|
|
356
|
+
for (const old of listMarkdown(dir))
|
|
357
|
+
if (!(old in files) && drop(old) && readFileSync(join(dir, old), "utf8").startsWith(BANNER))
|
|
358
|
+
rmSync(join(dir, old));
|
|
359
|
+
for (const [name, text] of Object.entries(files)) {
|
|
360
|
+
mkdirSync(dirname(join(dir, name)), { recursive: true });
|
|
361
|
+
writeFileSync(join(dir, name), text);
|
|
362
|
+
}
|
|
363
|
+
return Object.keys(files).sort();
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Write a changed-only view into `dir`, removing pages an earlier run wrote there (they carry the banner)
|
|
367
|
+
* that this view doesn't include, so a folder reused for a second `--changed` doesn't keep the first one's pages.
|
|
368
|
+
* `rules-in-context.md` is a separate view of the same folder and stays.
|
|
369
|
+
*/
|
|
370
|
+
export function writeChangedPages(dir, files) {
|
|
371
|
+
return replacePages(dir, files, (old) => old !== "rules-in-context.md");
|
|
372
|
+
}
|
|
373
|
+
function listMarkdown(dir) {
|
|
374
|
+
const out = [];
|
|
375
|
+
const walk = (rel) => {
|
|
376
|
+
let entries;
|
|
377
|
+
try {
|
|
378
|
+
entries = readdirSync(join(dir, rel), { withFileTypes: true });
|
|
379
|
+
}
|
|
380
|
+
catch {
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
for (const e of entries) {
|
|
384
|
+
const p = rel ? `${rel}/${e.name}` : e.name;
|
|
385
|
+
if (e.isDirectory())
|
|
386
|
+
walk(p);
|
|
387
|
+
else if (e.name.endsWith(".md"))
|
|
388
|
+
out.push(p);
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
walk("");
|
|
392
|
+
return out;
|
|
393
|
+
}
|
package/dist/metakb.d.ts
CHANGED
package/dist/metakb.js
CHANGED
|
@@ -3,7 +3,7 @@ import { readFileSync } from "node:fs";
|
|
|
3
3
|
import { dirname, join } from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import * as naming from "./naming.js";
|
|
6
|
-
import {} from "@ontology-kit/
|
|
6
|
+
import {} from "@ontology-kit/reader";
|
|
7
7
|
import {} from "./types.js";
|
|
8
8
|
export const META_DIR = join(dirname(dirname(fileURLToPath(import.meta.url))), "meta-kb", "data");
|
|
9
9
|
const EXPLAINABLE = new Set(["Concept", "Principle", "Decision", "Step", "Rule"]);
|
package/dist/naming.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Name styles, conversion, and singular/plural guessing. */
|
|
2
|
-
import { type Conventions } from "@ontology-kit/
|
|
3
|
-
export { fold, key, rawTokens, relType, slug, stripAccents, tokens } from "@ontology-kit/
|
|
2
|
+
import { type Conventions } from "@ontology-kit/reader";
|
|
3
|
+
export { fold, key, rawTokens, relType, slug, stripAccents, tokens } from "@ontology-kit/reader";
|
|
4
4
|
export declare const CLASS_STYLES: string[];
|
|
5
5
|
export declare const SLOT_STYLES: string[];
|
|
6
6
|
export declare const DEFAULT_CONVENTIONS: Conventions;
|
package/dist/naming.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Name styles, conversion, and singular/plural guessing. */
|
|
2
|
-
import { rawTokens, stripAccents, tokens } from "@ontology-kit/
|
|
3
|
-
export { fold, key, rawTokens, relType, slug, stripAccents, tokens } from "@ontology-kit/
|
|
2
|
+
import { rawTokens, stripAccents, tokens } from "@ontology-kit/reader";
|
|
3
|
+
export { fold, key, rawTokens, relType, slug, stripAccents, tokens } from "@ontology-kit/reader";
|
|
4
4
|
export const CLASS_STYLES = ["PascalCase", "Title Case", "snake_case", "kebab-case", "Sentence case"];
|
|
5
5
|
export const SLOT_STYLES = ["camelCase", "snake_case", "kebab-case", "lower case"];
|
|
6
6
|
export const DEFAULT_CONVENTIONS = {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Ontology } from "@ontology-kit/reader";
|
|
2
|
+
/** Where the working ontology sits inside its git repository, and the repository's top folder. */
|
|
3
|
+
export declare function locateInRepo(folder: string): {
|
|
4
|
+
top: string;
|
|
5
|
+
path: string;
|
|
6
|
+
};
|
|
7
|
+
/** Load the ontology as it was at `ref`. `where` is from `locateInRepo`. */
|
|
8
|
+
export declare function loadAtRef(ref: string, where: {
|
|
9
|
+
top: string;
|
|
10
|
+
path: string;
|
|
11
|
+
}): Ontology;
|
|
12
|
+
/**
|
|
13
|
+
* Resolve one side of `okb diff`: an existing folder is read as it is; anything else is a git ref,
|
|
14
|
+
* looked up in the repository around `context` (the working ontology folder). A name that is both
|
|
15
|
+
* (like `git diff`'s "both revision and filename") is an error that gives both spellings.
|
|
16
|
+
*/
|
|
17
|
+
export declare function loadSide(arg: string, context: string): {
|
|
18
|
+
ont: Ontology;
|
|
19
|
+
name: string;
|
|
20
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Load an ontology from a folder or from a git ref (`main`, `HEAD~3`, a tag, a sha) without touching
|
|
3
|
+
* the working tree: the ref's okb files are read with `git show` into a temp folder, loaded, and deleted.
|
|
4
|
+
* Read-only: it never takes the write lock.
|
|
5
|
+
*/
|
|
6
|
+
import { execFileSync } from "node:child_process";
|
|
7
|
+
import { existsSync, mkdtempSync, mkdirSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { tmpdir } from "node:os";
|
|
9
|
+
import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
10
|
+
import { OkbError, Ontology, findRoot, MANIFEST } from "@ontology-kit/reader";
|
|
11
|
+
const FILES = [MANIFEST, "nodes.jsonl", "edges.jsonl", "nodes.json", "edges.json"];
|
|
12
|
+
function git(cwd, args) {
|
|
13
|
+
try {
|
|
14
|
+
return execFileSync("git", args, { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], maxBuffer: 1 << 30 });
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
const err = e;
|
|
18
|
+
if (err.code === "ENOENT")
|
|
19
|
+
throw new OkbError("okb diff with a git ref needs git, and it isn't installed.");
|
|
20
|
+
throw new OkbError(`git ${args[0]} failed: ${(err.stderr ?? String(e)).trim()}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/** Where the working ontology sits inside its git repository, and the repository's top folder. */
|
|
24
|
+
export function locateInRepo(folder) {
|
|
25
|
+
const root = findRoot(folder);
|
|
26
|
+
if (!root)
|
|
27
|
+
throw new OkbError(`No ontology found in ${resolve(folder)} or its parents, so there is nothing to read from a git ref. Run okb diff from an ontology folder, or pass -C <folder>.`);
|
|
28
|
+
let top;
|
|
29
|
+
try {
|
|
30
|
+
top = git(root, ["rev-parse", "--show-toplevel"]).trim();
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
throw new OkbError(`${root} isn't inside a git repository, so '${folder}' can't be read as a git ref. Give two folders instead.`);
|
|
34
|
+
}
|
|
35
|
+
// realpath-safe: compare through git's own view of the folder
|
|
36
|
+
const prefix = git(root, ["rev-parse", "--show-prefix"]).trim().replace(/\/$/, "");
|
|
37
|
+
return { top, path: prefix || relative(top, root) || "." };
|
|
38
|
+
}
|
|
39
|
+
/** Load the ontology as it was at `ref`. `where` is from `locateInRepo`. */
|
|
40
|
+
export function loadAtRef(ref, where) {
|
|
41
|
+
if (ref.startsWith("-"))
|
|
42
|
+
throw new OkbError(`'${ref}' isn't a folder or a git ref.`);
|
|
43
|
+
try {
|
|
44
|
+
git(where.top, ["rev-parse", "--verify", "--quiet", `${ref}^{commit}`]);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
throw new OkbError(`'${ref}' isn't a folder or a git ref in ${where.top}.`);
|
|
48
|
+
}
|
|
49
|
+
const at = where.path === "." ? "" : where.path + "/";
|
|
50
|
+
const tmp = mkdtempSync(join(tmpdir(), "okb-diff-"));
|
|
51
|
+
try {
|
|
52
|
+
let found = false;
|
|
53
|
+
for (const f of FILES) {
|
|
54
|
+
const spec = `${ref}:${at}${f}`;
|
|
55
|
+
try {
|
|
56
|
+
git(where.top, ["cat-file", "-e", spec]);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const body = execFileSync("git", ["show", spec], { cwd: where.top, maxBuffer: 1 << 30, stdio: ["ignore", "pipe", "pipe"] });
|
|
62
|
+
mkdirSync(dirname(join(tmp, f)), { recursive: true });
|
|
63
|
+
writeFileSync(join(tmp, f), body);
|
|
64
|
+
if (f === MANIFEST)
|
|
65
|
+
found = true;
|
|
66
|
+
}
|
|
67
|
+
if (!found)
|
|
68
|
+
throw new OkbError(`There is no ontology at ${ref}:${at || "."} (no ${MANIFEST} there). Check the ref, or pass the folder it was in.`);
|
|
69
|
+
return Ontology.load(tmp);
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
rmSync(tmp, { recursive: true, force: true });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/** The unambiguous spelling of a ref (`refs/heads/main`, `refs/tags/v1`, or the full sha), or null if `name` isn't a ref there. */
|
|
76
|
+
function fullRef(top, name) {
|
|
77
|
+
if (name.startsWith("-"))
|
|
78
|
+
return null;
|
|
79
|
+
try {
|
|
80
|
+
const sha = git(top, ["rev-parse", "--verify", "--quiet", `${name}^{commit}`]).trim();
|
|
81
|
+
return git(top, ["rev-parse", "--symbolic-full-name", name]).trim().split("\n")[0] || sha;
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Resolve one side of `okb diff`: an existing folder is read as it is; anything else is a git ref,
|
|
89
|
+
* looked up in the repository around `context` (the working ontology folder). A name that is both
|
|
90
|
+
* (like `git diff`'s "both revision and filename") is an error that gives both spellings.
|
|
91
|
+
*/
|
|
92
|
+
export function loadSide(arg, context) {
|
|
93
|
+
if (existsSync(arg) && statSync(arg).isDirectory()) {
|
|
94
|
+
let ref = null;
|
|
95
|
+
try {
|
|
96
|
+
ref = fullRef(locateInRepo(context).top, arg);
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
// not in a repository (or no ontology around `context`): it can only be the folder
|
|
100
|
+
}
|
|
101
|
+
if (ref) {
|
|
102
|
+
const folder = isAbsolute(arg) || arg.startsWith("./") || arg.startsWith("../") ? arg : `./${arg}`;
|
|
103
|
+
throw new OkbError(`'${arg}' is both a folder and a git ref. Say which you mean:\n the folder: ${folder}\n the ref: ${ref}`);
|
|
104
|
+
}
|
|
105
|
+
return { ont: Ontology.load(arg), name: arg };
|
|
106
|
+
}
|
|
107
|
+
return { ont: loadAtRef(arg, locateInRepo(context)), name: arg };
|
|
108
|
+
}
|
package/dist/ops/admin.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Ontology, type NodeType } from "@ontology-kit/
|
|
1
|
+
import { Ontology, type NodeType } from "@ontology-kit/reader";
|
|
2
2
|
import type { Notes } from "./common.js";
|
|
3
3
|
/** Start an empty ontology folder: the manifest, the one Ontology node, no edges. Saved before it returns. */
|
|
4
4
|
export declare function createOntology(root: string, name: string): Ontology;
|
package/dist/ops/admin.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/** Creating an ontology, design decisions, renaming and removing. */
|
|
2
|
-
import { existsSync, mkdirSync } from "node:fs";
|
|
2
|
+
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { join, resolve } from "node:path";
|
|
4
4
|
import * as naming from "../naming.js";
|
|
5
5
|
import { runChecks } from "../checks.js";
|
|
6
6
|
import { today } from "../clock.js";
|
|
7
7
|
import { MetaKB } from "../metakb.js";
|
|
8
|
-
import { FORMAT, MANIFEST, OkbError, Ontology, nameOrText } from "@ontology-kit/
|
|
8
|
+
import { FORMAT, MANIFEST, OkbError, Ontology, nameOrText } from "@ontology-kit/reader";
|
|
9
9
|
import { checkName } from "./naming.js";
|
|
10
10
|
/** Start an empty ontology folder: the manifest, the one Ontology node, no edges. Saved before it returns. */
|
|
11
11
|
export function createOntology(root, name) {
|
|
@@ -13,12 +13,16 @@ export function createOntology(root, name) {
|
|
|
13
13
|
if (existsSync(join(root, MANIFEST)))
|
|
14
14
|
throw new OkbError(`${root} already contains an ontology (${MANIFEST}).`);
|
|
15
15
|
const manifest = { format: FORMAT, name, currentStep: 1, created: today() };
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
const ont = new Ontology(resolve(root), manifest, [], []);
|
|
17
|
+
ont.addNode({
|
|
18
|
+
type: "Ontology", id: "ontology", name, domain: "", purpose: "", users: [], maintainers: [],
|
|
19
|
+
outOfScope: [], kind: "application", reuseReviewed: false,
|
|
20
|
+
});
|
|
21
21
|
ont.save();
|
|
22
|
+
// Keep the lock file and half-written temp files out of git (a team keeps the folder in a repository).
|
|
23
|
+
const ignore = join(root, ".gitignore");
|
|
24
|
+
if (!existsSync(ignore))
|
|
25
|
+
writeFileSync(ignore, ".okb.lock\n*.tmp\n");
|
|
22
26
|
return ont;
|
|
23
27
|
}
|
|
24
28
|
export function addDecision(ont, o) {
|
|
@@ -60,14 +64,26 @@ export function rename(ont, ref, next, force = false) {
|
|
|
60
64
|
}
|
|
61
65
|
const old = n.name;
|
|
62
66
|
if (n.type === "Slot" && n.valueType === "Instance") {
|
|
67
|
+
const oldType = n.relType;
|
|
63
68
|
const retyped = ont.rel.rename(n, next);
|
|
64
69
|
if (retyped)
|
|
65
70
|
notes.push(`Its links are now stored as ${retyped.to} (were ${retyped.from}).`);
|
|
71
|
+
if (oldType && n.relType && n.relType !== oldType)
|
|
72
|
+
n.formerRelTypes = remember(n.formerRelTypes, oldType, n.relType);
|
|
66
73
|
}
|
|
74
|
+
if (n.type !== "ReusedOntology" && old !== next)
|
|
75
|
+
n.formerNames = remember(n.formerNames, old, next);
|
|
67
76
|
n.name = next;
|
|
77
|
+
ont.touch(n);
|
|
68
78
|
notes.unshift(`Renamed ${n.type} '${old}' → '${next}' (id ${n.id} unchanged).`);
|
|
79
|
+
if (n.type !== "ReusedOntology" && old !== next)
|
|
80
|
+
notes.push(`Kept '${old}' as a former name, so a release's change log can map old to new.`);
|
|
69
81
|
return notes;
|
|
70
82
|
}
|
|
83
|
+
/** The former names after a rename: `old` goes on the end (oldest first), and a name that comes back is no longer former. */
|
|
84
|
+
function remember(former, old, next) {
|
|
85
|
+
return [...(former ?? []).filter((x) => x !== old && x !== next), old];
|
|
86
|
+
}
|
|
71
87
|
export function remove(ont, ref, types) {
|
|
72
88
|
const n = ont.find(ref, types);
|
|
73
89
|
if (n.id === "ontology")
|
|
@@ -101,6 +117,7 @@ export function remove(ont, ref, types) {
|
|
|
101
117
|
for (const t of ont.ofType("Term")) {
|
|
102
118
|
if (ont.targets(t.id, "BECAME").includes(n.id)) {
|
|
103
119
|
t.disposition = "undecided";
|
|
120
|
+
ont.touch(t);
|
|
104
121
|
notes.push(`Term '${t.text}' is undecided again.`);
|
|
105
122
|
}
|
|
106
123
|
}
|
package/dist/ops/classes.d.ts
CHANGED