@ontology-kit/okb 0.1.0-bootstrap.0 → 0.2.0
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 +159 -45
- package/dist/clock.js +1 -1
- package/dist/commands.js +96 -2
- 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 +1 -1
- package/dist/help.js +9 -2
- 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 +48 -0
- package/dist/release.js +318 -0
- package/dist/render.d.ts +4 -1
- package/dist/render.js +21 -2
- 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/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/meta-kb/data/manifest.json +2 -2
- package/meta-kb/data/nodes.json +8 -8
- package/package.json +7 -3
- 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/ops/classes.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** The class hierarchy: adding and changing classes, parents and disjointness. */
|
|
2
2
|
import * as naming from "../naming.js";
|
|
3
|
-
import { OkbError } from "@ontology-kit/
|
|
3
|
+
import { OkbError } from "@ontology-kit/reader";
|
|
4
4
|
import { an, splitList as list } from "./common.js";
|
|
5
5
|
import { checkName } from "./naming.js";
|
|
6
6
|
import { linkTermIfAny } from "./scope.js";
|
|
@@ -62,8 +62,10 @@ export function checkParents(ont, parents, name, notes) {
|
|
|
62
62
|
export function setClass(ont, ref, o) {
|
|
63
63
|
const cl = ont.find(ref, "Class");
|
|
64
64
|
const notes = [];
|
|
65
|
-
if (o.description !== undefined)
|
|
65
|
+
if (o.description !== undefined) {
|
|
66
66
|
cl.description = o.description;
|
|
67
|
+
ont.touch(cl);
|
|
68
|
+
}
|
|
67
69
|
for (const p of o.addParents ?? []) {
|
|
68
70
|
const pn = ont.find(p, "Class");
|
|
69
71
|
if (pn.id === cl.id || ont.ancestors(pn.id).has(cl.id))
|
|
@@ -77,12 +79,18 @@ export function setClass(ont, ref, o) {
|
|
|
77
79
|
ont.removeEdges((e) => e.from === cl.id && e.type === "IS_A" && e.to === pn.id);
|
|
78
80
|
notes.push(`${cl.name} is no longer under ${pn.name}.`);
|
|
79
81
|
}
|
|
80
|
-
if (o.synonyms?.length)
|
|
82
|
+
if (o.synonyms?.length) {
|
|
81
83
|
cl.synonyms = [...new Set([...(cl.synonyms ?? []), ...list(o.synonyms)])];
|
|
82
|
-
|
|
84
|
+
ont.touch(cl);
|
|
85
|
+
}
|
|
86
|
+
if (o.abstract !== undefined) {
|
|
83
87
|
cl.abstract = o.abstract || undefined;
|
|
84
|
-
|
|
88
|
+
ont.touch(cl);
|
|
89
|
+
}
|
|
90
|
+
if (o.terminological !== undefined) {
|
|
85
91
|
cl.terminological = o.terminological || undefined;
|
|
92
|
+
ont.touch(cl);
|
|
93
|
+
}
|
|
86
94
|
return notes.length ? notes : [`Updated ${cl.name}.`];
|
|
87
95
|
}
|
|
88
96
|
export function disjoint(ont, refs) {
|
package/dist/ops/instances.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Ontology } from "@ontology-kit/
|
|
1
|
+
import { type Ontology } from "@ontology-kit/reader";
|
|
2
2
|
import { type Notes } from "./common.js";
|
|
3
3
|
export declare function addInstance(ont: Ontology, name: string, o: {
|
|
4
4
|
of: string[];
|
|
@@ -6,3 +6,4 @@ export declare function addInstance(ont: Ontology, name: string, o: {
|
|
|
6
6
|
assignments?: string[];
|
|
7
7
|
}): Notes;
|
|
8
8
|
export declare function setInstanceClasses(ont: Ontology, ref: string, classes: string[]): Notes;
|
|
9
|
+
export declare function setInstanceDescription(ont: Ontology, ref: string, description: string): Notes;
|
package/dist/ops/instances.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Instances and the classes they belong to. */
|
|
2
2
|
import * as naming from "../naming.js";
|
|
3
|
-
import { OkbError, literalValues } from "@ontology-kit/
|
|
3
|
+
import { OkbError, literalValues } from "@ontology-kit/reader";
|
|
4
4
|
import { an } from "./common.js";
|
|
5
5
|
import { assign } from "./values.js";
|
|
6
6
|
import { checkParents } from "./classes.js";
|
|
@@ -68,3 +68,9 @@ export function setInstanceClasses(ont, ref, classes) {
|
|
|
68
68
|
notes.push(`Warning: its values for ${[...new Set(lost)].map((s) => ont.label(s)).join(", ")} don't apply to the new class. Remove them (okb instance set "${inst.name}" <slot>=) or pick another class.`);
|
|
69
69
|
return notes;
|
|
70
70
|
}
|
|
71
|
+
export function setInstanceDescription(ont, ref, description) {
|
|
72
|
+
const inst = ont.find(ref, "Instance");
|
|
73
|
+
inst.description = description;
|
|
74
|
+
ont.touch(inst);
|
|
75
|
+
return ["Updated description."];
|
|
76
|
+
}
|
package/dist/ops/links.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Ontology } from "@ontology-kit/
|
|
1
|
+
import { type Ontology } from "@ontology-kit/reader";
|
|
2
2
|
import type { Notes } from "./common.js";
|
|
3
3
|
/** Create (or update) one relationship value, with edge properties. */
|
|
4
4
|
export declare function link(ont: Ontology, fromRef: string, relRef: string, toRef: string, o?: {
|
package/dist/ops/links.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** One relationship value at a time, with edge properties (okb link / unlink). */
|
|
2
2
|
import * as naming from "../naming.js";
|
|
3
|
-
import { OkbError, edgeProps } from "@ontology-kit/
|
|
3
|
+
import { OkbError, edgeProps } from "@ontology-kit/reader";
|
|
4
4
|
import { assign, findSlotFor, parseAssignments } from "./values.js";
|
|
5
5
|
function coerceEdgeValue(decl, raw, relName) {
|
|
6
6
|
switch (decl.valueType) {
|
package/dist/ops/naming.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Ontology, type Conventions } from "@ontology-kit/
|
|
1
|
+
import { type Ontology, type Conventions } from "@ontology-kit/reader";
|
|
2
2
|
import type { Notes } from "./common.js";
|
|
3
3
|
export declare function setConventions(ont: Ontology, o: Partial<Conventions>): Notes;
|
|
4
4
|
export declare function checkName(ont: Ontology, name: string, kind: "Class" | "Slot", force: boolean | undefined, notes: Notes, exclude?: string): void;
|
package/dist/ops/naming.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Naming conventions, and the checks every new class or slot name goes through. */
|
|
2
2
|
import * as naming from "../naming.js";
|
|
3
|
-
import { OkbError } from "@ontology-kit/
|
|
3
|
+
import { OkbError } from "@ontology-kit/reader";
|
|
4
4
|
export function setConventions(ont, o) {
|
|
5
5
|
const conv = { ...naming.DEFAULT_CONVENTIONS, ...(ont.conventions ?? {}) };
|
|
6
6
|
if (o.classCase) {
|
|
@@ -27,6 +27,7 @@ export function setConventions(ont, o) {
|
|
|
27
27
|
}
|
|
28
28
|
conv.source = "chosen";
|
|
29
29
|
ont.meta.conventions = conv;
|
|
30
|
+
ont.touch(ont.meta);
|
|
30
31
|
const notes = [];
|
|
31
32
|
const bad = [...ont.ofType("Class"), ...ont.ofType("Slot")].filter((n) => n.name && naming.conventionalName(n.name, n.type, conv) !== n.name);
|
|
32
33
|
if (bad.length)
|
|
@@ -36,6 +37,7 @@ export function setConventions(ont, o) {
|
|
|
36
37
|
function ensureConventions(ont, notes) {
|
|
37
38
|
if (!ont.conventions) {
|
|
38
39
|
ont.meta.conventions = { ...naming.DEFAULT_CONVENTIONS, source: "default" };
|
|
40
|
+
ont.touch(ont.meta);
|
|
39
41
|
notes.push("No naming convention was set, so okb is using its defaults: classes PascalCase and singular, slots camelCase. Confirm them with `okb convention` (or pick your own).");
|
|
40
42
|
}
|
|
41
43
|
return ont.conventions;
|
package/dist/ops/scope.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Ontology, type Disposition } from "@ontology-kit/
|
|
1
|
+
import { type Ontology, type Disposition } from "@ontology-kit/reader";
|
|
2
2
|
import { type Notes } from "./common.js";
|
|
3
3
|
export declare function setScope(ont: Ontology, o: {
|
|
4
4
|
name?: string;
|
|
@@ -10,6 +10,10 @@ export declare function setScope(ont: Ontology, o: {
|
|
|
10
10
|
kind?: string;
|
|
11
11
|
}): Notes;
|
|
12
12
|
export declare function addCQ(ont: Ontology, text: string): Notes;
|
|
13
|
+
export declare function setCQ(ont: Ontology, ref: string, o: {
|
|
14
|
+
text?: string;
|
|
15
|
+
status?: string;
|
|
16
|
+
}): Notes;
|
|
13
17
|
export declare function linkCQ(ont: Ontology, cqRef: string, refs: string[], unlink?: boolean): Notes;
|
|
14
18
|
/**
|
|
15
19
|
* Once a question is answered, suggest its family (rule scope-cq-families): the same
|
package/dist/ops/scope.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** Step 1 to 3: scope, competency questions, reuse, and the brainstormed term list. */
|
|
2
2
|
import * as naming from "../naming.js";
|
|
3
3
|
import { questionFamilies } from "../families.js";
|
|
4
|
-
import { OkbError, DISPOSITIONS } from "@ontology-kit/
|
|
4
|
+
import { OkbError, DISPOSITIONS } from "@ontology-kit/reader";
|
|
5
5
|
import { isOneOf } from "../types.js";
|
|
6
6
|
import { splitList as list } from "./common.js";
|
|
7
7
|
import { addDecision } from "./admin.js";
|
|
@@ -26,6 +26,8 @@ export function setScope(ont, o) {
|
|
|
26
26
|
throw new OkbError("--kind must be 'application' or 'terminological'.");
|
|
27
27
|
m.kind = o.kind;
|
|
28
28
|
}
|
|
29
|
+
if (Object.values(o).some((v) => v !== undefined && (!Array.isArray(v) || v.length)))
|
|
30
|
+
ont.touch(m);
|
|
29
31
|
return [];
|
|
30
32
|
}
|
|
31
33
|
export function addCQ(ont, text) {
|
|
@@ -36,6 +38,18 @@ export function addCQ(ont, text) {
|
|
|
36
38
|
notes.push("Tip: phrase competency questions as actual questions.");
|
|
37
39
|
return notes;
|
|
38
40
|
}
|
|
41
|
+
export function setCQ(ont, ref, o) {
|
|
42
|
+
const q = ont.find(ref, "CompetencyQuestion");
|
|
43
|
+
if (o.status && !["draft", "answerable"].includes(o.status))
|
|
44
|
+
throw new OkbError("--status must be draft or answerable.");
|
|
45
|
+
if (o.text)
|
|
46
|
+
q.text = o.text;
|
|
47
|
+
if (o.status)
|
|
48
|
+
q.status = o.status;
|
|
49
|
+
if (o.text || o.status)
|
|
50
|
+
ont.touch(q);
|
|
51
|
+
return o.status === "answerable" ? [`Updated ${q.id}.`, familyTip(ont, q.id)] : [`Updated ${q.id}.`];
|
|
52
|
+
}
|
|
39
53
|
export function linkCQ(ont, cqRef, refs, unlink = false) {
|
|
40
54
|
const q = ont.find(cqRef, "CompetencyQuestion");
|
|
41
55
|
const notes = [];
|
|
@@ -85,6 +99,7 @@ export function setTerm(ont, ref, as, nodeRef, note) {
|
|
|
85
99
|
t.disposition = as;
|
|
86
100
|
if (note)
|
|
87
101
|
t.note = note;
|
|
102
|
+
ont.touch(t);
|
|
88
103
|
ont.removeEdges((e) => e.from === t.id && e.type === "BECAME");
|
|
89
104
|
const notes = [`'${t.text}' → ${as}.`];
|
|
90
105
|
const typeFor = { class: ["Class"], slot: ["Slot"], instance: ["Instance"], value: ["Slot"], synonym: ["Class"] };
|
|
@@ -108,10 +123,12 @@ export function addReuse(ont, o) {
|
|
|
108
123
|
throw new OkbError(`--decision must be one of: ${decisions.join(", ")}.`);
|
|
109
124
|
ont.addNode({ type: "ReusedOntology", id: ont.newId("ReusedOntology", o.name), name: o.name, url: o.url, decision: o.decision, notes: o.notes });
|
|
110
125
|
ont.meta.reuseReviewed = true;
|
|
126
|
+
ont.touch(ont.meta);
|
|
111
127
|
return [`Recorded '${o.name}' (${o.decision}).`];
|
|
112
128
|
}
|
|
113
129
|
export function reuseNone(ont, why) {
|
|
114
130
|
ont.meta.reuseReviewed = true;
|
|
131
|
+
ont.touch(ont.meta);
|
|
115
132
|
addDecision(ont, { title: "No existing ontology reused", decision: "Build from scratch.", rationale: why, about: ["ontology"] });
|
|
116
133
|
return ["Recorded that no existing ontology was reused, with your reason as a design decision."];
|
|
117
134
|
}
|
|
@@ -119,6 +136,7 @@ export function linkTermIfAny(ont, name, nodeId, as) {
|
|
|
119
136
|
const t = ont.ofType("Term").find((x) => naming.key(naming.withHead(x.text, naming.singularize)) === naming.key(naming.withHead(name, naming.singularize)));
|
|
120
137
|
if (t && (!t.disposition || t.disposition === "undecided")) {
|
|
121
138
|
t.disposition = as;
|
|
139
|
+
ont.touch(t);
|
|
122
140
|
ont.addEdge(t.id, "BECAME", nodeId);
|
|
123
141
|
}
|
|
124
142
|
}
|
package/dist/ops/slots.d.ts
CHANGED
package/dist/ops/slots.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Slots (properties and relationships), their facets, inverses and edge-property declarations. */
|
|
2
2
|
import * as naming from "../naming.js";
|
|
3
|
-
import { OkbError, isRelationship, CARDINALITIES, VALUE_TYPES } from "@ontology-kit/
|
|
3
|
+
import { OkbError, isRelationship, CARDINALITIES, VALUE_TYPES } from "@ontology-kit/reader";
|
|
4
4
|
import { isOneOf } from "../types.js";
|
|
5
5
|
import { splitList as list } from "./common.js";
|
|
6
6
|
import { checkName } from "./naming.js";
|
|
@@ -43,6 +43,7 @@ export function updateSlot(ont, ref, o, creating = false) {
|
|
|
43
43
|
throw new OkbError(`--type must be one of ${VALUE_TYPES.join(", ")}.`);
|
|
44
44
|
const wasRel = s.valueType === "Instance";
|
|
45
45
|
s.valueType = t;
|
|
46
|
+
ont.touch(s);
|
|
46
47
|
if (t !== "Enumerated")
|
|
47
48
|
delete s.allowedValues;
|
|
48
49
|
if (t !== "Instance") {
|
|
@@ -64,6 +65,7 @@ export function updateSlot(ont, ref, o, creating = false) {
|
|
|
64
65
|
if (s.valueType !== "Enumerated")
|
|
65
66
|
throw new OkbError("--values only applies to Enumerated slots (use --type Enumerated).");
|
|
66
67
|
s.allowedValues = list(o.values);
|
|
68
|
+
ont.touch(s);
|
|
67
69
|
}
|
|
68
70
|
const setRange = (refs, replace) => {
|
|
69
71
|
if (s.valueType !== "Instance")
|
|
@@ -72,6 +74,7 @@ export function updateSlot(ont, ref, o, creating = false) {
|
|
|
72
74
|
ont.removeEdges((e) => e.from === s.id && e.type === "RANGE");
|
|
73
75
|
for (const r of refs)
|
|
74
76
|
ont.addEdge(s.id, "RANGE", ont.find(r, "Class").id);
|
|
77
|
+
ont.touch(s); // a slot's range is a facet, so it counts even though it's stored as edges
|
|
75
78
|
};
|
|
76
79
|
if (o.range?.length)
|
|
77
80
|
setRange(o.range, true);
|
|
@@ -80,12 +83,16 @@ export function updateSlot(ont, ref, o, creating = false) {
|
|
|
80
83
|
for (const r of o.removeRange ?? []) {
|
|
81
84
|
const rc = ont.find(r, "Class");
|
|
82
85
|
ont.removeEdges((e) => e.from === s.id && e.type === "RANGE" && e.to === rc.id);
|
|
86
|
+
ont.touch(s);
|
|
83
87
|
}
|
|
84
88
|
if (o.card) {
|
|
85
89
|
if (!isOneOf(CARDINALITIES, o.card))
|
|
86
90
|
throw new OkbError("--card must be single or multiple.");
|
|
87
91
|
s.cardinality = o.card;
|
|
92
|
+
ont.touch(s);
|
|
88
93
|
}
|
|
94
|
+
if (o.min !== undefined || o.max !== undefined || o.description !== undefined)
|
|
95
|
+
ont.touch(s);
|
|
89
96
|
if (o.min !== undefined)
|
|
90
97
|
s.minCardinality = o.min;
|
|
91
98
|
if (o.max !== undefined)
|
|
@@ -113,10 +120,14 @@ export function updateSlot(ont, ref, o, creating = false) {
|
|
|
113
120
|
if (s.valueType === "Instance")
|
|
114
121
|
throw new OkbError(`${s.name} is a relationship. A rule's qualifiers must be properties; link rules with okb rule refines.`);
|
|
115
122
|
s.appliesToRules = true;
|
|
123
|
+
ont.touch(s);
|
|
116
124
|
}
|
|
117
|
-
if (o.offRules)
|
|
125
|
+
if (o.offRules) {
|
|
118
126
|
delete s.appliesToRules;
|
|
127
|
+
ont.touch(s);
|
|
128
|
+
}
|
|
119
129
|
if (o.default !== undefined) {
|
|
130
|
+
ont.touch(s);
|
|
120
131
|
if (o.default === "")
|
|
121
132
|
delete s.default;
|
|
122
133
|
else
|
|
@@ -164,6 +175,7 @@ export function declareEdgeProperty(ont, relRef, name, o) {
|
|
|
164
175
|
const decls = (rel.edgeProperties ??= []);
|
|
165
176
|
if (o.remove) {
|
|
166
177
|
rel.edgeProperties = decls.filter((d) => d.name !== name);
|
|
178
|
+
ont.touch(rel);
|
|
167
179
|
return [`Removed edge property ${name} from ${rel.name}. Existing values stay on the edges until you remove them.`];
|
|
168
180
|
}
|
|
169
181
|
if (RESERVED_EDGE_KEYS.has(name))
|
|
@@ -182,5 +194,6 @@ export function declareEdgeProperty(ont, relRef, name, o) {
|
|
|
182
194
|
decls[i] = decl;
|
|
183
195
|
else
|
|
184
196
|
decls.push(decl);
|
|
197
|
+
ont.touch(rel);
|
|
185
198
|
return [`${rel.name} edges can now carry ${name} (${t}${decl.required ? ", required" : ""}): (…)-[:${rel.relType} {${name}: …}]->(…)`];
|
|
186
199
|
}
|
package/dist/ops/values.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Ontology, type Literal, type SlotNode } from "@ontology-kit/
|
|
1
|
+
import { type Ontology, type Literal, type SlotNode } from "@ontology-kit/reader";
|
|
2
2
|
import { type Notes } from "./common.js";
|
|
3
3
|
export declare function parseAssignments(args: string[]): {
|
|
4
4
|
slot: string;
|
package/dist/ops/values.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Parsing and storing values: instance values, class fixed values, defaults and restrictions. */
|
|
2
2
|
import * as naming from "../naming.js";
|
|
3
|
-
import { OkbError, literalValues, nameOrText } from "@ontology-kit/
|
|
3
|
+
import { OkbError, literalValues, nameOrText } from "@ontology-kit/reader";
|
|
4
4
|
import { an, splitList as list } from "./common.js";
|
|
5
5
|
export function parseAssignments(args) {
|
|
6
6
|
return args.map((a) => {
|
|
@@ -106,6 +106,7 @@ export function assign(ont, ownerId, assignments, mode = "value") {
|
|
|
106
106
|
delete stored[slot.id];
|
|
107
107
|
else
|
|
108
108
|
stored[slot.id] = slot.cardinality === "multiple" ? next : next[0];
|
|
109
|
+
ont.touch(owner);
|
|
109
110
|
notes.push(`${owner.name}.${slot.name} ${mode === "fixed" ? "fixed to" : "="} ${next.map((v) => JSON.stringify(v)).join(", ") || "(nothing)"}`);
|
|
110
111
|
}
|
|
111
112
|
}
|
|
@@ -123,6 +124,7 @@ export function classDefault(ont, ref, assignments) {
|
|
|
123
124
|
delete cl.defaults[slot.id];
|
|
124
125
|
else
|
|
125
126
|
cl.defaults[slot.id] = coerce(ont, slot, a.raw);
|
|
127
|
+
ont.touch(cl);
|
|
126
128
|
notes.push(`New ${cl.name} instances will start with ${slot.name} = ${JSON.stringify(cl.defaults[slot.id] ?? null)} (can be changed per instance).`);
|
|
127
129
|
}
|
|
128
130
|
return notes;
|
|
@@ -133,6 +135,7 @@ export function restrict(ont, ref, slotRef, o) {
|
|
|
133
135
|
cl.facetOverrides ??= {};
|
|
134
136
|
if (o.clear) {
|
|
135
137
|
delete cl.facetOverrides[slot.id];
|
|
138
|
+
ont.touch(cl);
|
|
136
139
|
return [`Removed ${cl.name}'s restrictions on ${slot.name}.`];
|
|
137
140
|
}
|
|
138
141
|
const ov = (cl.facetOverrides[slot.id] ??= {});
|
|
@@ -144,6 +147,7 @@ export function restrict(ont, ref, slotRef, o) {
|
|
|
144
147
|
ov.maxCardinality = o.max;
|
|
145
148
|
if (o.range?.length)
|
|
146
149
|
ov.range = o.range.map((r) => ont.find(r, "Class").id);
|
|
150
|
+
ont.touch(cl);
|
|
147
151
|
const notes = [`${cl.name} now restricts ${slot.name}: ${JSON.stringify(ov)}.`];
|
|
148
152
|
if (o.max === 0)
|
|
149
153
|
notes.push(`Maximum 0 means ${cl.name} never has a ${slot.name} (Ontology 101 §3, Step 6).`);
|
package/dist/provenance.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type MdDoc } from "./markdown.js";
|
|
2
|
-
import { type Ontology, type SourceNode } from "@ontology-kit/
|
|
1
|
+
import { type MdDoc, type QuoteHit } from "./markdown.js";
|
|
2
|
+
import { type Ontology, type SourceLocationNode, type SourceNode } from "@ontology-kit/reader";
|
|
3
3
|
import type { Notes } from "./ops.js";
|
|
4
4
|
export declare const isMarkdown: (p: string) => boolean;
|
|
5
5
|
export declare function sourcePath(ont: Ontology, src: SourceNode): string;
|
|
@@ -18,6 +18,7 @@ export interface AddQuoteOpts {
|
|
|
18
18
|
export declare function addQuote(ont: Ontology, sourceRef: string, quote: string, o?: AddQuoteOpts): Promise<Notes>;
|
|
19
19
|
/** Attach an existing quote to a node: a CITES edge. Marks the node extracted, except an authored rule. */
|
|
20
20
|
export declare function cite(ont: Ontology, nodeRef: string, locRef: string): Notes;
|
|
21
|
+
export declare function locFields(hit: QuoteHit, src: SourceNode): Partial<SourceLocationNode>;
|
|
21
22
|
/** Re-locate every quote of a markdown source after the file changed; updates lines and links. */
|
|
22
23
|
export declare function refreshSource(ont: Ontology, sourceRef: string): Notes;
|
|
23
24
|
export interface AddRuleOpts {
|
|
@@ -49,5 +50,6 @@ export declare function verify(ont: Ontology, ref: string, o: {
|
|
|
49
50
|
corrected?: string;
|
|
50
51
|
confidence?: string;
|
|
51
52
|
note?: string;
|
|
53
|
+
ref?: string;
|
|
52
54
|
approve?: boolean;
|
|
53
55
|
}): Notes;
|
package/dist/provenance.js
CHANGED
|
@@ -6,11 +6,13 @@
|
|
|
6
6
|
import { existsSync, readFileSync } from "node:fs";
|
|
7
7
|
import { isAbsolute, join, relative, resolve } from "node:path";
|
|
8
8
|
import { deepLinks, locate, parseMarkdown } from "./markdown.js";
|
|
9
|
-
import { OkbError, nameOrText, MODALITIES, VERIFICATION_STATUSES as STATUSES } from "@ontology-kit/
|
|
9
|
+
import { OkbError, nameOrText, MODALITIES, VERIFICATION_STATUSES as STATUSES } from "@ontology-kit/reader";
|
|
10
10
|
import { isOneOf } from "./types.js";
|
|
11
|
+
import { UNSUPPORTED_NOTE_TIP, overreachNoteTips, shellQuote, statedModality } from "./verifynote.js";
|
|
11
12
|
import * as naming from "./naming.js";
|
|
12
13
|
import { assign } from "./ops/values.js";
|
|
13
14
|
import { findQuote, loadPages } from "./quotes.js";
|
|
15
|
+
import { blockRecords } from "./resync.js";
|
|
14
16
|
/** Suggest the closest block for a failed quote only if it shares at least this share of the quote's words. */
|
|
15
17
|
const MIN_CLOSEST_WORD_OVERLAP = 0.4;
|
|
16
18
|
export const isMarkdown = (p) => /\.(md|markdown)$/i.test(p);
|
|
@@ -42,6 +44,7 @@ export function addSource(ont, file, o) {
|
|
|
42
44
|
node.title ||= doc.title ?? file;
|
|
43
45
|
if (doc.frontmatter)
|
|
44
46
|
node.meta = doc.frontmatter;
|
|
47
|
+
node.blocks = blockRecords(doc);
|
|
45
48
|
const quotable = doc.blocks.filter((b) => b.quotable).length;
|
|
46
49
|
notes.push(`Read ${doc.blocks.length} blocks (${quotable} quotable) under ${doc.headings.length} headings.`);
|
|
47
50
|
for (const p of doc.problems)
|
|
@@ -116,11 +119,13 @@ export function cite(ont, nodeRef, locRef) {
|
|
|
116
119
|
const loc = ont.find(locRef, "SourceLocation");
|
|
117
120
|
const had = ont.targets(n.id, "CITES").includes(loc.id);
|
|
118
121
|
ont.addEdge(n.id, "CITES", loc.id);
|
|
119
|
-
if (!(n.type === "Rule" && n.authored))
|
|
122
|
+
if (!(n.type === "Rule" && n.authored) && !n.extracted) {
|
|
120
123
|
n.extracted = true;
|
|
124
|
+
ont.touch(n);
|
|
125
|
+
}
|
|
121
126
|
return [had ? `${n.type} ${nameOrText(n) ?? n.id} already cited ${loc.id}.` : `${n.type} ${nameOrText(n) ?? n.id} now cites ${loc.id}.`];
|
|
122
127
|
}
|
|
123
|
-
function locFields(hit, src) {
|
|
128
|
+
export function locFields(hit, src) {
|
|
124
129
|
const links = deepLinks(hit, src.repoUrl, src.url);
|
|
125
130
|
return Object.fromEntries(Object.entries({
|
|
126
131
|
locator: hit.locator,
|
|
@@ -134,11 +139,7 @@ function locFields(hit, src) {
|
|
|
134
139
|
}).filter(([, v]) => v !== undefined));
|
|
135
140
|
}
|
|
136
141
|
function nextLocId(ont, src) {
|
|
137
|
-
|
|
138
|
-
let i = 1;
|
|
139
|
-
while (ont.get(`${base}.${i}`))
|
|
140
|
-
i++;
|
|
141
|
-
return `${base}.${i}`;
|
|
142
|
+
return ont.newId("SourceLocation", naming.slug(src.title ?? src.id).slice(0, 30));
|
|
142
143
|
}
|
|
143
144
|
/** Suggest the block that shares the most words with a failed quote. */
|
|
144
145
|
function closest(doc, quote) {
|
|
@@ -179,6 +180,7 @@ export function refreshSource(ont, sourceRef) {
|
|
|
179
180
|
moved++;
|
|
180
181
|
notes.push(` ${loc.id}: line ${loc.lines} → ${hit.startLine}${hit.locator !== loc.locator ? ` (now under ${hit.locator})` : ""}`);
|
|
181
182
|
Object.assign(loc, locFields(hit, src));
|
|
183
|
+
ont.touch(loc);
|
|
182
184
|
}
|
|
183
185
|
}
|
|
184
186
|
notes.unshift(`${src.id}: ${moved} quote(s) moved, ${missing} missing.${missing ? " Missing quotes are errors in okb validate (prov-quote-current); re-extract them from the current text." : ""}`);
|
|
@@ -247,7 +249,23 @@ export function fulfill(ont, instanceRef, ruleRef, o = {}) {
|
|
|
247
249
|
ont.addEdge(inst.id, "FULFILLS", rule.id);
|
|
248
250
|
return [`${inst.name} fulfills ${rule.id}.`];
|
|
249
251
|
}
|
|
252
|
+
/** `--ref`: a link to the discussion behind a verification. Only web links, so nothing local or private leaks into the graph. */
|
|
253
|
+
function checkRef(ref) {
|
|
254
|
+
if (ref === undefined)
|
|
255
|
+
return;
|
|
256
|
+
let ok = /^https?:\/\/\S+$/i.test(ref);
|
|
257
|
+
if (ok)
|
|
258
|
+
try {
|
|
259
|
+
new URL(ref);
|
|
260
|
+
}
|
|
261
|
+
catch {
|
|
262
|
+
ok = false;
|
|
263
|
+
}
|
|
264
|
+
if (!ok)
|
|
265
|
+
throw new OkbError(`--ref must be an http:// or https:// link (to a PR comment, issue or review thread), not "${ref}".`);
|
|
266
|
+
}
|
|
250
267
|
export function verify(ont, ref, o) {
|
|
268
|
+
checkRef(o.ref);
|
|
251
269
|
const n = ont.find(ref, ["Rule", "Class", "Slot", "Instance"]);
|
|
252
270
|
const cited = ont.targets(n.id, "CITES");
|
|
253
271
|
if (!cited.length)
|
|
@@ -259,25 +277,41 @@ export function verify(ont, ref, o) {
|
|
|
259
277
|
throw new OkbError(`${n.id} hasn't been through verification yet.`);
|
|
260
278
|
if (n.verification.status === "UNSUPPORTED")
|
|
261
279
|
throw new OkbError("An UNSUPPORTED item can't be approved; remove it or re-extract from a quote that supports it.");
|
|
262
|
-
n.verification = { ...n.verification, status: "SUPPORTED", approvedAfter: n.verification.status, ...(o.note ? { note: o.note } : {}) };
|
|
280
|
+
n.verification = { ...n.verification, status: "SUPPORTED", approvedAfter: n.verification.status, ...(o.note ? { note: o.note } : {}), ...(o.ref ? { ref: o.ref } : {}) };
|
|
281
|
+
ont.touch(n);
|
|
263
282
|
return [`${n.id}: approved by a person (was ${n.verification.approvedAfter}).`];
|
|
264
283
|
}
|
|
265
284
|
const status = (o.status ?? "").toUpperCase();
|
|
266
285
|
if (!isOneOf(STATUSES, status))
|
|
267
286
|
throw new OkbError(`--status must be one of ${STATUSES.join(", ")} (or use --approve after a human review).`);
|
|
268
287
|
const notes = [];
|
|
288
|
+
const noteTips = [];
|
|
289
|
+
// The earlier result, when this runs again on an item still waiting for approval: its note and link stay unless replaced.
|
|
290
|
+
// Only for the same correction: a different one makes the old note wrong ("changed 44 to 24" after a change to 18).
|
|
291
|
+
const waiting = n.verification?.status === "OVERREACH" ? n.verification : undefined;
|
|
292
|
+
const again = waiting && status === "OVERREACH" && (n.type === "Rule" ? n.statement : n.description) === o.corrected ? waiting : undefined;
|
|
269
293
|
if (status === "OVERREACH") {
|
|
270
294
|
if (!o.corrected)
|
|
271
295
|
throw new OkbError('OVERREACH needs --corrected "<the narrower statement the quote does support>".');
|
|
272
|
-
|
|
273
|
-
|
|
296
|
+
const current = n.type === "Rule" ? n.statement : n.description ?? "";
|
|
297
|
+
// Running OVERREACH again on an item that is still waiting for approval (to add a note or a link, as the
|
|
298
|
+
// suggested command does) must not replace the original wording with the earlier correction.
|
|
299
|
+
const original = n.verification?.status === "OVERREACH" && n._originalDraft !== undefined ? n._originalDraft : current;
|
|
300
|
+
if (!o.note && !again?.note)
|
|
301
|
+
noteTips.push(...overreachNoteTips(n.id, original, o.corrected, o.ref ? ` --ref ${shellQuote(o.ref)}` : ""));
|
|
302
|
+
n._originalDraft = original;
|
|
303
|
+
if (n.type === "Rule")
|
|
274
304
|
n.statement = o.corrected;
|
|
275
|
-
|
|
276
|
-
else {
|
|
277
|
-
n._originalDraft = n.description;
|
|
305
|
+
else
|
|
278
306
|
n.description = o.corrected;
|
|
279
|
-
}
|
|
280
307
|
n.extractionConfidence = "corrected";
|
|
308
|
+
// A rule's strength lives in `modality`, not in the statement: keep the two in step, or approving the correction
|
|
309
|
+
// would publish a SHOULD statement as a MUST rule. The original wording (and its keyword) stays in _originalDraft.
|
|
310
|
+
const stated = n.type === "Rule" ? statedModality(o.corrected) : null;
|
|
311
|
+
if (n.type === "Rule" && stated && stated !== n.modality) {
|
|
312
|
+
notes.push(`Modality changed from ${n.modality} to ${stated} to match the corrected statement. Whoever approves it should check the new strength against the quote.`);
|
|
313
|
+
n.modality = stated;
|
|
314
|
+
}
|
|
281
315
|
notes.push(`Corrected ${field}: "${o.corrected}" (original kept in _originalDraft).`);
|
|
282
316
|
notes.push(`It stays blocked (prov-verified) until a person checks the correction: okb verify ${n.id} --approve`);
|
|
283
317
|
}
|
|
@@ -288,9 +322,16 @@ export function verify(ont, ref, o) {
|
|
|
288
322
|
}
|
|
289
323
|
else
|
|
290
324
|
n.extractionConfidence ??= "paraphrased";
|
|
291
|
-
|
|
292
|
-
|
|
325
|
+
const note = o.note ?? (status === "OVERREACH" ? again?.note : undefined);
|
|
326
|
+
const link = o.ref ?? (status === "OVERREACH" ? again?.ref : undefined);
|
|
327
|
+
n.verification = { status, checkedAgainst: cited, ...(note ? { note } : {}), ...(link ? { ref: link } : {}) };
|
|
328
|
+
ont.touch(n);
|
|
329
|
+
if (status === "UNSUPPORTED") {
|
|
293
330
|
notes.push(`${n.id} is UNSUPPORTED and blocks okb validate (prov-verified). Remove it: okb remove ${n.id}`);
|
|
331
|
+
if (!o.note)
|
|
332
|
+
noteTips.push(UNSUPPORTED_NOTE_TIP);
|
|
333
|
+
}
|
|
334
|
+
notes.push(...noteTips);
|
|
294
335
|
notes.unshift(`${n.id}: ${status}.`);
|
|
295
336
|
return notes;
|
|
296
337
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Ontology } from "@ontology-kit/reader";
|
|
2
|
+
import type { Finding } from "./types.js";
|
|
3
|
+
import type { Notes } from "./ops.js";
|
|
4
|
+
export declare const MANIFEST_FILE = "manifest.json";
|
|
5
|
+
export declare const RELEASES_DIR = "releases";
|
|
6
|
+
/** A dataset in a manifest: a folder (relative to the manifest) and the SHA-256 of the files pinned in it. */
|
|
7
|
+
export interface Dataset {
|
|
8
|
+
path: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
files: Record<string, string>;
|
|
11
|
+
}
|
|
12
|
+
export interface ReleaseManifest {
|
|
13
|
+
id: string;
|
|
14
|
+
version: string;
|
|
15
|
+
title?: string;
|
|
16
|
+
description?: string;
|
|
17
|
+
datasets: {
|
|
18
|
+
docs?: Dataset;
|
|
19
|
+
ontology?: Dataset;
|
|
20
|
+
};
|
|
21
|
+
provenance?: Record<string, unknown>;
|
|
22
|
+
}
|
|
23
|
+
/** <0 if a is older than b, 0 if equal, >0 if newer. Semver precedence; a version with a pre-release tag is older than the plain one. */
|
|
24
|
+
export declare function compareVersions(a: string, b: string): number;
|
|
25
|
+
export declare const isVersion: (v: string) => boolean;
|
|
26
|
+
/** Read and check the shape of a manifest.json. Throws OkbError naming the problem. */
|
|
27
|
+
export declare function readReleaseManifest(file: string): ReleaseManifest;
|
|
28
|
+
export interface ReleaseResult {
|
|
29
|
+
version: string;
|
|
30
|
+
previous?: string;
|
|
31
|
+
manifest: ReleaseManifest;
|
|
32
|
+
notes: Notes;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Cut release `version` of the folder `ont` was loaded from. Call it inside `Ontology.edit` (it saves
|
|
36
|
+
* and writes files under the lock). `findings` are the validator's results; any open error stops the release.
|
|
37
|
+
* Writes nothing when it refuses.
|
|
38
|
+
*/
|
|
39
|
+
export declare function cutRelease(ont: Ontology, version: string, findings: Finding[]): ReleaseResult;
|
|
40
|
+
export interface VerifyResult {
|
|
41
|
+
id: string;
|
|
42
|
+
version: string;
|
|
43
|
+
ok: boolean;
|
|
44
|
+
checked: number;
|
|
45
|
+
problems: string[];
|
|
46
|
+
}
|
|
47
|
+
/** Check the files in `root` against its manifest.json. Read-only. */
|
|
48
|
+
export declare function verifyRelease(root: string): VerifyResult;
|