@ontology-kit/format 0.0.0-stage → 0.1.0-bootstrap.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/LICENSE +9 -0
- package/README.md +35 -2
- package/dist/edge-types.d.ts +18 -0
- package/dist/edge-types.js +26 -0
- package/dist/errors.d.ts +3 -0
- package/dist/errors.js +3 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +16 -0
- package/dist/model.d.ts +96 -0
- package/dist/model.js +501 -0
- package/dist/naming.d.ts +25 -0
- package/dist/naming.js +50 -0
- package/dist/registry.d.ts +4 -0
- package/dist/registry.js +39 -0
- package/dist/relationships.d.ts +30 -0
- package/dist/relationships.js +205 -0
- package/dist/types.d.ts +225 -0
- package/dist/types.js +13 -0
- package/package.json +49 -3
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How relationship values are stored. This is the one module that knows it.
|
|
3
|
+
*
|
|
4
|
+
* A slot with valueType "Instance" is a relationship. Its values are edges whose type
|
|
5
|
+
* is the slot's relType, the slot name in UPPER_SNAKE case: (wine)-[:MAKER]->(winery).
|
|
6
|
+
* An edge from a class is a fixed class-level value its members inherit.
|
|
7
|
+
*
|
|
8
|
+
* Inverse slots are one relationship read from both ends, stored once. The slot on the
|
|
9
|
+
* `from` side of INVERSE_OF is the primary (stored) direction; its inverse reads the
|
|
10
|
+
* same edges backwards, so `produces` = incoming MAKER edges. Edge-property
|
|
11
|
+
* declarations live on the primary slot.
|
|
12
|
+
*
|
|
13
|
+
* Everything that creates, retypes, moves or deletes those edges goes through here,
|
|
14
|
+
* so a change to the storage scheme is a change to this file.
|
|
15
|
+
*/
|
|
16
|
+
import { OkbError } from "./errors.js";
|
|
17
|
+
import * as naming from "./naming.js";
|
|
18
|
+
import { isStructuralEdgeType } from "./edge-types.js";
|
|
19
|
+
/** An edge's own properties (everything except from/type/to). */
|
|
20
|
+
export function edgeProps(e) {
|
|
21
|
+
const { from: _f, type: _t, to: _to, ...rest } = e;
|
|
22
|
+
return rest;
|
|
23
|
+
}
|
|
24
|
+
export class Relationships {
|
|
25
|
+
ont;
|
|
26
|
+
constructor(ont) {
|
|
27
|
+
this.ont = ont;
|
|
28
|
+
}
|
|
29
|
+
/** The slot that stores a relationship's edges: the slot itself, or the one it's the inverse of. */
|
|
30
|
+
primary(slotId) {
|
|
31
|
+
return this.ont.sources(slotId, "INVERSE_OF")[0] ?? slotId;
|
|
32
|
+
}
|
|
33
|
+
isPrimary(slotId) {
|
|
34
|
+
return this.primary(slotId) === slotId;
|
|
35
|
+
}
|
|
36
|
+
spec(slotId) {
|
|
37
|
+
const s = this.ont.get(slotId);
|
|
38
|
+
if (s?.type !== "Slot" || s.valueType !== "Instance")
|
|
39
|
+
return null;
|
|
40
|
+
const primary = this.primary(slotId);
|
|
41
|
+
const p = this.ont.get(primary);
|
|
42
|
+
if (p?.type !== "Slot" || !p.relType)
|
|
43
|
+
return null;
|
|
44
|
+
return { type: p.relType, reverse: primary !== slotId };
|
|
45
|
+
}
|
|
46
|
+
/** Edge types that hold relationship values, mapped to the slot that stores each. */
|
|
47
|
+
edgeTypes() {
|
|
48
|
+
const m = new Map();
|
|
49
|
+
for (const s of this.ont.ofType("Slot"))
|
|
50
|
+
if (isRelationship(s) && this.isPrimary(s.id))
|
|
51
|
+
m.set(s.relType, s.id);
|
|
52
|
+
return m;
|
|
53
|
+
}
|
|
54
|
+
/** The nodes `id` is linked to through a relationship slot (either direction). */
|
|
55
|
+
values(id, slotId) {
|
|
56
|
+
const spec = this.spec(slotId);
|
|
57
|
+
if (!spec)
|
|
58
|
+
return [];
|
|
59
|
+
return spec.reverse ? this.ont.sources(id, spec.type) : this.ont.targets(id, spec.type);
|
|
60
|
+
}
|
|
61
|
+
/** The stored edge behind one relationship value, whichever end it's read from. */
|
|
62
|
+
edge(id, slotId, target) {
|
|
63
|
+
const spec = this.spec(slotId);
|
|
64
|
+
if (!spec)
|
|
65
|
+
return undefined;
|
|
66
|
+
const [from, to] = spec.reverse ? [target, id] : [id, target];
|
|
67
|
+
return this.ont.outEdges(from, spec.type).find((e) => e.to === to);
|
|
68
|
+
}
|
|
69
|
+
/** Relationship slots `id` has any values for (either direction). */
|
|
70
|
+
slotsWithValues(id) {
|
|
71
|
+
return this.ont.ofType("Slot").filter((s) => this.values(id, s.id).length > 0).map((s) => s.id);
|
|
72
|
+
}
|
|
73
|
+
/** The edge properties a relationship's edges can carry (declared on its primary slot). */
|
|
74
|
+
edgeProperties(slotId) {
|
|
75
|
+
const p = this.ont.get(this.primary(slotId));
|
|
76
|
+
return (p?.type === "Slot" && p.edgeProperties) || [];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Link `id` to `target` through a relationship slot. There's at most one edge per
|
|
80
|
+
* (from, relationship, to); `props` (edge properties, or `rule`) are merged into it.
|
|
81
|
+
* Returns whether a new edge was created.
|
|
82
|
+
*/
|
|
83
|
+
/** @internal */
|
|
84
|
+
link(id, slotId, target, props = {}) {
|
|
85
|
+
const existing = this.edge(id, slotId, target);
|
|
86
|
+
if (existing) {
|
|
87
|
+
Object.assign(existing, props);
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
const spec = this.spec(slotId);
|
|
91
|
+
if (!spec)
|
|
92
|
+
throw new OkbError(`${this.ont.label(slotId)} isn't a relationship.`);
|
|
93
|
+
const [from, to] = spec.reverse ? [target, id] : [id, target];
|
|
94
|
+
this.ont.addEdge(from, spec.type, to, props);
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
/** @internal */
|
|
98
|
+
unlink(id, slotId, target) {
|
|
99
|
+
const spec = this.spec(slotId);
|
|
100
|
+
if (!spec)
|
|
101
|
+
return;
|
|
102
|
+
const [from, to] = spec.reverse ? [target, id] : [id, target];
|
|
103
|
+
this.ont.removeEdges((e) => e.type === spec.type && e.from === from && e.to === to);
|
|
104
|
+
}
|
|
105
|
+
/** The edge type a relationship called `name` would be stored as; refuses structural and taken types. */
|
|
106
|
+
/** @internal */
|
|
107
|
+
typeFor(name, slotId) {
|
|
108
|
+
const t = naming.relType(name);
|
|
109
|
+
if (isStructuralEdgeType(t))
|
|
110
|
+
throw new OkbError(`A relationship called '${name}' would be stored as ${t}, which okb uses for its own structure. Pick another name.`);
|
|
111
|
+
const other = this.ont.ofType("Slot").find((x) => x.id !== slotId && x.relType === t);
|
|
112
|
+
if (other)
|
|
113
|
+
throw new OkbError(`'${name}' would be stored as ${t}, which ${other.name} already uses. Pick another name.`);
|
|
114
|
+
return t;
|
|
115
|
+
}
|
|
116
|
+
/** A slot's value type became Instance: give it an edge type, unless it already has one. */
|
|
117
|
+
/** @internal */
|
|
118
|
+
becomeRelationship(slot) {
|
|
119
|
+
if (!slot.relType)
|
|
120
|
+
slot.relType = this.typeFor(slot.name, slot.id);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* A relationship's value type changed to a literal type: its stored links and its
|
|
124
|
+
* inverse pairing go. Returns the edge type and how many edges of it there were.
|
|
125
|
+
*/
|
|
126
|
+
/** @internal */
|
|
127
|
+
becomeProperty(slot) {
|
|
128
|
+
const type = slot.relType;
|
|
129
|
+
const links = type ? this.ont.edgesOf(type).length : 0;
|
|
130
|
+
if (type && this.isPrimary(slot.id))
|
|
131
|
+
this.ont.removeEdges((e) => e.type === type);
|
|
132
|
+
this.ont.removeEdges((e) => e.type === "INVERSE_OF" && (e.from === slot.id || e.to === slot.id));
|
|
133
|
+
delete slot.relType;
|
|
134
|
+
return { type, links };
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Make `b` the inverse of `a`: `a` stays the stored direction, so any edges stored
|
|
138
|
+
* under b's own type move onto a's type, reversed (merging properties where the
|
|
139
|
+
* same link already exists). Returns how many edges moved.
|
|
140
|
+
*/
|
|
141
|
+
/** @internal */
|
|
142
|
+
declareInverse(a, b) {
|
|
143
|
+
const moved = this.ont.edgesOf(b.relType);
|
|
144
|
+
this.ont.removeEdges((e) => e.type === b.relType);
|
|
145
|
+
for (const e of moved) {
|
|
146
|
+
const existing = this.ont.outEdges(e.to, a.relType).find((x) => x.to === e.from);
|
|
147
|
+
if (existing)
|
|
148
|
+
Object.assign(existing, edgeProps(e));
|
|
149
|
+
else
|
|
150
|
+
this.ont.addEdge(e.to, a.relType, e.from, edgeProps(e));
|
|
151
|
+
}
|
|
152
|
+
const declared = a.edgeProperties ?? [];
|
|
153
|
+
if (b.edgeProperties?.length)
|
|
154
|
+
a.edgeProperties = [...declared, ...b.edgeProperties.filter((p) => !declared.some((q) => q.name === p.name))];
|
|
155
|
+
this.ont.addEdge(a.id, "INVERSE_OF", b.id);
|
|
156
|
+
return moved.length;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* A relationship is being renamed: claim the new edge type and, if this slot stores
|
|
160
|
+
* the edges, retype them. Returns the change when stored edges were retyped.
|
|
161
|
+
*/
|
|
162
|
+
/** @internal */
|
|
163
|
+
rename(slot, name) {
|
|
164
|
+
const t = this.typeFor(name, slot.id);
|
|
165
|
+
if (t === slot.relType)
|
|
166
|
+
return null;
|
|
167
|
+
const from = slot.relType;
|
|
168
|
+
slot.relType = t;
|
|
169
|
+
if (!this.isPrimary(slot.id))
|
|
170
|
+
return null;
|
|
171
|
+
if (from)
|
|
172
|
+
this.ont.retypeEdges(from, t);
|
|
173
|
+
return { from, to: t };
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* A relationship slot is about to be removed. If it stores the edges and has an
|
|
177
|
+
* inverse, the inverse becomes the stored direction and keeps every link;
|
|
178
|
+
* otherwise its stored edges are deleted. Returns what was kept, if anything.
|
|
179
|
+
*/
|
|
180
|
+
/** @internal */
|
|
181
|
+
drop(slot) {
|
|
182
|
+
const type = slot.relType;
|
|
183
|
+
if (!type || !this.isPrimary(slot.id))
|
|
184
|
+
return null;
|
|
185
|
+
const inv = isRelationship(slot) ? this.ont.targets(slot.id, "INVERSE_OF")[0] : undefined;
|
|
186
|
+
if (!inv) {
|
|
187
|
+
this.ont.removeEdges((e) => e.type === type);
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
const invNode = this.ont.require(inv, "Slot");
|
|
191
|
+
if (!isRelationship(invNode))
|
|
192
|
+
throw new OkbError(`${slot.name}'s inverse ${invNode.name} isn't a relationship. Fix it (okb slot set ${invNode.name} --type Instance) or remove the inverse first.`);
|
|
193
|
+
const moved = this.ont.edgesOf(type);
|
|
194
|
+
this.ont.removeEdges((e) => e.type === type || (e.type === "INVERSE_OF" && e.from === slot.id));
|
|
195
|
+
for (const e of moved)
|
|
196
|
+
this.ont.addEdge(e.to, invNode.relType, e.from, edgeProps(e));
|
|
197
|
+
if (slot.edgeProperties?.length && !invNode.edgeProperties?.length)
|
|
198
|
+
invNode.edgeProperties = slot.edgeProperties;
|
|
199
|
+
return { links: moved.length, type: invNode.relType, name: invNode.name };
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
export function isRelationship(s) {
|
|
203
|
+
const slot = s;
|
|
204
|
+
return slot?.type === "Slot" && slot.valueType === "Instance" && Boolean(slot.relType);
|
|
205
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types for the okb file format (okb-lpg/2). The node and edge registry
|
|
3
|
+
* is meta-kb/src/format.yaml; docs/FORMAT.md describes each property.
|
|
4
|
+
*
|
|
5
|
+
* Files can be edited by hand, so what's loaded is only *expected* to match these
|
|
6
|
+
* types. The struct-well-formed rule reports what doesn't, and code that walks
|
|
7
|
+
* edges should still expect ids that point nowhere (use Ontology.require).
|
|
8
|
+
*/
|
|
9
|
+
/** An untyped graph node: the meta-KB, and okb files before they're checked. */
|
|
10
|
+
export interface GraphNode {
|
|
11
|
+
id: string;
|
|
12
|
+
type: string;
|
|
13
|
+
[prop: string]: any;
|
|
14
|
+
}
|
|
15
|
+
/** An edge. Anything besides from/type/to is an edge property (see OkbEdgeProps). */
|
|
16
|
+
export interface GraphEdge {
|
|
17
|
+
from: string;
|
|
18
|
+
type: string;
|
|
19
|
+
to: string;
|
|
20
|
+
[prop: string]: unknown;
|
|
21
|
+
}
|
|
22
|
+
export interface Manifest {
|
|
23
|
+
format: string;
|
|
24
|
+
currentStep: number;
|
|
25
|
+
name?: string;
|
|
26
|
+
created?: string;
|
|
27
|
+
metaKbVersion?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface Conventions {
|
|
30
|
+
classCase: string;
|
|
31
|
+
slotCase: string;
|
|
32
|
+
instanceCase: string | null;
|
|
33
|
+
classNumber: "singular" | "plural";
|
|
34
|
+
slotAffix: "none" | "has-prefix" | "of-suffix";
|
|
35
|
+
/** "chosen" once the user ran `okb convention`; "default" when okb filled it in. */
|
|
36
|
+
source?: "chosen" | "default";
|
|
37
|
+
}
|
|
38
|
+
export declare const VALUE_TYPES: readonly ["String", "Integer", "Float", "Number", "Boolean", "Enumerated", "Instance"];
|
|
39
|
+
export type ValueType = (typeof VALUE_TYPES)[number];
|
|
40
|
+
/** Value types an edge property can have: everything except links to other things. */
|
|
41
|
+
export type LiteralType = Exclude<ValueType, "Instance">;
|
|
42
|
+
/** A stored property value (Instance.values, Class.fixedValues/defaults, Slot.default). */
|
|
43
|
+
export type Literal = string | number | boolean;
|
|
44
|
+
export type StoredValue = Literal | Literal[];
|
|
45
|
+
export declare const DISPOSITIONS: readonly ["undecided", "class", "slot", "instance", "value", "synonym", "out-of-scope"];
|
|
46
|
+
export type Disposition = (typeof DISPOSITIONS)[number];
|
|
47
|
+
export declare const CARDINALITIES: readonly ["single", "multiple"];
|
|
48
|
+
export type Cardinality = (typeof CARDINALITIES)[number];
|
|
49
|
+
export type VerificationStatus = (typeof VERIFICATION_STATUSES)[number];
|
|
50
|
+
export interface Verification {
|
|
51
|
+
status: VerificationStatus;
|
|
52
|
+
checkedAgainst?: string[];
|
|
53
|
+
note?: string;
|
|
54
|
+
/** Set by `okb verify --approve`: the status a person approved it from. */
|
|
55
|
+
approvedAfter?: VerificationStatus;
|
|
56
|
+
}
|
|
57
|
+
/** Fields the extraction pipeline adds to nodes drafted from a document. */
|
|
58
|
+
export interface ExtractedFields {
|
|
59
|
+
extracted?: boolean;
|
|
60
|
+
verification?: Verification;
|
|
61
|
+
extractionConfidence?: "verbatim" | "paraphrased" | "corrected";
|
|
62
|
+
_originalDraft?: string;
|
|
63
|
+
}
|
|
64
|
+
export interface OntologyNode {
|
|
65
|
+
type: "Ontology";
|
|
66
|
+
id: string;
|
|
67
|
+
name: string;
|
|
68
|
+
domain: string;
|
|
69
|
+
purpose: string;
|
|
70
|
+
users: string[];
|
|
71
|
+
maintainers: string[];
|
|
72
|
+
outOfScope: string[];
|
|
73
|
+
kind: "application" | "terminological";
|
|
74
|
+
reuseReviewed: boolean;
|
|
75
|
+
conventions?: Conventions;
|
|
76
|
+
}
|
|
77
|
+
export interface CompetencyQuestionNode {
|
|
78
|
+
type: "CompetencyQuestion";
|
|
79
|
+
id: string;
|
|
80
|
+
text: string;
|
|
81
|
+
status?: "draft" | "answerable";
|
|
82
|
+
}
|
|
83
|
+
export interface TermNode {
|
|
84
|
+
type: "Term";
|
|
85
|
+
id: string;
|
|
86
|
+
text: string;
|
|
87
|
+
disposition?: Disposition;
|
|
88
|
+
note?: string;
|
|
89
|
+
}
|
|
90
|
+
export interface ReusedOntologyNode {
|
|
91
|
+
type: "ReusedOntology";
|
|
92
|
+
id: string;
|
|
93
|
+
name: string;
|
|
94
|
+
url?: string;
|
|
95
|
+
decision: "reuse" | "adapt" | "reference" | "rejected";
|
|
96
|
+
notes?: string;
|
|
97
|
+
}
|
|
98
|
+
/** A class's restriction of an inherited slot (Ontology 101's facet overrides). */
|
|
99
|
+
export interface FacetOverride {
|
|
100
|
+
allowedValues?: Literal[];
|
|
101
|
+
minCardinality?: number;
|
|
102
|
+
maxCardinality?: number;
|
|
103
|
+
range?: string[];
|
|
104
|
+
}
|
|
105
|
+
export interface ClassNode extends ExtractedFields {
|
|
106
|
+
type: "Class";
|
|
107
|
+
id: string;
|
|
108
|
+
name: string;
|
|
109
|
+
description?: string;
|
|
110
|
+
synonyms?: string[];
|
|
111
|
+
abstract?: boolean;
|
|
112
|
+
terminological?: boolean;
|
|
113
|
+
/** Property values every member has. Relationship values are edges from the class. */
|
|
114
|
+
fixedValues?: Record<string, StoredValue>;
|
|
115
|
+
/** Starting values for new instances; they can change them. */
|
|
116
|
+
defaults?: Record<string, StoredValue>;
|
|
117
|
+
facetOverrides?: Record<string, FacetOverride>;
|
|
118
|
+
}
|
|
119
|
+
export interface EdgePropertyDecl {
|
|
120
|
+
name: string;
|
|
121
|
+
valueType: LiteralType;
|
|
122
|
+
allowedValues?: string[];
|
|
123
|
+
required?: boolean;
|
|
124
|
+
description?: string;
|
|
125
|
+
}
|
|
126
|
+
export interface SlotNode extends ExtractedFields {
|
|
127
|
+
type: "Slot";
|
|
128
|
+
id: string;
|
|
129
|
+
name: string;
|
|
130
|
+
description?: string;
|
|
131
|
+
/** "Instance" makes the slot a relationship (see RelationshipSlot). Missing until declared. */
|
|
132
|
+
valueType?: ValueType;
|
|
133
|
+
allowedValues?: string[];
|
|
134
|
+
cardinality?: Cardinality;
|
|
135
|
+
minCardinality?: number;
|
|
136
|
+
maxCardinality?: number;
|
|
137
|
+
default?: StoredValue;
|
|
138
|
+
/** Relationships only: the edge type its values are stored as (maker -> MAKER). */
|
|
139
|
+
relType?: string;
|
|
140
|
+
/** Relationships only: properties its edges can carry. */
|
|
141
|
+
edgeProperties?: EdgePropertyDecl[];
|
|
142
|
+
/** The slot applies to every Rule (qualifier values in Rule.values). Rules have no classes and no inheritance. */
|
|
143
|
+
appliesToRules?: boolean;
|
|
144
|
+
}
|
|
145
|
+
/** A slot whose values link to other things; they're stored as edges of type relType. */
|
|
146
|
+
export type RelationshipSlot = SlotNode & {
|
|
147
|
+
valueType: "Instance";
|
|
148
|
+
relType: string;
|
|
149
|
+
};
|
|
150
|
+
export interface InstanceNode extends ExtractedFields {
|
|
151
|
+
type: "Instance";
|
|
152
|
+
id: string;
|
|
153
|
+
name: string;
|
|
154
|
+
description?: string;
|
|
155
|
+
/** Property values only; relationship values are edges. */
|
|
156
|
+
values?: Record<string, StoredValue>;
|
|
157
|
+
}
|
|
158
|
+
export interface DesignDecisionNode extends ExtractedFields {
|
|
159
|
+
type: "DesignDecision";
|
|
160
|
+
id: string;
|
|
161
|
+
title: string;
|
|
162
|
+
decision: string;
|
|
163
|
+
question?: string;
|
|
164
|
+
rationale?: string;
|
|
165
|
+
alternatives?: string[];
|
|
166
|
+
/** Rule keys this decision explains (waives, for warnings and hints). */
|
|
167
|
+
metaRules?: string[];
|
|
168
|
+
date: string;
|
|
169
|
+
}
|
|
170
|
+
export interface SourceNode {
|
|
171
|
+
type: "Source";
|
|
172
|
+
id: string;
|
|
173
|
+
title: string;
|
|
174
|
+
localPath?: string;
|
|
175
|
+
format?: "markdown" | "pdf" | "text";
|
|
176
|
+
url?: string;
|
|
177
|
+
repoUrl?: string;
|
|
178
|
+
/** Markdown frontmatter. */
|
|
179
|
+
meta?: Record<string, unknown>;
|
|
180
|
+
}
|
|
181
|
+
export interface SourceLocationNode {
|
|
182
|
+
type: "SourceLocation";
|
|
183
|
+
id: string;
|
|
184
|
+
quote: string;
|
|
185
|
+
locator?: string;
|
|
186
|
+
headingPath?: string[];
|
|
187
|
+
startLine?: number;
|
|
188
|
+
endLine?: number;
|
|
189
|
+
lines?: string;
|
|
190
|
+
blockKind?: string;
|
|
191
|
+
sourceLink?: string;
|
|
192
|
+
pageLink?: string;
|
|
193
|
+
page?: number | string;
|
|
194
|
+
}
|
|
195
|
+
export declare const MODALITIES: readonly ["MUST", "MUST_NOT", "SHOULD", "SHOULD_NOT", "MAY"];
|
|
196
|
+
export declare const VERIFICATION_STATUSES: readonly ["SUPPORTED", "OVERREACH", "UNSUPPORTED"];
|
|
197
|
+
export type Modality = (typeof MODALITIES)[number];
|
|
198
|
+
/**
|
|
199
|
+
* A domain rule: a requirement on any implementation, extracted from documentation
|
|
200
|
+
* (docs/EXTRACTION-PIPELINE.md) or written by the ontology's owner.
|
|
201
|
+
*/
|
|
202
|
+
export interface RuleNode extends ExtractedFields {
|
|
203
|
+
type: "Rule";
|
|
204
|
+
id: string;
|
|
205
|
+
name: string;
|
|
206
|
+
modality: Modality;
|
|
207
|
+
statement: string;
|
|
208
|
+
/** Written by the ontology owner, not extracted. It still cites a quote and gets verified. */
|
|
209
|
+
authored?: boolean;
|
|
210
|
+
/** Qualifier values for property slots that apply to Rules (Slot.appliesToRules), e.g. condition. Each rule states its own; nothing is inherited through REFINES. */
|
|
211
|
+
values?: Record<string, StoredValue>;
|
|
212
|
+
}
|
|
213
|
+
export type OkbNode = OntologyNode | CompetencyQuestionNode | TermNode | ReusedOntologyNode | ClassNode | SlotNode | InstanceNode | DesignDecisionNode | SourceNode | SourceLocationNode | RuleNode;
|
|
214
|
+
export type NodeType = OkbNode["type"];
|
|
215
|
+
export type NodeOf<T extends NodeType> = Extract<OkbNode, {
|
|
216
|
+
type: T;
|
|
217
|
+
}>;
|
|
218
|
+
export interface Facets {
|
|
219
|
+
valueType?: ValueType;
|
|
220
|
+
allowedValues: Literal[] | null;
|
|
221
|
+
min: number;
|
|
222
|
+
max: number | null;
|
|
223
|
+
range: string[];
|
|
224
|
+
overriddenBy: string[];
|
|
225
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types for the okb file format (okb-lpg/2). The node and edge registry
|
|
3
|
+
* is meta-kb/src/format.yaml; docs/FORMAT.md describes each property.
|
|
4
|
+
*
|
|
5
|
+
* Files can be edited by hand, so what's loaded is only *expected* to match these
|
|
6
|
+
* types. The struct-well-formed rule reports what doesn't, and code that walks
|
|
7
|
+
* edges should still expect ids that point nowhere (use Ontology.require).
|
|
8
|
+
*/
|
|
9
|
+
export const VALUE_TYPES = ["String", "Integer", "Float", "Number", "Boolean", "Enumerated", "Instance"];
|
|
10
|
+
export const DISPOSITIONS = ["undecided", "class", "slot", "instance", "value", "synonym", "out-of-scope"];
|
|
11
|
+
export const CARDINALITIES = ["single", "multiple"];
|
|
12
|
+
export const MODALITIES = ["MUST", "MUST_NOT", "SHOULD", "SHOULD_NOT", "MAY"];
|
|
13
|
+
export const VERIFICATION_STATUSES = ["SUPPORTED", "OVERREACH", "UNSUPPORTED"];
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ontology-kit/format",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "0.1.0-bootstrap.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "Read the okb file format: an ontology folder's typed nodes and edges, loading with migrations, the reserved edge types and relationship values. No CLI, no meta-KB.",
|
|
6
|
+
"homepage": "https://ontology-kit.dev",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/alanbsmith/ontology-kit.git",
|
|
10
|
+
"directory": "packages/format"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/alanbsmith/ontology-kit/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"ontology",
|
|
17
|
+
"knowledge-graph",
|
|
18
|
+
"knowledge-base",
|
|
19
|
+
"labeled-property-graph",
|
|
20
|
+
"file-format",
|
|
21
|
+
"okb"
|
|
22
|
+
],
|
|
23
|
+
"type": "module",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"default": "./dist/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./package.json": "./package.json"
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist",
|
|
36
|
+
"README.md",
|
|
37
|
+
"LICENSE"
|
|
38
|
+
],
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=24"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/node": "^26.6.6",
|
|
44
|
+
"typescript": "^5.9.0"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"typecheck": "tsc",
|
|
48
|
+
"test": "node --test \"tests/*.test.ts\"",
|
|
49
|
+
"build": "rm -rf dist types-internal && tsc -p tsconfig.build.json && node ../../scripts/rewrite-dts.ts && tsc -p tsconfig.internal.json && node ../../scripts/rewrite-dts.ts types-internal"
|
|
50
|
+
},
|
|
51
|
+
"types": "./dist/index.d.ts"
|
|
6
52
|
}
|