@ontology-kit/okb 0.1.0 → 0.3.0-alpha.133
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 +102 -0
- package/dist/checks.d.ts +1 -1
- package/dist/checks.js +27 -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 +144 -0
- package/dist/command-table.js +85 -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 +467 -0
- package/dist/commands/planning.d.ts +3 -0
- package/dist/commands/planning.js +251 -0
- package/dist/commands/reviewing.d.ts +3 -0
- package/dist/commands/reviewing.js +234 -0
- package/dist/commands/skills.d.ts +3 -0
- package/dist/commands/skills.js +53 -0
- package/dist/commands.d.ts +10 -22
- package/dist/commands.js +15 -622
- package/dist/cqanswer.d.ts +51 -0
- package/dist/cqanswer.js +76 -0
- package/dist/diff.d.ts +85 -0
- package/dist/diff.js +323 -0
- package/dist/export-changes.d.ts +40 -0
- package/dist/export-changes.js +115 -0
- package/dist/export-csv.d.ts +17 -0
- package/dist/export-csv.js +188 -0
- package/dist/export-eval-cases.d.ts +38 -0
- package/dist/export-eval-cases.js +40 -0
- package/dist/export.d.ts +34 -3
- package/dist/export.js +70 -12
- 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 +2 -2
- package/dist/ops/admin.js +26 -8
- package/dist/ops/classes.d.ts +1 -1
- package/dist/ops/classes.js +15 -7
- package/dist/ops/common.d.ts +12 -2
- package/dist/ops/common.js +3 -0
- package/dist/ops/instances.d.ts +2 -1
- package/dist/ops/instances.js +9 -3
- package/dist/ops/links.d.ts +2 -2
- package/dist/ops/links.js +3 -2
- package/dist/ops/naming.d.ts +1 -1
- package/dist/ops/naming.js +3 -1
- package/dist/ops/scope.d.ts +14 -3
- package/dist/ops/scope.js +38 -4
- package/dist/ops/slots.d.ts +1 -1
- package/dist/ops/slots.js +21 -8
- package/dist/ops/values.d.ts +1 -1
- package/dist/ops/values.js +5 -1
- package/dist/provenance.d.ts +5 -3
- package/dist/provenance.js +61 -19
- package/dist/release.d.ts +52 -0
- package/dist/release.js +337 -0
- package/dist/render.d.ts +88 -1
- package/dist/render.js +265 -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 +84 -0
- package/dist/skills.d.ts +19 -3
- package/dist/skills.js +130 -14
- 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 +19 -0
- package/dist/verifynote.js +93 -0
- package/dist/workflows.d.ts +283 -0
- package/dist/workflows.js +270 -0
- package/meta-kb/data/edges.json +25 -0
- package/meta-kb/data/manifest.json +5 -5
- package/meta-kb/data/nodes.json +46 -9
- package/package.json +9 -4
- package/schema/edge.schema.json +68 -0
- package/schema/edges.schema.json +9 -0
- package/schema/node.schema.json +914 -0
- package/schema/nodes.schema.json +9 -0
- package/schema/okb.schema.json +41 -0
- package/skills/build-domain-kb-from-docs/SKILL.md +21 -3
- package/skills/ontology-coach/SKILL.md +8 -4
- package/skills/ontology-maintainer/SKILL.md +152 -0
- package/skills/ontology-review/SKILL.md +4 -2
- package/skills/ontology-signoff/SKILL.md +182 -0
- package/templates/okb-check.yml +148 -0
- package/templates/pull_request_template.md +16 -0
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The multi-step work behind a few commands, kept out of their records so `run` stays a few lines:
|
|
3
|
+
* the data an output shows (`--json`), and the steps that load, compute and write more than one thing.
|
|
4
|
+
* Nothing here prints; `render.ts` does.
|
|
5
|
+
*/
|
|
6
|
+
import { existsSync } from "node:fs";
|
|
7
|
+
import { join, resolve } from "node:path";
|
|
8
|
+
import { OkbError, Ontology, queryGet } from "@ontology-kit/reader";
|
|
9
|
+
import { duplicateQuotes, loadSourcePages, runChecks } from "./checks.js";
|
|
10
|
+
import { MetaKB } from "./metakb.js";
|
|
11
|
+
import { exportGraph, toCypher } from "./export.js";
|
|
12
|
+
import { changeSetCypher } from "./export-changes.js";
|
|
13
|
+
import { CSV_FORMATS, toNeo4jCsv, toNeptuneCsv } from "./export-csv.js";
|
|
14
|
+
import { diffOntologies } from "./diff.js";
|
|
15
|
+
import { installSkills, skillsStatus } from "./skills.js";
|
|
16
|
+
import * as ops from "./ops.js";
|
|
17
|
+
import * as prov from "./provenance.js";
|
|
18
|
+
import { computeStatus } from "./status.js";
|
|
19
|
+
import { kbDocs, writeChangedPages, writeKbDocs, writePages } from "./kbdocs.js";
|
|
20
|
+
import { changedPageSet, changesPage, contextPage } from "./reviewdocs.js";
|
|
21
|
+
import { loadSide } from "./ontology-ref.js";
|
|
22
|
+
import { resync } from "./resync.js";
|
|
23
|
+
import { runCheck } from "./check.js";
|
|
24
|
+
import { RELEASES_DIR, cutRelease, isVersion, verifyRelease } from "./release.js";
|
|
25
|
+
import { PACKAGE_VERSION } from "./version.js";
|
|
26
|
+
import { stepGuide } from "./render.js";
|
|
27
|
+
/** `okb init`: create the folder and stamp the meta-KB version. */
|
|
28
|
+
export function initOntology(folder, name) {
|
|
29
|
+
const ont = ops.createOntology(folder, name);
|
|
30
|
+
ont.manifest.metaKbVersion = MetaKB.get().version;
|
|
31
|
+
ont.save();
|
|
32
|
+
return { ont, guide: stepGuide(MetaKB.get().step(1)) };
|
|
33
|
+
}
|
|
34
|
+
/** `okb show`: the node and the edges on both sides of it. */
|
|
35
|
+
export function showData(ont, n) {
|
|
36
|
+
return queryGet(ont, n.id);
|
|
37
|
+
}
|
|
38
|
+
/** `okb validate`: run the checks and say whether the command should fail. */
|
|
39
|
+
export async function validate(ont, o) {
|
|
40
|
+
const { findings, hiddenLater } = runChecks(ont, { all: o.all, only: o.rule }, { pages: await loadSourcePages(ont) });
|
|
41
|
+
const open = findings.filter((f) => !f.explainedBy);
|
|
42
|
+
const fail = open.some((f) => f.severity === "error") || (!!o.strict && open.some((f) => f.severity === "warning"));
|
|
43
|
+
return { findings, hiddenLater, fail, data: { step: ont.step, metaKbVersion: MetaKB.get().version, hiddenLater, findings } };
|
|
44
|
+
}
|
|
45
|
+
/** `okb status`: every finding (not just this step's) and the step progress. */
|
|
46
|
+
export async function status(ont) {
|
|
47
|
+
const { findings } = runChecks(ont, { all: true }, { pages: await loadSourcePages(ont) });
|
|
48
|
+
const st = computeStatus(ont, findings);
|
|
49
|
+
return { findings, st, data: { currentStep: ont.step, ...st } };
|
|
50
|
+
}
|
|
51
|
+
/** `okb step <n|next|prev>`: move to the step, saving under the lock. */
|
|
52
|
+
export function moveToStep(dir, which) {
|
|
53
|
+
const meta = MetaKB.get();
|
|
54
|
+
return Ontology.edit(dir, (ont) => {
|
|
55
|
+
const target = which === "next" ? ont.step + 1 : which === "prev" ? ont.step - 1 : Number(which);
|
|
56
|
+
if (!meta.step(target))
|
|
57
|
+
throw new OkbError(`There is no step ${which}. Steps are 1–${meta.steps.length}.`);
|
|
58
|
+
const leaving = computeStatus(ont).steps.find((s) => s.order === ont.step);
|
|
59
|
+
ont.manifest.currentStep = target;
|
|
60
|
+
ont.save();
|
|
61
|
+
return { target, leaving };
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/** The step to show a guide for: the folder's, or step 1 when there is no ontology here. */
|
|
65
|
+
export function currentStep(dir) {
|
|
66
|
+
try {
|
|
67
|
+
return Ontology.load(dir).step;
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return 1;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/** `okb review --json`: the scope, the judgment prompts, every class and the decisions. */
|
|
74
|
+
export function reviewData(ont, items) {
|
|
75
|
+
const classes = ont.ofType("Class").map((cl) => ({
|
|
76
|
+
id: cl.id, name: cl.name, description: cl.description, parents: ont.parents(cl.id).map((x) => ont.label(x)),
|
|
77
|
+
children: ont.children(cl.id).map((x) => ont.label(x)), ownSlots: ont.ownSlots(cl.id).map((s) => ont.label(s)),
|
|
78
|
+
abstract: cl.abstract, terminological: cl.terminological, instances: ont.sources(cl.id, "INSTANCE_OF").length,
|
|
79
|
+
}));
|
|
80
|
+
return { step: ont.step, scope: ont.meta, judgmentRules: items, classes, decisions: ont.ofType("DesignDecision") };
|
|
81
|
+
}
|
|
82
|
+
/** `okb source outline`: the document's blocks and which lines already have a quote. */
|
|
83
|
+
export function outline(ont, sourceRef, o) {
|
|
84
|
+
const src = ont.find(sourceRef, "Source");
|
|
85
|
+
if (src.format !== "markdown")
|
|
86
|
+
throw new OkbError("outline works on markdown sources.");
|
|
87
|
+
const doc = prov.readMarkdownSource(ont, src);
|
|
88
|
+
const quoted = new Map();
|
|
89
|
+
for (const id of ont.sources(src.id, "PART_OF")) {
|
|
90
|
+
const l = ont.get(id);
|
|
91
|
+
if (l?.type !== "SourceLocation" || l.startLine === undefined)
|
|
92
|
+
continue;
|
|
93
|
+
const { startLine, endLine } = l;
|
|
94
|
+
for (let n = startLine; n <= (endLine ?? startLine); n++)
|
|
95
|
+
quoted.set(n, [...(quoted.get(n) ?? []), id]);
|
|
96
|
+
}
|
|
97
|
+
const blocks = doc.blocks.filter((b) => !o.quotable || b.quotable);
|
|
98
|
+
const data = () => ({
|
|
99
|
+
source: src.id, title: doc.title, frontmatter: doc.frontmatter, problems: doc.problems,
|
|
100
|
+
blocks: blocks.map((b) => ({ index: b.index, kind: b.kind, headingPath: b.headingPath, lines: [b.startLine, b.endLine], quotable: b.quotable, note: b.note, calloutType: b.calloutType, row: b.row, text: b.kind === "code" ? undefined : b.text, alreadyQuoted: [...new Set(Array.from({ length: b.endLine - b.startLine + 1 }, (_, k) => quoted.get(b.startLine + k) ?? []).flat())] })),
|
|
101
|
+
});
|
|
102
|
+
return { src, doc, blocks, quoted, data };
|
|
103
|
+
}
|
|
104
|
+
/** `okb source refresh --all`: re-check every quote against its document, and write only when something moved. */
|
|
105
|
+
export async function refreshAll(dir, o) {
|
|
106
|
+
const ont = Ontology.load(dir);
|
|
107
|
+
const pages = await loadSourcePages(ont);
|
|
108
|
+
const w = { write: !o.dryRun, record: !!o.record && !o.dryRun };
|
|
109
|
+
let report = resync(ont, pages, { write: false, record: false });
|
|
110
|
+
// Take the lock only when something has to be written.
|
|
111
|
+
if (w.write && (report.moved.length || w.record)) {
|
|
112
|
+
report = Ontology.edit(dir, (locked) => {
|
|
113
|
+
const r = locked.tick(() => resync(locked, pages, w));
|
|
114
|
+
locked.save();
|
|
115
|
+
return r;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
return { report, write: w.write };
|
|
119
|
+
}
|
|
120
|
+
/** `okb drift`: near-duplicate quotes across the ontologies in these folders. */
|
|
121
|
+
export function drift(folders) {
|
|
122
|
+
const onts = (folders.length ? folders : ["."]).map((d) => Ontology.load(d));
|
|
123
|
+
const merged = Ontology.fromData(onts.flatMap((o) => o.nodes.filter((n) => n.type !== "Ontology")), onts.flatMap((o) => o.edges));
|
|
124
|
+
return duplicateQuotes(merged);
|
|
125
|
+
}
|
|
126
|
+
/** `okb release <version>`: run the checks and cut the release under the lock. */
|
|
127
|
+
export function release(dir, version) {
|
|
128
|
+
return Ontology.edit(dir, async (ont) => {
|
|
129
|
+
const findings = runChecks(ont, { all: false }, { pages: await loadSourcePages(ont) }).findings;
|
|
130
|
+
return cutRelease(ont, version, findings);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
/** `okb pin`: record the installed okb version in okb.json. */
|
|
134
|
+
export function pin(dir) {
|
|
135
|
+
Ontology.edit(dir, (ont) => {
|
|
136
|
+
ont.manifest.okbVersion = PACKAGE_VERSION;
|
|
137
|
+
ont.save();
|
|
138
|
+
});
|
|
139
|
+
return PACKAGE_VERSION;
|
|
140
|
+
}
|
|
141
|
+
/** `okb check`. */
|
|
142
|
+
export async function check(ont) {
|
|
143
|
+
return runCheck(ont, PACKAGE_VERSION);
|
|
144
|
+
}
|
|
145
|
+
/** `okb docs`: the reference pages, the changed-since-<ref> view, or the rules-in-context page. */
|
|
146
|
+
export async function docs(dir, outDir, o) {
|
|
147
|
+
const out = resolve(outDir);
|
|
148
|
+
if (o.context && (o.changed !== undefined || o.hops !== undefined))
|
|
149
|
+
throw new OkbError("--context is its own view of every rule; it doesn't combine with --changed or --hops.");
|
|
150
|
+
if (o.hops !== undefined && o.changed === undefined)
|
|
151
|
+
throw new OkbError("--hops adds neighbors to a --changed view; give --changed <ref> too.");
|
|
152
|
+
if (o.context) {
|
|
153
|
+
const ont = Ontology.load(dir);
|
|
154
|
+
return { files: writePages(out, { "rules-in-context.md": contextPage(ont, await loadSourcePages(ont)) }), what: "rules-in-context.md", hint: "" };
|
|
155
|
+
}
|
|
156
|
+
if (o.changed !== undefined) {
|
|
157
|
+
if (o.hops !== undefined && !/^\d+$/.test(o.hops))
|
|
158
|
+
throw new OkbError("--hops needs a whole number (0 or more).");
|
|
159
|
+
const hops = o.hops === undefined ? 0 : Number(o.hops);
|
|
160
|
+
const ont = Ontology.load(dir);
|
|
161
|
+
const old = loadSide(o.changed, dir);
|
|
162
|
+
const { pages, changes } = changedPageSet(kbDocs(old.ont), kbDocs(ont), hops);
|
|
163
|
+
const after = kbDocs(ont);
|
|
164
|
+
const report = resync(ont, await loadSourcePages(ont), { write: false, record: false });
|
|
165
|
+
const files = Object.fromEntries(pages.map((n) => [n, after[n]]));
|
|
166
|
+
files["changes.md"] = changesPage({ against: o.changed, name: ont.meta.name, changes, hops, resync: report });
|
|
167
|
+
const stale = report.gone.length + report.moved.length + report.worklist.length;
|
|
168
|
+
return {
|
|
169
|
+
files: writeChangedPages(out, files),
|
|
170
|
+
what: `${pages.length} changed ${pages.length === 1 ? "page" : "pages"} and changes.md (${stale} source ${stale === 1 ? "change" : "changes"} not yet in the KB)`,
|
|
171
|
+
hint: " (start at changes.md)",
|
|
172
|
+
extra: changes,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
const files = writeKbDocs(Ontology.load(dir), out);
|
|
176
|
+
return { files, what: `${files.length} pages`, hint: " (start at index.md)" };
|
|
177
|
+
}
|
|
178
|
+
/** `okb diff <old> [<new>]`: each side a folder or a git ref; with one, the new side is the folder itself. */
|
|
179
|
+
export function diff(dir, oldRef, newRef) {
|
|
180
|
+
const a = loadSide(oldRef, dir);
|
|
181
|
+
const b = newRef ? loadSide(newRef, dir) : { ont: Ontology.load(dir), name: "working folder" };
|
|
182
|
+
return diffOntologies(a.ont, b.ont, a.name, b.name);
|
|
183
|
+
}
|
|
184
|
+
/** `okb release verify`: check the folder against its manifest.json (read-only). */
|
|
185
|
+
export function releaseVerify(dir) {
|
|
186
|
+
return verifyRelease(resolve(dir));
|
|
187
|
+
}
|
|
188
|
+
/** `okb export`: the graph, as text, or for the CSV formats a set of files for `--out` (a folder). The format follows --out's extension when --format is left out. */
|
|
189
|
+
export function exportOntology(ont, o) {
|
|
190
|
+
const fmt = o.format ?? (o.out?.endsWith(".cypher") || o.out?.endsWith(".cql") ? "cypher" : "json");
|
|
191
|
+
const csv = CSV_FORMATS.includes(fmt);
|
|
192
|
+
if (!["json", "cypher"].includes(fmt) && !csv)
|
|
193
|
+
throw new OkbError("--format must be json, cypher, neo4j-csv or neptune-csv.");
|
|
194
|
+
if (o.style !== undefined && !["batched", "simple"].includes(o.style))
|
|
195
|
+
throw new OkbError("--style must be batched or simple.");
|
|
196
|
+
if (o.style !== undefined && fmt !== "cypher")
|
|
197
|
+
throw new OkbError("--style only applies to --format cypher.");
|
|
198
|
+
if (o.since !== undefined && (fmt !== "cypher" || o.style === "simple"))
|
|
199
|
+
throw new OkbError("--since writes a change set, which only exists as --format cypher in the default batched style.");
|
|
200
|
+
if (csv && !o.out)
|
|
201
|
+
throw new OkbError(`--format ${fmt} writes several files, so give a folder with --out.`);
|
|
202
|
+
const opts = { inherited: !o.noInherited, schema: o.schema, rules: !o.noRules, unverified: o.includeUnverified };
|
|
203
|
+
const graph = exportGraph(ont, opts);
|
|
204
|
+
if (o.since !== undefined) {
|
|
205
|
+
const cs = exportChangeSet(ont, o.since, opts, graph);
|
|
206
|
+
return { fmt, graph, text: cs.text, files: undefined, loadCommand: undefined, changes: cs.summary };
|
|
207
|
+
}
|
|
208
|
+
if (csv) {
|
|
209
|
+
const neo4j = fmt === "neo4j-csv" ? toNeo4jCsv(graph) : undefined;
|
|
210
|
+
const { files, notes } = neo4j ? { files: neo4j.files, notes: [] } : toNeptuneCsv(graph);
|
|
211
|
+
return { fmt, graph: { ...graph, notes: [...graph.notes, ...notes] }, text: "", files: files, loadCommand: neo4j?.command, changes: undefined };
|
|
212
|
+
}
|
|
213
|
+
const release = ont.manifest.version ? { ontology: ont.meta.name, version: ont.manifest.version } : undefined;
|
|
214
|
+
return { fmt, graph, text: fmt === "cypher" ? toCypher(graph, { style: o.style, release }) : JSON.stringify(graph, null, 2) + "\n", files: undefined, loadCommand: undefined, changes: undefined };
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* `okb export --since`: the change set from release `since` (a release in `releases/`, a folder, or a git ref) to this
|
|
218
|
+
* folder, which must be exactly its latest release so the script's end version is true.
|
|
219
|
+
*/
|
|
220
|
+
function exportChangeSet(ont, since, opts, graph) {
|
|
221
|
+
const to = ont.manifest.version;
|
|
222
|
+
if (!to)
|
|
223
|
+
throw new OkbError("This knowledge base has no release version yet, so a change set has no end version. Cut a release first: okb release <version>.");
|
|
224
|
+
if (existsSync(join(ont.root, "manifest.json"))) {
|
|
225
|
+
const v = verifyRelease(ont.root);
|
|
226
|
+
if (!v.ok)
|
|
227
|
+
throw new OkbError(`The folder has changed since release ${to} (${v.problems[0]}), so a change set to ${to} would be wrong. Cut a release first (okb release <version>), then export the change set.`);
|
|
228
|
+
}
|
|
229
|
+
const snapshot = isVersion(since) && existsSync(join(ont.root, RELEASES_DIR, since, "okb.json")) ? join(ont.root, RELEASES_DIR, since) : undefined;
|
|
230
|
+
const old = snapshot ? { ont: Ontology.load(snapshot), name: since } : loadSide(since, ont.root);
|
|
231
|
+
const from = old.ont.manifest.version;
|
|
232
|
+
if (!from)
|
|
233
|
+
throw new OkbError(`'${since}' has no release version, so a change set from it can't check the database it runs against. Pass a release (a folder in releases/, or a git ref of a commit made by okb release).`);
|
|
234
|
+
if (from === to)
|
|
235
|
+
throw new OkbError(`'${since}' is release ${from}, the same as the current version. Pass an earlier release.`);
|
|
236
|
+
const oldGraph = exportGraph(old.ont, opts);
|
|
237
|
+
const flags = [opts.schema ? "--with-schema" : "", opts.inherited ? "" : "--no-inherited", opts.rules ? "" : "--no-rules", opts.unverified ? "--include-unverified" : ""].filter(Boolean).join(" ");
|
|
238
|
+
return changeSetCypher(oldGraph, graph, { from: { ontology: old.ont.meta.name, version: from }, to: { ontology: ont.meta.name, version: to }, flags: flags || undefined });
|
|
239
|
+
}
|
|
240
|
+
/** `okb instance set`: move to other classes, assign values, change the description, in that order. */
|
|
241
|
+
export function setInstance(ont, name, o) {
|
|
242
|
+
const notes = [
|
|
243
|
+
...(o.of?.length ? ops.setInstanceClasses(ont, name, o.of) : []),
|
|
244
|
+
...(o.assignments.length ? ops.assign(ont, ont.find(name, "Instance").id, o.assignments) : []),
|
|
245
|
+
];
|
|
246
|
+
if (o.desc !== undefined)
|
|
247
|
+
notes.push(...ops.setInstanceDescription(ont, name, o.desc));
|
|
248
|
+
return notes;
|
|
249
|
+
}
|
|
250
|
+
/** `okb quote list`: every quote, or the quotes from one source. */
|
|
251
|
+
export function quotes(ont, sourceRef) {
|
|
252
|
+
const locs = ont.ofType("SourceLocation").filter((l) => !sourceRef || ont.targets(l.id, "PART_OF").includes(ont.find(sourceRef, "Source").id));
|
|
253
|
+
return { locs, data: () => locs.map((l) => ({ ...l, citedBy: ont.sources(l.id, "CITES") })) };
|
|
254
|
+
}
|
|
255
|
+
/** `okb explain <topic>`: what matches, with the citations and rationale `--json` adds. */
|
|
256
|
+
export function explainData(hits) {
|
|
257
|
+
const meta = MetaKB.get();
|
|
258
|
+
return hits.map((h) => ({ ...h, citations: meta.citations(h.id), rationale: h.type === "Rule" ? meta.rationale(h) : undefined }));
|
|
259
|
+
}
|
|
260
|
+
/** `okb version`. */
|
|
261
|
+
export const versionLine = () => `okb ${PACKAGE_VERSION} · meta-KB ${MetaKB.get().version}`;
|
|
262
|
+
/** `okb skills install` and `okb skills status`, for the packaged skills and this meta-KB version. */
|
|
263
|
+
export function skillsInstallReport(o) {
|
|
264
|
+
return installSkills({ dir: o.dir, metaVersion: MetaKB.get().version, copy: o.copy, force: o.force, interactive: o.interactive, ask: o.ask });
|
|
265
|
+
}
|
|
266
|
+
export function skillsStatusReport(o) {
|
|
267
|
+
const metaVersion = MetaKB.get().version;
|
|
268
|
+
const { dir, skills } = skillsStatus({ dir: o.dir, metaVersion });
|
|
269
|
+
return { dir, skills, metaVersion, allCurrent: skills.every((s) => s.state === "current") };
|
|
270
|
+
}
|
package/meta-kb/data/edges.json
CHANGED
|
@@ -1989,6 +1989,21 @@
|
|
|
1989
1989
|
"type": "GOVERNS",
|
|
1990
1990
|
"to": "concept.competency-question"
|
|
1991
1991
|
},
|
|
1992
|
+
{
|
|
1993
|
+
"from": "rule.scope-cq-expected-answer",
|
|
1994
|
+
"type": "JUSTIFIED_BY",
|
|
1995
|
+
"to": "rat.scope-cq-expected-answer"
|
|
1996
|
+
},
|
|
1997
|
+
{
|
|
1998
|
+
"from": "rat.scope-cq-expected-answer",
|
|
1999
|
+
"type": "CITES",
|
|
2000
|
+
"to": "loc.o101.cq-litmus"
|
|
2001
|
+
},
|
|
2002
|
+
{
|
|
2003
|
+
"from": "rule.scope-cq-expected-answer",
|
|
2004
|
+
"type": "GOVERNS",
|
|
2005
|
+
"to": "concept.competency-question"
|
|
2006
|
+
},
|
|
1992
2007
|
{
|
|
1993
2008
|
"from": "rule.scope-no-unneeded",
|
|
1994
2009
|
"type": "JUSTIFIED_BY",
|
|
@@ -2144,6 +2159,16 @@
|
|
|
2144
2159
|
"type": "GOVERNS",
|
|
2145
2160
|
"to": "concept.lpg"
|
|
2146
2161
|
},
|
|
2162
|
+
{
|
|
2163
|
+
"from": "rule.struct-no-save-leftovers",
|
|
2164
|
+
"type": "JUSTIFIED_BY",
|
|
2165
|
+
"to": "rat.struct-no-save-leftovers"
|
|
2166
|
+
},
|
|
2167
|
+
{
|
|
2168
|
+
"from": "rule.struct-no-save-leftovers",
|
|
2169
|
+
"type": "GOVERNS",
|
|
2170
|
+
"to": "concept.lpg"
|
|
2171
|
+
},
|
|
2147
2172
|
{
|
|
2148
2173
|
"from": "rule.prov-verified",
|
|
2149
2174
|
"type": "JUSTIFIED_BY",
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.
|
|
3
|
-
"formatVersion": "okb-lpg/
|
|
2
|
+
"version": "2.8.1",
|
|
3
|
+
"formatVersion": "okb-lpg/3",
|
|
4
4
|
"nodeCounts": {
|
|
5
5
|
"MetaKB": 1,
|
|
6
6
|
"Source": 2,
|
|
7
7
|
"SourceLocation": 127,
|
|
8
8
|
"Principle": 7,
|
|
9
9
|
"Concept": 40,
|
|
10
|
-
"Rule":
|
|
11
|
-
"Rationale":
|
|
10
|
+
"Rule": 59,
|
|
11
|
+
"Rationale": 59,
|
|
12
12
|
"Decision": 10,
|
|
13
13
|
"Step": 8,
|
|
14
14
|
"NodeType": 11,
|
|
15
15
|
"EdgeType": 14
|
|
16
16
|
},
|
|
17
|
-
"edgeCount":
|
|
17
|
+
"edgeCount": 639,
|
|
18
18
|
"quotesVerified": true
|
|
19
19
|
}
|
package/meta-kb/data/nodes.json
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
{
|
|
3
3
|
"type": "MetaKB",
|
|
4
4
|
"id": "metakb",
|
|
5
|
-
"version": "2.
|
|
6
|
-
"formatVersion": "okb-lpg/
|
|
5
|
+
"version": "2.8.1",
|
|
6
|
+
"formatVersion": "okb-lpg/3",
|
|
7
7
|
"description": "Rules, method and vocabulary for building ontologies, derived from Ontology 101 (Noy & McGuinness 2001) and Gruber (1993)."
|
|
8
8
|
},
|
|
9
9
|
{
|
|
@@ -1110,7 +1110,7 @@
|
|
|
1110
1110
|
"definition": "An ontology together with a set of individual instances of classes. The line between where the ontology ends and the knowledge base begins is a fine one.",
|
|
1111
1111
|
"plainLanguage": "The ontology is the empty form: which fields exist and what's allowed in them. The knowledge base is the form filled in with real things.",
|
|
1112
1112
|
"example": "The ontology defines the Wine class and its slots; adding 'Château Morgon Beaujolais' with body=light turns it into a knowledge base.",
|
|
1113
|
-
"inThisToolkit": "The same nodes.
|
|
1113
|
+
"inThisToolkit": "The same nodes.jsonl/edges.jsonl hold both. Instance nodes are the knowledge-base part.",
|
|
1114
1114
|
"origin": "source"
|
|
1115
1115
|
},
|
|
1116
1116
|
{
|
|
@@ -1437,7 +1437,7 @@
|
|
|
1437
1437
|
"definition": "The storage format used by this toolkit: nodes and edges that each carry a type label and a set of key/value properties.",
|
|
1438
1438
|
"plainLanguage": "Your ontology is saved as two JSON lists, nodes and edges, which is how graph databases like Neo4j and Neptune think. Classes, slots and instances are nodes. Structural links (IS_A, HAS_SLOT...) and relationship values ((wine)-[:MAKER]->(winery)) are edges. `okb export` writes the data the way a graph database expects it: instances as nodes labeled with their classes. It's still just the storage format, so model the meaning first (see principle.knowledge-level).",
|
|
1439
1439
|
"example": "{\"type\": \"Class\", \"id\": \"c.red-wine\", \"name\": \"RedWine\"} and {\"from\": \"c.red-wine\", \"type\": \"IS_A\", \"to\": \"c.wine\"}",
|
|
1440
|
-
"inThisToolkit": "nodes.
|
|
1440
|
+
"inThisToolkit": "nodes.jsonl and edges.jsonl in your ontology folder. See docs/FORMAT.md.",
|
|
1441
1441
|
"origin": "operational"
|
|
1442
1442
|
},
|
|
1443
1443
|
{
|
|
@@ -2359,6 +2359,25 @@
|
|
|
2359
2359
|
"id": "rat.scope-cq-coverage",
|
|
2360
2360
|
"explanation": "Competency questions are the litmus test: does the ontology contain enough information to answer them? NEEDS links make that test explicit and checkable."
|
|
2361
2361
|
},
|
|
2362
|
+
{
|
|
2363
|
+
"type": "Rule",
|
|
2364
|
+
"id": "rule.scope-cq-expected-answer",
|
|
2365
|
+
"key": "scope-cq-expected-answer",
|
|
2366
|
+
"modality": "SHOULD",
|
|
2367
|
+
"basis": "interpretive",
|
|
2368
|
+
"check": "heuristic",
|
|
2369
|
+
"severity": "warning",
|
|
2370
|
+
"fromStep": 8,
|
|
2371
|
+
"statement": "Each competency question should record the answer the ontology is expected to give.",
|
|
2372
|
+
"plainLanguage": "Write down what each question should return, so a script can tell you when a change stops the ontology from answering it.",
|
|
2373
|
+
"review": "Read each stored query next to its question: does it really ask what the question asks?",
|
|
2374
|
+
"fix": "`okb cq answer <n> --query '<JSON>' --expect A,B,C`."
|
|
2375
|
+
},
|
|
2376
|
+
{
|
|
2377
|
+
"type": "Rationale",
|
|
2378
|
+
"id": "rat.scope-cq-expected-answer",
|
|
2379
|
+
"explanation": "Competency questions are the litmus test, but a test nobody runs proves nothing. A stored query and its expected names turn each question into a regression check that `okb cq check` and `okb check` run on every change. okb can see that no answer is stored, not that the stored one is the right answer."
|
|
2380
|
+
},
|
|
2362
2381
|
{
|
|
2363
2382
|
"type": "Rule",
|
|
2364
2383
|
"id": "rule.scope-no-unneeded",
|
|
@@ -2508,6 +2527,24 @@
|
|
|
2508
2527
|
"id": "rat.struct-well-formed",
|
|
2509
2528
|
"explanation": "Every other check assumes the graph is structurally sound."
|
|
2510
2529
|
},
|
|
2530
|
+
{
|
|
2531
|
+
"type": "Rule",
|
|
2532
|
+
"id": "rule.struct-no-save-leftovers",
|
|
2533
|
+
"key": "struct-no-save-leftovers",
|
|
2534
|
+
"modality": "SHOULD",
|
|
2535
|
+
"basis": "operational",
|
|
2536
|
+
"check": "mechanical",
|
|
2537
|
+
"severity": "warning",
|
|
2538
|
+
"fromStep": 1,
|
|
2539
|
+
"statement": "An ontology folder should hold no leftovers of an interrupted save: no okb.json.tmp, nodes.jsonl.tmp or edges.jsonl.tmp, and no .okb.saving.tmp marker.",
|
|
2540
|
+
"plainLanguage": "A save that was killed halfway can leave new nodes next to old edges, and nothing else notices. Leftover temp files are the sign.",
|
|
2541
|
+
"fix": "If a command is running, wait for it. If the marker is there, run any okb command that changes this folder: it finishes the save. If only `*.tmp` files are there, run `okb validate` to check the real files agree (a save killed halfway can leave new nodes beside old edges), restore the folder from git or a backup if they don't, then delete the leftovers."
|
|
2542
|
+
},
|
|
2543
|
+
{
|
|
2544
|
+
"type": "Rationale",
|
|
2545
|
+
"id": "rat.struct-no-save-leftovers",
|
|
2546
|
+
"explanation": "A folder with leftovers can pass every other check while some of its files come from an older save. Older okb versions, and a save killed before it finished writing, leave temp files with no marker, so no load finishes them on its own."
|
|
2547
|
+
},
|
|
2511
2548
|
{
|
|
2512
2549
|
"type": "Rule",
|
|
2513
2550
|
"id": "rule.prov-verified",
|
|
@@ -3196,7 +3233,7 @@
|
|
|
3196
3233
|
"id",
|
|
3197
3234
|
"text"
|
|
3198
3235
|
],
|
|
3199
|
-
"description": "A question the ontology must answer. status: draft | answerable."
|
|
3236
|
+
"description": "A question the ontology must answer. status: draft | answerable. answer (`okb cq answer`): {query, expect[], match: exact | includes}, a declarative find/traverse/slots query and the names it must return, which `okb cq check` evaluates."
|
|
3200
3237
|
},
|
|
3201
3238
|
{
|
|
3202
3239
|
"type": "NodeType",
|
|
@@ -3230,7 +3267,7 @@
|
|
|
3230
3267
|
"id",
|
|
3231
3268
|
"name"
|
|
3232
3269
|
],
|
|
3233
|
-
"description": "description, synonyms[], abstract, terminological, fixedValues{slotId: value}, defaults{slotId: value}, facetOverrides{slotId: {allowedValues, minCardinality, maxCardinality}}."
|
|
3270
|
+
"description": "description, formerNames[] (earlier names, set by okb rename), synonyms[], abstract, terminological, fixedValues{slotId: value}, defaults{slotId: value}, facetOverrides{slotId: {allowedValues, minCardinality, maxCardinality}}."
|
|
3234
3271
|
},
|
|
3235
3272
|
{
|
|
3236
3273
|
"type": "NodeType",
|
|
@@ -3241,7 +3278,7 @@
|
|
|
3241
3278
|
"id",
|
|
3242
3279
|
"name"
|
|
3243
3280
|
],
|
|
3244
|
-
"description": "description, valueType (String|Integer|Float|Number|Boolean|Enumerated|Instance), allowedValues[], cardinality (single|multiple), minCardinality, maxCardinality, default, relType (Instance slots only: the edge type its values are stored as), appliesToRules (Boolean, property slots only: the slot applies to every Rule)."
|
|
3281
|
+
"description": "description, formerNames[], formerRelTypes[] (edge types before renames), valueType (String|Integer|Float|Number|Boolean|Enumerated|Instance), allowedValues[], cardinality (single|multiple), minCardinality, maxCardinality, default, relType (Instance slots only: the edge type its values are stored as), appliesToRules (Boolean, property slots only: the slot applies to every Rule)."
|
|
3245
3282
|
},
|
|
3246
3283
|
{
|
|
3247
3284
|
"type": "NodeType",
|
|
@@ -3252,7 +3289,7 @@
|
|
|
3252
3289
|
"id",
|
|
3253
3290
|
"name"
|
|
3254
3291
|
],
|
|
3255
|
-
"description": "description, values{slotId: value | [values]} for property (non-Instance) slots. Relationship values are edges."
|
|
3292
|
+
"description": "description, formerNames[], values{slotId: value | [values]} for property (non-Instance) slots. Relationship values are edges."
|
|
3256
3293
|
},
|
|
3257
3294
|
{
|
|
3258
3295
|
"type": "NodeType",
|
|
@@ -3275,7 +3312,7 @@
|
|
|
3275
3312
|
"id",
|
|
3276
3313
|
"title"
|
|
3277
3314
|
],
|
|
3278
|
-
"description": "Provenance: a document content was extracted from (`okb source add`). localPath (checked by okb validate), format (markdown | pdf | text), url (rendered page), repoUrl (GitHub file URL, for line links), meta (markdown frontmatter)."
|
|
3315
|
+
"description": "Provenance: a document content was extracted from (`okb source add`). localPath (checked by okb validate), format (markdown | pdf | text), url (rendered page), repoUrl (GitHub file URL, for line links), meta (markdown frontmatter), blocks[] (hash, kind, headingPath, rowKey, preview of each quotable block the KB last saw, so `okb source refresh --all` can list new and changed blocks)."
|
|
3279
3316
|
},
|
|
3280
3317
|
{
|
|
3281
3318
|
"type": "NodeType",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ontology-kit/okb",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-alpha.133",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "A toolkit for building knowledge graphs with guardrails: a checked file format, rules from a meta-KB, provenance down to verbatim quotes, and skills that drive it.",
|
|
6
6
|
"homepage": "https://ontology-kit.dev",
|
|
@@ -31,6 +31,8 @@
|
|
|
31
31
|
"bin",
|
|
32
32
|
"dist",
|
|
33
33
|
"meta-kb/data",
|
|
34
|
+
"schema",
|
|
35
|
+
"templates",
|
|
34
36
|
"!meta-kb/README.md",
|
|
35
37
|
"skills",
|
|
36
38
|
"README.md",
|
|
@@ -42,6 +44,7 @@
|
|
|
42
44
|
"development": "./src/cli.ts",
|
|
43
45
|
"default": "./dist/cli.js"
|
|
44
46
|
},
|
|
47
|
+
"./schema/*": "./schema/*",
|
|
45
48
|
"./package.json": "./package.json"
|
|
46
49
|
},
|
|
47
50
|
"bin": {
|
|
@@ -52,13 +55,14 @@
|
|
|
52
55
|
},
|
|
53
56
|
"devDependencies": {
|
|
54
57
|
"@types/node": "^26.6.6",
|
|
55
|
-
"
|
|
58
|
+
"ajv": "^8.20.0",
|
|
59
|
+
"typescript": "^7.0.2"
|
|
56
60
|
},
|
|
57
61
|
"optionalDependencies": {
|
|
58
62
|
"pdfjs-dist": "^6.3.289"
|
|
59
63
|
},
|
|
60
64
|
"dependencies": {
|
|
61
|
-
"@ontology-kit/
|
|
65
|
+
"@ontology-kit/reader": "0.3.0-alpha.133",
|
|
62
66
|
"yaml": "^2.8.0"
|
|
63
67
|
},
|
|
64
68
|
"scripts": {
|
|
@@ -68,7 +72,8 @@
|
|
|
68
72
|
"docs": "node src/gendocs.ts",
|
|
69
73
|
"example": "node examples/build-wine.ts && node examples/build-espresso.ts",
|
|
70
74
|
"typecheck": "tsc",
|
|
75
|
+
"bench": "node scripts/bench-scale.ts",
|
|
71
76
|
"test": "node --test --test-concurrency=1 \"tests/*.test.ts\"",
|
|
72
|
-
"build": "pnpm --filter @ontology-kit/
|
|
77
|
+
"build": "pnpm --filter @ontology-kit/reader run build && rm -rf dist && tsc -p tsconfig.build.json && node ../../scripts/rewrite-dts.ts"
|
|
73
78
|
}
|
|
74
79
|
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://ontology-kit.dev/schema/okb-lpg-3/edge.schema.json",
|
|
4
|
+
"title": "An okb edge (okb-lpg/3): one line of edges.jsonl",
|
|
5
|
+
"description": "An edge is {from, type, to} plus optional properties. The type is one of the reserved types below or the relType of a relationship slot (UPPER_SNAKE case). Whether the ends exist and have the right node types is checked by `okb validate`.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"required": [
|
|
8
|
+
"from",
|
|
9
|
+
"type",
|
|
10
|
+
"to"
|
|
11
|
+
],
|
|
12
|
+
"properties": {
|
|
13
|
+
"from": {
|
|
14
|
+
"type": "string",
|
|
15
|
+
"minLength": 1
|
|
16
|
+
},
|
|
17
|
+
"type": {
|
|
18
|
+
"type": "string",
|
|
19
|
+
"pattern": "^[A-Z0-9][A-Z0-9_]*$",
|
|
20
|
+
"examples": [
|
|
21
|
+
"IS_A",
|
|
22
|
+
"INSTANCE_OF",
|
|
23
|
+
"HAS_SLOT",
|
|
24
|
+
"RANGE",
|
|
25
|
+
"INVERSE_OF",
|
|
26
|
+
"DISJOINT_WITH",
|
|
27
|
+
"NEEDS",
|
|
28
|
+
"BECAME",
|
|
29
|
+
"ABOUT",
|
|
30
|
+
"CITES",
|
|
31
|
+
"PART_OF",
|
|
32
|
+
"GOVERNS",
|
|
33
|
+
"REFINES",
|
|
34
|
+
"FULFILLS"
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
"to": {
|
|
38
|
+
"type": "string",
|
|
39
|
+
"minLength": 1
|
|
40
|
+
},
|
|
41
|
+
"rule": {
|
|
42
|
+
"type": "string",
|
|
43
|
+
"description": "The Rule node whose quote and verification justify this link."
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"allOf": [
|
|
47
|
+
{
|
|
48
|
+
"if": {
|
|
49
|
+
"properties": {
|
|
50
|
+
"type": {
|
|
51
|
+
"const": "REFINES"
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"required": [
|
|
55
|
+
"type"
|
|
56
|
+
]
|
|
57
|
+
},
|
|
58
|
+
"then": {
|
|
59
|
+
"properties": {
|
|
60
|
+
"adds": {
|
|
61
|
+
"type": "string"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"required": []
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
}
|