@ontology-kit/reader 0.3.0-alpha.68 → 0.3.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/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/model.d.ts +1 -24
- package/dist/model.js +33 -8
- package/dist/query.d.ts +0 -2
- package/dist/query.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
* source and left out of the shipped type declarations. docs/FORMAT.md lists the
|
|
9
9
|
* API and says what counts as a breaking change.
|
|
10
10
|
*/
|
|
11
|
-
export { Ontology, FORMAT, MANIFEST, findRoot, nodeLabel, nameOrText,
|
|
11
|
+
export { Ontology, FORMAT, MANIFEST, findRoot, nodeLabel, nameOrText, literalValues } from "./model.js";
|
|
12
12
|
export { OkbError } from "./errors.js";
|
|
13
13
|
export { Relationships, isRelationship, edgeProps } from "./relationships.js";
|
|
14
14
|
export type { LinkSpec } from "./relationships.js";
|
|
15
|
-
export {
|
|
15
|
+
export { checkQuery, query, queryFind, queryGet, querySlots, queryTraverse, resultNames } from "./query.js";
|
|
16
16
|
export type { FindQuery, GetResult, NodeHit, Query, QueryResult, QueryValue, SlotHit, SlotsQuery, TraverseHit, TraverseQuery, } from "./query.js";
|
|
17
17
|
export { NODE_TYPES, STRUCTURAL_EDGE_TYPES, PROVENANCE_EDGE_TYPES, isStructuralEdgeType, isProvenanceEdgeType } from "./edge-types.js";
|
|
18
18
|
export { fold, key, rawTokens, relType, slug, stripAccents, tokens } from "./naming.js";
|
package/dist/index.js
CHANGED
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
* source and left out of the shipped type declarations. docs/FORMAT.md lists the
|
|
9
9
|
* API and says what counts as a breaking change.
|
|
10
10
|
*/
|
|
11
|
-
export { Ontology, FORMAT, MANIFEST, findRoot, nodeLabel, nameOrText,
|
|
11
|
+
export { Ontology, FORMAT, MANIFEST, findRoot, nodeLabel, nameOrText, literalValues } from "./model.js";
|
|
12
12
|
export { OkbError } from "./errors.js";
|
|
13
13
|
export { Relationships, isRelationship, edgeProps } from "./relationships.js";
|
|
14
|
-
export {
|
|
14
|
+
export { checkQuery, query, queryFind, queryGet, querySlots, queryTraverse, resultNames } from "./query.js";
|
|
15
15
|
export { NODE_TYPES, STRUCTURAL_EDGE_TYPES, PROVENANCE_EDGE_TYPES, isStructuralEdgeType, isProvenanceEdgeType } from "./edge-types.js";
|
|
16
16
|
export { fold, key, rawTokens, relType, slug, stripAccents, tokens } from "./naming.js";
|
|
17
17
|
export { CARDINALITIES, DISPOSITIONS, MODALITIES, VALUE_TYPES, VERIFICATION_STATUSES, } from "./types.js";
|
package/dist/model.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { OkbError } from "./errors.js";
|
|
2
2
|
import { Relationships, edgeProps, isRelationship } from "./relationships.js";
|
|
3
|
-
import { DISPOSITIONS, VALUE_TYPES, type ClassNode, type
|
|
3
|
+
import { DISPOSITIONS, VALUE_TYPES, type ClassNode, type Facets, type GraphEdge, type InstanceNode, type Manifest, type NodeOf, type NodeType, type OkbNode, type OntologyNode, type RuleNode, type StoredValue } from "./types.js";
|
|
4
4
|
export { DISPOSITIONS, VALUE_TYPES };
|
|
5
5
|
export declare const FORMAT: string;
|
|
6
6
|
export declare const MANIFEST = "okb.json";
|
|
@@ -10,7 +10,6 @@ export declare function nodeLabel(n: OkbNode): string;
|
|
|
10
10
|
export { isRelationship };
|
|
11
11
|
export declare function findRoot(start: string): string | null;
|
|
12
12
|
export declare class Ontology {
|
|
13
|
-
root: string;
|
|
14
13
|
manifest: Manifest;
|
|
15
14
|
private _nodes;
|
|
16
15
|
private _edges;
|
|
@@ -45,8 +44,6 @@ export declare class Ontology {
|
|
|
45
44
|
private indexEdge;
|
|
46
45
|
/** The Ontology node (scope, conventions). A stand-in if the file lacks one; struct-well-formed reports that. */
|
|
47
46
|
get meta(): OntologyNode;
|
|
48
|
-
get conventions(): Conventions | undefined;
|
|
49
|
-
get step(): number;
|
|
50
47
|
get(id: string): OkbNode | undefined;
|
|
51
48
|
/**
|
|
52
49
|
* The node with this id, which the caller knows exists (an edge end, a stored
|
|
@@ -80,40 +77,20 @@ export declare class Ontology {
|
|
|
80
77
|
* the walk gives `b, c, z, a`. Cycle-safe.
|
|
81
78
|
*/
|
|
82
79
|
private walk;
|
|
83
|
-
/** id plus all its ancestors. */
|
|
84
|
-
up(id: string): Set<string>;
|
|
85
|
-
/** a is b, or a (transitively) IS_A b. */
|
|
86
|
-
isSub(a: string, b: string): boolean;
|
|
87
|
-
/** a and b can never share members: a declared DISJOINT_WITH pair covers them (directly or via ancestors). */
|
|
88
|
-
disjointImplied(a: string, b: string): boolean;
|
|
89
80
|
roots(): string[];
|
|
90
81
|
/** Every class an instance belongs to, including inherited ones. */
|
|
91
82
|
instanceClasses(id: string): Set<string>;
|
|
92
|
-
/** Classes a node belongs to for slot purposes: an instance's classes, or a class and its ancestors. */
|
|
93
|
-
classContext(id: string): string[];
|
|
94
|
-
/** Whether following `type` edges from `from` ever reaches `to`. */
|
|
95
|
-
reaches(from: string, to: string, type: string): boolean;
|
|
96
83
|
ownSlots(id: string): string[];
|
|
97
|
-
slotsOfClasses(classes: Iterable<string>): string[];
|
|
98
84
|
/** Own + inherited slots of a class, all slots of an instance, or the slots declared to apply to Rules. */
|
|
99
85
|
applicableSlots(id: string): string[];
|
|
100
86
|
domain(slotId: string): string[];
|
|
101
|
-
/** Whether a slot belongs to anything: a class, or every Rule. */
|
|
102
|
-
isAttached(slotId: string): boolean;
|
|
103
87
|
range(slotId: string): string[];
|
|
104
88
|
inverses(slotId: string): string[];
|
|
105
89
|
/** Slot facets with overrides from any of `classes` applied (most restrictive wins). */
|
|
106
90
|
effectiveFacets(slotId: string, classes: Iterable<string>): Facets;
|
|
107
91
|
/** Values a node states for a slot: literals (values / fixedValues) plus relationship targets. */
|
|
108
92
|
statedValues(id: string, slotId: string): unknown[];
|
|
109
|
-
/** The fixed (class-level) values for a slot inherited from any of `classes`, with the class that set them. */
|
|
110
|
-
inheritedFixed(slotId: string, classes: Iterable<string>, exclude?: string): {
|
|
111
|
-
cls: string;
|
|
112
|
-
values: unknown[];
|
|
113
|
-
} | null;
|
|
114
93
|
}
|
|
115
|
-
/** A node's own literal value for a slot: an instance's value, or a class's fixed value. */
|
|
116
|
-
export declare function literalValue(n: OkbNode, slotId: string): StoredValue | undefined;
|
|
117
94
|
/** Where a node keeps its own literal values: instances and rules in `values`, classes in `fixedValues`. */
|
|
118
95
|
export declare function literalValues(n: InstanceNode | ClassNode | RuleNode): Record<string, StoredValue>;
|
|
119
96
|
/** A node's name, or a question's/term's text (undefined for anything else). */
|
package/dist/model.js
CHANGED
|
@@ -82,6 +82,7 @@ function readJson(path, fallback) {
|
|
|
82
82
|
return existsSync(path) ? JSON.parse(readFileSync(path, "utf8")) : fallback;
|
|
83
83
|
}
|
|
84
84
|
export class Ontology {
|
|
85
|
+
/** @internal */
|
|
85
86
|
root;
|
|
86
87
|
manifest;
|
|
87
88
|
// Changed only through addNode/addEdge/remove*, which keep the indexes current.
|
|
@@ -296,9 +297,11 @@ export class Ontology {
|
|
|
296
297
|
? n
|
|
297
298
|
: { type: "Ontology", id: "ontology", name: "", domain: "", purpose: "", users: [], maintainers: [], outOfScope: [], kind: "application", reuseReviewed: false };
|
|
298
299
|
}
|
|
300
|
+
/** @internal */
|
|
299
301
|
get conventions() {
|
|
300
302
|
return this.meta.conventions;
|
|
301
303
|
}
|
|
304
|
+
/** @internal */
|
|
302
305
|
get step() {
|
|
303
306
|
return Number(this.manifest.currentStep ?? 1);
|
|
304
307
|
}
|
|
@@ -578,15 +581,24 @@ export class Ontology {
|
|
|
578
581
|
}
|
|
579
582
|
return seen;
|
|
580
583
|
}
|
|
581
|
-
/**
|
|
584
|
+
/**
|
|
585
|
+
* id plus all its ancestors.
|
|
586
|
+
* @internal
|
|
587
|
+
*/
|
|
582
588
|
up(id) {
|
|
583
589
|
return new Set([id, ...this.ancestors(id)]);
|
|
584
590
|
}
|
|
585
|
-
/**
|
|
591
|
+
/**
|
|
592
|
+
* a is b, or a (transitively) IS_A b.
|
|
593
|
+
* @internal
|
|
594
|
+
*/
|
|
586
595
|
isSub(a, b) {
|
|
587
596
|
return a === b || this.ancestors(a).has(b);
|
|
588
597
|
}
|
|
589
|
-
/**
|
|
598
|
+
/**
|
|
599
|
+
* a and b can never share members: a declared DISJOINT_WITH pair covers them (directly or via ancestors).
|
|
600
|
+
* @internal
|
|
601
|
+
*/
|
|
590
602
|
disjointImplied(a, b) {
|
|
591
603
|
const ua = this.up(a);
|
|
592
604
|
const ub = this.up(b);
|
|
@@ -603,14 +615,20 @@ export class Ontology {
|
|
|
603
615
|
out.add(x);
|
|
604
616
|
return out;
|
|
605
617
|
}
|
|
606
|
-
/**
|
|
618
|
+
/**
|
|
619
|
+
* Classes a node belongs to for slot purposes: an instance's classes, or a class and its ancestors.
|
|
620
|
+
* @internal
|
|
621
|
+
*/
|
|
607
622
|
classContext(id) {
|
|
608
623
|
const n = this.byId.get(id);
|
|
609
624
|
if (n?.type === "Rule")
|
|
610
625
|
return [];
|
|
611
626
|
return [...(n?.type === "Instance" ? this.instanceClasses(id) : this.up(id))];
|
|
612
627
|
}
|
|
613
|
-
/**
|
|
628
|
+
/**
|
|
629
|
+
* Whether following `type` edges from `from` ever reaches `to`.
|
|
630
|
+
* @internal
|
|
631
|
+
*/
|
|
614
632
|
reaches(from, to, type) {
|
|
615
633
|
const seen = new Set();
|
|
616
634
|
const stack = [from];
|
|
@@ -627,6 +645,7 @@ export class Ontology {
|
|
|
627
645
|
ownSlots(id) {
|
|
628
646
|
return this.targets(id, "HAS_SLOT");
|
|
629
647
|
}
|
|
648
|
+
/** @internal */
|
|
630
649
|
slotsOfClasses(classes) {
|
|
631
650
|
const out = [];
|
|
632
651
|
for (const c of classes)
|
|
@@ -647,7 +666,10 @@ export class Ontology {
|
|
|
647
666
|
domain(slotId) {
|
|
648
667
|
return this.sources(slotId, "HAS_SLOT");
|
|
649
668
|
}
|
|
650
|
-
/**
|
|
669
|
+
/**
|
|
670
|
+
* Whether a slot belongs to anything: a class, or every Rule.
|
|
671
|
+
* @internal
|
|
672
|
+
*/
|
|
651
673
|
isAttached(slotId) {
|
|
652
674
|
const s = this.byId.get(slotId);
|
|
653
675
|
return this.domain(slotId).length > 0 || (s?.type === "Slot" && s.appliesToRules === true);
|
|
@@ -707,7 +729,10 @@ export class Ontology {
|
|
|
707
729
|
out.push(...this.rel.values(id, slotId));
|
|
708
730
|
return out;
|
|
709
731
|
}
|
|
710
|
-
/**
|
|
732
|
+
/**
|
|
733
|
+
* The fixed (class-level) values for a slot inherited from any of `classes`, with the class that set them.
|
|
734
|
+
* @internal
|
|
735
|
+
*/
|
|
711
736
|
inheritedFixed(slotId, classes, exclude) {
|
|
712
737
|
for (const c of classes) {
|
|
713
738
|
if (c === exclude)
|
|
@@ -720,7 +745,7 @@ export class Ontology {
|
|
|
720
745
|
}
|
|
721
746
|
}
|
|
722
747
|
/** A node's own literal value for a slot: an instance's value, or a class's fixed value. */
|
|
723
|
-
|
|
748
|
+
function literalValue(n, slotId) {
|
|
724
749
|
if (n.type === "Instance" || n.type === "Rule")
|
|
725
750
|
return n.values?.[slotId];
|
|
726
751
|
if (n.type === "Class")
|
package/dist/query.d.ts
CHANGED
|
@@ -68,8 +68,6 @@ export type QueryResult = {
|
|
|
68
68
|
kind: "slots";
|
|
69
69
|
hits: SlotHit[];
|
|
70
70
|
};
|
|
71
|
-
/** The most hops a traversal takes. */
|
|
72
|
-
export declare const MAX_DEPTH = 3;
|
|
73
71
|
/** Check a query's shape and return it typed, or throw an `OkbError` saying what is wrong. Names aren't looked up here. */
|
|
74
72
|
export declare function checkQuery(q: unknown): Query;
|
|
75
73
|
/** Run a query. Throws an `OkbError` when its shape is wrong or a name in it doesn't exist. */
|
package/dist/query.js
CHANGED
|
@@ -17,7 +17,7 @@ const SHAPES = new Map([
|
|
|
17
17
|
["slots", ["of"]],
|
|
18
18
|
]);
|
|
19
19
|
/** The most hops a traversal takes. */
|
|
20
|
-
|
|
20
|
+
const MAX_DEPTH = 3;
|
|
21
21
|
const isObj = (x) => !!x && typeof x === "object" && !Array.isArray(x);
|
|
22
22
|
// okb's cq compare (packages/okb/src/cqanswer.ts) normalizes names the same way; keep the two definitions equal.
|
|
23
23
|
const norm = (s) => s.trim().toLowerCase();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ontology-kit/reader",
|
|
3
|
-
"version": "0.3.0
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"license": "MIT",
|
|
5
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
6
|
"homepage": "https://ontology-kit.dev",
|