@ontology-kit/okb 0.1.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.
Files changed (74) hide show
  1. package/README.md +1 -1
  2. package/dist/check.d.ts +43 -0
  3. package/dist/check.js +83 -0
  4. package/dist/checks.d.ts +1 -1
  5. package/dist/checks.js +4 -4
  6. package/dist/cli.js +159 -45
  7. package/dist/clock.js +1 -1
  8. package/dist/commands.js +96 -2
  9. package/dist/diff.d.ts +85 -0
  10. package/dist/diff.js +323 -0
  11. package/dist/export.d.ts +1 -1
  12. package/dist/export.js +1 -1
  13. package/dist/families.d.ts +1 -1
  14. package/dist/families.js +1 -1
  15. package/dist/help.d.ts +1 -1
  16. package/dist/help.js +9 -2
  17. package/dist/kbdocs.d.ts +18 -0
  18. package/dist/kbdocs.js +393 -0
  19. package/dist/metakb.d.ts +1 -1
  20. package/dist/metakb.js +1 -1
  21. package/dist/naming.d.ts +2 -2
  22. package/dist/naming.js +2 -2
  23. package/dist/ontology-ref.d.ts +20 -0
  24. package/dist/ontology-ref.js +108 -0
  25. package/dist/ops/admin.d.ts +1 -1
  26. package/dist/ops/admin.js +24 -7
  27. package/dist/ops/classes.d.ts +1 -1
  28. package/dist/ops/classes.js +13 -5
  29. package/dist/ops/instances.d.ts +2 -1
  30. package/dist/ops/instances.js +7 -1
  31. package/dist/ops/links.d.ts +1 -1
  32. package/dist/ops/links.js +1 -1
  33. package/dist/ops/naming.d.ts +1 -1
  34. package/dist/ops/naming.js +3 -1
  35. package/dist/ops/scope.d.ts +5 -1
  36. package/dist/ops/scope.js +19 -1
  37. package/dist/ops/slots.d.ts +1 -1
  38. package/dist/ops/slots.js +15 -2
  39. package/dist/ops/values.d.ts +1 -1
  40. package/dist/ops/values.js +5 -1
  41. package/dist/provenance.d.ts +4 -2
  42. package/dist/provenance.js +58 -17
  43. package/dist/release.d.ts +48 -0
  44. package/dist/release.js +318 -0
  45. package/dist/render.d.ts +4 -1
  46. package/dist/render.js +21 -2
  47. package/dist/resync.d.ts +98 -0
  48. package/dist/resync.js +234 -0
  49. package/dist/review.d.ts +1 -1
  50. package/dist/review.js +1 -1
  51. package/dist/reviewdocs.d.ts +42 -0
  52. package/dist/reviewdocs.js +263 -0
  53. package/dist/skills.js +1 -1
  54. package/dist/status.d.ts +1 -1
  55. package/dist/status.js +1 -1
  56. package/dist/types.d.ts +1 -1
  57. package/dist/types.js +1 -1
  58. package/dist/verifynote.d.ts +18 -0
  59. package/dist/verifynote.js +92 -0
  60. package/meta-kb/data/manifest.json +2 -2
  61. package/meta-kb/data/nodes.json +8 -8
  62. package/package.json +7 -3
  63. package/schema/edge.schema.json +68 -0
  64. package/schema/edges.schema.json +9 -0
  65. package/schema/node.schema.json +893 -0
  66. package/schema/nodes.schema.json +9 -0
  67. package/schema/okb.schema.json +41 -0
  68. package/skills/build-domain-kb-from-docs/SKILL.md +20 -2
  69. package/skills/ontology-coach/SKILL.md +6 -2
  70. package/skills/ontology-maintainer/SKILL.md +152 -0
  71. package/skills/ontology-review/SKILL.md +3 -1
  72. package/skills/ontology-signoff/SKILL.md +182 -0
  73. package/templates/okb-check.yml +132 -0
  74. package/templates/pull_request_template.md +16 -0
@@ -0,0 +1,92 @@
1
+ const MODALITY = /\b(MUST\s+NOT|SHOULD\s+NOT|MUST|SHOULD|MAY)\b/gi;
2
+ const keyword = (m) => m.toUpperCase().replace(/\s+/g, " ");
3
+ const NUMBER = /\d+(?:[.,]\d+)*/g;
4
+ const WORD = /[\p{L}'-]+/gu;
5
+ /** Strongest first, so a drop in rank reads as narrowing. */
6
+ const RANK = ["MUST NOT", "MUST", "SHOULD NOT", "SHOULD", "MAY"];
7
+ /** A diff longer than this is a rewrite, and a list of words wouldn't name it. */
8
+ const MAX_WORDS = 4;
9
+ const found = (text, re) => [...text.matchAll(re)].map((m) => m[0]);
10
+ const quote = (words) => words.map((w) => `"${w}"`).join(", ");
11
+ /** Items in `a` that `b` doesn't have, counting repeats. */
12
+ function without(a, b) {
13
+ const left = [...b];
14
+ return a.filter((x) => {
15
+ const i = left.indexOf(x);
16
+ if (i < 0)
17
+ return true;
18
+ left.splice(i, 1);
19
+ return false;
20
+ });
21
+ }
22
+ /** Words minus the modality and number tokens, which the other parts of the suggestion name. */
23
+ function plainWords(text) {
24
+ return found(text.replace(MODALITY, " ").replace(NUMBER, " "), WORD).map((w) => w.toLowerCase());
25
+ }
26
+ /**
27
+ * One sentence naming what changed: a modality, a number, or a few words. Null when the difference
28
+ * can't be named this way (a rewording, or a change too big to list), so the caller falls back to the
29
+ * generic tip.
30
+ */
31
+ export function suggestNote(original, corrected) {
32
+ const parts = [];
33
+ const m0 = found(original, MODALITY).map(keyword);
34
+ const m1 = found(corrected, MODALITY).map(keyword);
35
+ if (m0.length && m0.length === m1.length) {
36
+ const i = m0.findIndex((m, k) => m !== m1[k]);
37
+ if (i >= 0) {
38
+ const [r0, r1] = [RANK.indexOf(m0[i]), RANK.indexOf(m1[i])];
39
+ // MUST NOT to MUST (or the other way) flips the meaning; it is neither narrower nor stronger.
40
+ const flips = m0[i].endsWith("NOT") !== m1[i].endsWith("NOT");
41
+ parts.push(`${flips ? "changed" : r1 > r0 ? "narrowed" : "strengthened"} ${m0[i]} to ${m1[i]}`);
42
+ }
43
+ }
44
+ else if (m0.join() !== m1.join())
45
+ return null;
46
+ const n0 = found(original, NUMBER);
47
+ const n1 = found(corrected, NUMBER);
48
+ const goneN = without(n0, n1);
49
+ const newN = without(n1, n0);
50
+ if (goneN.length && goneN.length === newN.length)
51
+ parts.push(`changed ${goneN.join(", ")} to ${newN.join(", ")}`);
52
+ else {
53
+ if (goneN.length)
54
+ parts.push(`removed ${goneN.join(", ")}`);
55
+ if (newN.length)
56
+ parts.push(`added ${newN.join(", ")}`);
57
+ }
58
+ const w0 = plainWords(original);
59
+ const w1 = plainWords(corrected);
60
+ const goneW = without(w0, w1);
61
+ const newW = without(w1, w0);
62
+ if (goneW.length > MAX_WORDS || newW.length > MAX_WORDS)
63
+ return null;
64
+ if (goneW.length && newW.length && goneW.length === newW.length && goneW.length <= 2)
65
+ parts.push(`replaced ${quote(goneW)} with ${quote(newW)}`);
66
+ else {
67
+ if (goneW.length)
68
+ parts.push(`removed ${quote(goneW)}`);
69
+ if (newW.length)
70
+ parts.push(`added ${quote(newW)}`);
71
+ }
72
+ return parts.length ? parts.join("; ") : null;
73
+ }
74
+ /**
75
+ * The one modality a statement states in capitals (`... SHOULD be ...` is SHOULD, `MUST NOT` is MUST_NOT), or null
76
+ * when it states none or more than one. Lower-case "may" or "should" is ordinary prose and doesn't count.
77
+ */
78
+ export function statedModality(statement) {
79
+ const found = new Set([...statement.matchAll(/\b(MUST\s+NOT|SHOULD\s+NOT|MUST|SHOULD|MAY)\b/g)].map((m) => m[1].replace(/\s+/g, "_")));
80
+ return found.size === 1 ? [...found][0] : null;
81
+ }
82
+ /** A double-quoted shell argument. */
83
+ export const shellQuote = (s) => `"${s.replace(/(["\\$`])/g, "\\$1")}"`;
84
+ export const GENERIC_NOTE_TIP = 'Tip: add a note so a reviewer sees why, not just the verdict: --note "<one sentence naming the word or number you changed>". Skip it when the correction speaks for itself.';
85
+ export const UNSUPPORTED_NOTE_TIP = 'Tip: add --note "<which part of the statement the quote doesn\'t support>". One sentence naming the word or claim; don\'t restate UNSUPPORTED.';
86
+ /** Lines to print after OVERREACH with no --note. */
87
+ export function overreachNoteTips(id, original, corrected, extra) {
88
+ const s = suggestNote(original, corrected);
89
+ if (!s)
90
+ return [GENERIC_NOTE_TIP];
91
+ return [`Suggested note: ${s}`, `To store it: okb verify ${id} --status OVERREACH --corrected ${shellQuote(corrected)} --note ${shellQuote(s)}${extra}`];
92
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
- "version": "2.4.2",
3
- "formatVersion": "okb-lpg/2",
2
+ "version": "2.6.3",
3
+ "formatVersion": "okb-lpg/3",
4
4
  "nodeCounts": {
5
5
  "MetaKB": 1,
6
6
  "Source": 2,
@@ -2,8 +2,8 @@
2
2
  {
3
3
  "type": "MetaKB",
4
4
  "id": "metakb",
5
- "version": "2.4.2",
6
- "formatVersion": "okb-lpg/2",
5
+ "version": "2.6.3",
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.json/edges.json hold both. Instance nodes are the knowledge-base part.",
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.json and edges.json in your ontology folder. See docs/FORMAT.md.",
1440
+ "inThisToolkit": "nodes.jsonl and edges.jsonl in your ontology folder. See docs/FORMAT.md.",
1441
1441
  "origin": "operational"
1442
1442
  },
1443
1443
  {
@@ -3230,7 +3230,7 @@
3230
3230
  "id",
3231
3231
  "name"
3232
3232
  ],
3233
- "description": "description, synonyms[], abstract, terminological, fixedValues{slotId: value}, defaults{slotId: value}, facetOverrides{slotId: {allowedValues, minCardinality, maxCardinality}}."
3233
+ "description": "description, formerNames[] (earlier names, set by okb rename), synonyms[], abstract, terminological, fixedValues{slotId: value}, defaults{slotId: value}, facetOverrides{slotId: {allowedValues, minCardinality, maxCardinality}}."
3234
3234
  },
3235
3235
  {
3236
3236
  "type": "NodeType",
@@ -3241,7 +3241,7 @@
3241
3241
  "id",
3242
3242
  "name"
3243
3243
  ],
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)."
3244
+ "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
3245
  },
3246
3246
  {
3247
3247
  "type": "NodeType",
@@ -3252,7 +3252,7 @@
3252
3252
  "id",
3253
3253
  "name"
3254
3254
  ],
3255
- "description": "description, values{slotId: value | [values]} for property (non-Instance) slots. Relationship values are edges."
3255
+ "description": "description, formerNames[], values{slotId: value | [values]} for property (non-Instance) slots. Relationship values are edges."
3256
3256
  },
3257
3257
  {
3258
3258
  "type": "NodeType",
@@ -3275,7 +3275,7 @@
3275
3275
  "id",
3276
3276
  "title"
3277
3277
  ],
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)."
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), 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
3279
  },
3280
3280
  {
3281
3281
  "type": "NodeType",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ontology-kit/okb",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
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",
58
+ "ajv": "^8.20.0",
55
59
  "typescript": "^5.9.0"
56
60
  },
57
61
  "optionalDependencies": {
58
62
  "pdfjs-dist": "^6.3.289"
59
63
  },
60
64
  "dependencies": {
61
- "@ontology-kit/format": "0.1.0",
65
+ "@ontology-kit/reader": "0.2.0",
62
66
  "yaml": "^2.8.0"
63
67
  },
64
68
  "scripts": {
@@ -69,6 +73,6 @@
69
73
  "example": "node examples/build-wine.ts && node examples/build-espresso.ts",
70
74
  "typecheck": "tsc",
71
75
  "test": "node --test --test-concurrency=1 \"tests/*.test.ts\"",
72
- "build": "pnpm --filter @ontology-kit/format run build && rm -rf dist && tsc -p tsconfig.build.json && node ../../scripts/rewrite-dts.ts"
76
+ "build": "pnpm --filter @ontology-kit/reader run build && rm -rf dist && tsc -p tsconfig.build.json && node ../../scripts/rewrite-dts.ts"
73
77
  }
74
78
  }
@@ -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
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://ontology-kit.dev/schema/okb-lpg-3/edges.schema.json",
4
+ "title": "An older edges.json: an array of edges",
5
+ "type": "array",
6
+ "items": {
7
+ "$ref": "edge.schema.json"
8
+ }
9
+ }