@shaclmate/shacl-ast 2.0.13 → 2.0.14

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.
@@ -0,0 +1,239 @@
1
+ import TermMap from "@rdfjs/term-map";
2
+ import TermSet from "@rdfjs/term-set";
3
+ import { owl, sh } from "@tpluscode/rdf-ns-builders";
4
+ import { Maybe } from "purify-ts";
5
+ import { ResourceSet } from "rdfjs-resource";
6
+ export class RdfjsShapesGraph {
7
+ constructor({ dataset, factory, }) {
8
+ this.dataset = dataset;
9
+ this.resourceSet = new ResourceSet({ dataset: this.dataset });
10
+ this.node = this.readGraph();
11
+ const { nodeShapes, nodeShapesByIdentifier, propertyShapes, propertyShapesByIdentifier, } = this.readShapes(factory);
12
+ this.nodeShapes = nodeShapes;
13
+ this.nodeShapesByIdentifier = nodeShapesByIdentifier;
14
+ this.propertyShapes = propertyShapes;
15
+ this.propertyShapesByIdentifier = propertyShapesByIdentifier;
16
+ const { ontologies, ontologiesByIdentifier } = this.readOntologies(factory);
17
+ this.ontologies = ontologies;
18
+ this.ontologiesByIdentifier = ontologiesByIdentifier;
19
+ const { propertyGroups, propertyGroupsByIdentifier } = this.readPropertyGroups(factory);
20
+ this.propertyGroups = propertyGroups;
21
+ this.propertyGroupsByIdentifier = propertyGroupsByIdentifier;
22
+ }
23
+ nodeShapeByIdentifier(nodeShapeNode) {
24
+ return Maybe.fromNullable(this.nodeShapesByIdentifier.get(nodeShapeNode));
25
+ }
26
+ ontologyByIdentifier(identifier) {
27
+ return Maybe.fromNullable(this.ontologiesByIdentifier.get(identifier));
28
+ }
29
+ propertyGroupByIdentifier(identifier) {
30
+ return Maybe.fromNullable(this.propertyGroupsByIdentifier.get(identifier));
31
+ }
32
+ propertyShapeByIdentifier(identifier) {
33
+ return Maybe.fromNullable(this.propertyShapesByIdentifier.get(identifier));
34
+ }
35
+ shapeByIdentifier(identifier) {
36
+ const nodeShape = this.nodeShapeByIdentifier(identifier);
37
+ if (nodeShape.isJust()) {
38
+ return nodeShape;
39
+ }
40
+ return this.propertyShapeByIdentifier(identifier);
41
+ }
42
+ readGraph() {
43
+ const graphs = new TermSet();
44
+ for (const quad of this.dataset) {
45
+ graphs.add(quad.graph);
46
+ }
47
+ if (graphs.size !== 1) {
48
+ return null;
49
+ }
50
+ const graph = [...graphs.values()][0];
51
+ switch (graph.termType) {
52
+ case "BlankNode":
53
+ case "DefaultGraph":
54
+ case "NamedNode":
55
+ return graph;
56
+ default:
57
+ throw new RangeError(`expected NamedNode or default graph, actual ${graph.termType}`);
58
+ }
59
+ }
60
+ readOntologies(factory) {
61
+ const ontologies = [];
62
+ const ontologiesByIdentifier = new TermMap();
63
+ for (const ontologyResource of this.resourceSet.instancesOf(owl.Ontology, {
64
+ graph: this.node,
65
+ })) {
66
+ if (ontologiesByIdentifier.has(ontologyResource.identifier)) {
67
+ continue;
68
+ }
69
+ factory
70
+ .ontologyFromRdf({
71
+ resource: ontologyResource,
72
+ shapesGraph: this,
73
+ })
74
+ .ifRight((ontology) => {
75
+ ontologies.push(ontology);
76
+ ontologiesByIdentifier.set(ontologyResource.identifier, ontology);
77
+ });
78
+ }
79
+ return { ontologies, ontologiesByIdentifier };
80
+ }
81
+ readPropertyGroups(factory) {
82
+ const propertyGroups = [];
83
+ const propertyGroupsByIdentifier = new TermMap();
84
+ for (const propertyGroupResource of this.resourceSet.instancesOf(sh.PropertyGroup, { graph: this.node })) {
85
+ if (propertyGroupResource.identifier.termType !== "NamedNode") {
86
+ continue;
87
+ }
88
+ if (propertyGroupsByIdentifier.has(propertyGroupResource.identifier)) {
89
+ continue;
90
+ }
91
+ factory
92
+ .propertyGroupFromRdf({
93
+ resource: propertyGroupResource,
94
+ shapesGraph: this,
95
+ })
96
+ .ifRight((propertyGroup) => {
97
+ propertyGroups.push(propertyGroup);
98
+ propertyGroupsByIdentifier.set(propertyGroupResource.identifier, propertyGroup);
99
+ });
100
+ }
101
+ return { propertyGroups, propertyGroupsByIdentifier };
102
+ }
103
+ readShapes(factory) {
104
+ // Collect the shape identifiers in sets
105
+ const shapeNodeSet = new TermSet();
106
+ // Utility function for doing the collection
107
+ const addShapeNode = (shapeNode) => {
108
+ switch (shapeNode.termType) {
109
+ case "BlankNode":
110
+ case "NamedNode":
111
+ shapeNodeSet.add(shapeNode);
112
+ break;
113
+ }
114
+ };
115
+ // Test each shape condition
116
+ // https://www.w3.org/TR/shacl/#shapes
117
+ // Subject is a SHACL instance of sh:NodeShape or sh:PropertyShape
118
+ for (const rdfType of [sh.NodeShape, sh.PropertyShape]) {
119
+ for (const resource of this.resourceSet.instancesOf(rdfType, {
120
+ graph: this.node,
121
+ })) {
122
+ addShapeNode(resource.identifier);
123
+ }
124
+ }
125
+ // Subject of a triple with sh:targetClass, sh:targetNode, sh:targetObjectsOf, or sh:targetSubjectsOf predicate
126
+ for (const predicate of [
127
+ sh.targetClass,
128
+ sh.targetNode,
129
+ sh.targetObjectsOf,
130
+ sh.targetSubjectsOf,
131
+ ]) {
132
+ for (const quad of this.dataset.match(null, predicate, null, this.node)) {
133
+ addShapeNode(quad.subject);
134
+ }
135
+ }
136
+ // Subject of a triple that has a parameter as predicate
137
+ // https://www.w3.org/TR/shacl/#constraints
138
+ // https://www.w3.org/TR/shacl/#core-components
139
+ for (const predicate of [
140
+ sh.class,
141
+ sh.datatype,
142
+ sh.nodeKind,
143
+ sh.minCount,
144
+ sh.maxCount,
145
+ sh.minExclusive,
146
+ sh.minInclusive,
147
+ sh.maxExclusive,
148
+ sh.maxInclusive,
149
+ sh.minLength,
150
+ sh.maxLength,
151
+ sh.pattern,
152
+ sh.languageIn,
153
+ sh.uniqueLang,
154
+ sh.equals,
155
+ sh.disjoint,
156
+ sh.lessThan,
157
+ sh.lessThanOrEquals,
158
+ sh.not,
159
+ sh.and,
160
+ sh.or,
161
+ sh.xone,
162
+ sh.node,
163
+ sh.property,
164
+ sh.qualifiedValueShape,
165
+ sh.qualifiedMinCount,
166
+ sh.qualifiedMaxCount,
167
+ sh.closed,
168
+ sh.ignoredProperties,
169
+ sh.hasValue,
170
+ sh.in,
171
+ ]) {
172
+ for (const quad of this.dataset.match(null, predicate, null, this.node)) {
173
+ addShapeNode(quad.subject);
174
+ }
175
+ }
176
+ // Object of a shape-expecting, non-list-taking parameter such as sh:node
177
+ for (const predicate of [sh.node, sh.property]) {
178
+ for (const quad of this.dataset.match(null, predicate, null, this.node)) {
179
+ addShapeNode(quad.object);
180
+ }
181
+ }
182
+ // Member of a SHACL list that is a value of a shape-expecting and list-taking parameter such as sh:or
183
+ for (const predicate of [sh.and, sh.or, sh.xone]) {
184
+ for (const quad of this.dataset.match(null, predicate, null, this.node)) {
185
+ switch (quad.object.termType) {
186
+ case "BlankNode":
187
+ case "NamedNode":
188
+ break;
189
+ default:
190
+ continue;
191
+ }
192
+ for (const value of this.resourceSet
193
+ .resource(quad.object)
194
+ .toList()
195
+ .orDefault([])) {
196
+ value.toIdentifier().ifRight(addShapeNode);
197
+ }
198
+ }
199
+ }
200
+ // Separate shapes into node and property shapes.
201
+ const nodeShapes = [];
202
+ const nodeShapesByIdentifier = new TermMap();
203
+ const propertyShapes = [];
204
+ const propertyShapesByIdentifier = new TermMap();
205
+ for (const shapeNode of shapeNodeSet) {
206
+ if (this.dataset.match(shapeNode, sh.path, null, this.node).size > 0) {
207
+ // A property shape is a shape in the shapes graph that is the subject of a triple that has sh:path as its predicate. A shape has at most one value for sh:path. Each value of sh:path in a shape must be a well-formed SHACL property path. It is recommended, but not required, for a property shape to be declared as a SHACL instance of sh:PropertyShape. SHACL instances of sh:PropertyShape have one value for the property sh:path.
208
+ factory
209
+ .propertyShapeFromRdf({
210
+ resource: this.resourceSet.resource(shapeNode),
211
+ shapesGraph: this,
212
+ })
213
+ .ifRight((propertyShape) => {
214
+ propertyShapes.push(propertyShape);
215
+ propertyShapesByIdentifier.set(shapeNode, propertyShape);
216
+ });
217
+ }
218
+ else {
219
+ // A node shape is a shape in the shapes graph that is not the subject of a triple with sh:path as its predicate. It is recommended, but not required, for a node shape to be declared as a SHACL instance of sh:NodeShape. SHACL instances of sh:NodeShape cannot have a value for the property sh:path.
220
+ factory
221
+ .nodeShapeFromRdf({
222
+ resource: this.resourceSet.resource(shapeNode),
223
+ shapesGraph: this,
224
+ })
225
+ .ifRight((nodeShape) => {
226
+ nodeShapes.push(nodeShape);
227
+ nodeShapesByIdentifier.set(shapeNode, nodeShape);
228
+ });
229
+ }
230
+ }
231
+ return {
232
+ nodeShapes,
233
+ nodeShapesByIdentifier,
234
+ propertyShapes,
235
+ propertyShapesByIdentifier,
236
+ };
237
+ }
238
+ }
239
+ //# sourceMappingURL=RdfjsShapesGraph.js.map
package/Shape.d.ts CHANGED
@@ -1,47 +1,42 @@
1
1
  import type { BlankNode, Literal, NamedNode } from "@rdfjs/types";
2
- import type { Maybe } from "purify-ts";
3
- import type { Resource } from "rdfjs-resource";
4
- import { NodeKind } from "./NodeKind.js";
5
- import type { NodeShape } from "./NodeShape.js";
2
+ import { Maybe } from "purify-ts";
3
+ import type { NodeKind } from "./NodeKind.js";
4
+ import type { OntologyLike } from "./OntologyLike.js";
6
5
  import type { ShapesGraph } from "./ShapesGraph.js";
7
- export declare abstract class Shape {
8
- readonly resource: Resource;
9
- abstract readonly constraints: Shape.Constraints;
10
- readonly targets: Shape.Targets;
11
- protected constructor(resource: Resource);
12
- get description(): Maybe<Literal>;
13
- get name(): Maybe<Literal>;
6
+ import type * as generated from "./generated.js";
7
+ export declare abstract class Shape<NodeShapeT extends ShapeT, OntologyT extends OntologyLike, PropertyGroupT, PropertyShapeT extends ShapeT, ShapeT> {
8
+ private readonly generatedShaclCoreShape;
9
+ protected readonly shapesGraph: ShapesGraph<NodeShapeT, OntologyT, PropertyGroupT, PropertyShapeT, ShapeT>;
10
+ abstract readonly constraints: Shape.Constraints<NodeShapeT, OntologyT, PropertyGroupT, PropertyShapeT, ShapeT>;
11
+ constructor(generatedShaclCoreShape: Omit<generated.ShaclCoreShape, "type">, shapesGraph: ShapesGraph<NodeShapeT, OntologyT, PropertyGroupT, PropertyShapeT, ShapeT>);
12
+ get comments(): readonly Literal[];
13
+ get identifier(): BlankNode | NamedNode;
14
+ get isDefinedBy(): Maybe<OntologyT>;
15
+ get labels(): readonly Literal[];
14
16
  }
15
17
  export declare namespace Shape {
16
- class Constraints {
17
- protected readonly resource: Resource;
18
- protected readonly shapesGraph: ShapesGraph;
19
- constructor(resource: Resource, shapesGraph: ShapesGraph);
20
- get and(): readonly Shape[];
18
+ class Constraints<NodeShapeT extends ShapeT, OntologyT extends OntologyLike, PropertyGroupT, PropertyShapeT extends ShapeT, ShapeT> {
19
+ private readonly generatedShaclCoreShape;
20
+ protected readonly shapesGraph: ShapesGraph<NodeShapeT, OntologyT, PropertyGroupT, PropertyShapeT, ShapeT>;
21
+ constructor(generatedShaclCoreShape: Omit<generated.ShaclCoreShape, "type">, shapesGraph: ShapesGraph<NodeShapeT, OntologyT, PropertyGroupT, PropertyShapeT, ShapeT>);
22
+ get and(): readonly ShapeT[];
21
23
  get classes(): readonly NamedNode[];
22
24
  get datatype(): Maybe<NamedNode>;
23
- get hasValue(): Maybe<BlankNode | Literal | NamedNode>;
24
- get in_(): Maybe<readonly (BlankNode | Literal | NamedNode)[]>;
25
+ get hasValues(): readonly (BlankNode | Literal | NamedNode)[];
26
+ get in_(): readonly (BlankNode | Literal | NamedNode)[];
27
+ get languageIn(): readonly string[];
25
28
  get maxCount(): Maybe<number>;
26
29
  get maxExclusive(): Maybe<Literal>;
27
30
  get maxInclusive(): Maybe<Literal>;
28
31
  get minCount(): Maybe<number>;
29
32
  get minExclusive(): Maybe<Literal>;
30
33
  get minInclusive(): Maybe<Literal>;
31
- get nodeKinds(): Set<NodeKind>;
32
- get nodes(): readonly NodeShape[];
33
- get not(): readonly Shape[];
34
- get or(): readonly Shape[];
35
- get xone(): readonly Shape[];
36
- private listTakingLogicalConstraint;
37
- }
38
- class Targets {
39
- protected readonly resource: Resource;
40
- constructor(resource: Resource);
41
- get targetClasses(): readonly NamedNode[];
42
- get targetNodes(): readonly (Literal | NamedNode)[];
43
- get targetObjectsOf(): readonly NamedNode[];
44
- get targetSubjectsOf(): readonly NamedNode[];
34
+ get nodeKinds(): Maybe<Set<NodeKind>>;
35
+ get nodes(): readonly NodeShapeT[];
36
+ get not(): readonly ShapeT[];
37
+ get or(): readonly ShapeT[];
38
+ get xone(): readonly ShapeT[];
39
+ private shapeListTakingConstraint;
45
40
  }
46
41
  }
47
42
  //# sourceMappingURL=Shape.d.ts.map
package/Shape.js CHANGED
@@ -1,171 +1,127 @@
1
- import { sh } from "@tpluscode/rdf-ns-builders";
2
- import { NodeKind } from "./NodeKind.js";
1
+ import { Maybe } from "purify-ts";
3
2
  export class Shape {
4
- constructor(resource) {
5
- this.resource = resource;
6
- this.targets = new Shape.Targets(resource);
3
+ constructor(generatedShaclCoreShape, shapesGraph) {
4
+ this.generatedShaclCoreShape = generatedShaclCoreShape;
5
+ this.shapesGraph = shapesGraph;
7
6
  }
8
- get description() {
9
- return this.resource
10
- .value(sh.description)
11
- .chain((value) => value.toLiteral())
12
- .toMaybe();
7
+ get comments() {
8
+ return this.generatedShaclCoreShape.comments;
13
9
  }
14
- get name() {
15
- return this.resource
16
- .value(sh.name)
17
- .chain((value) => value.toLiteral())
18
- .toMaybe();
10
+ get identifier() {
11
+ return this.generatedShaclCoreShape.identifier;
12
+ }
13
+ get isDefinedBy() {
14
+ if (this.generatedShaclCoreShape.isDefinedBy.isJust()) {
15
+ // If there's an rdfs:isDefinedBy statement on the shape then don't fall back to anything else
16
+ return this.shapesGraph.ontologyByIdentifier(this.generatedShaclCoreShape.isDefinedBy.unsafeCoerce());
17
+ }
18
+ // No rdfs:isDefinedBy statement on the shape
19
+ const ontologies = this.shapesGraph.ontologies;
20
+ if (ontologies.length === 1) {
21
+ // If there's a single ontology in the shapes graph, consider the shape a part of the ontology
22
+ return Maybe.of(ontologies[0]);
23
+ }
24
+ if (this.identifier.termType === "NamedNode") {
25
+ const prefixOntologies = ontologies.filter((ontology) => ontology.identifier.termType === "NamedNode" &&
26
+ this.identifier.value.startsWith(ontology.identifier.value));
27
+ if (prefixOntologies.length === 1) {
28
+ // If there's a single ontology whose IRI is a prefix of this shape's IRI, consider the shape a part of the ontology
29
+ return Maybe.of(prefixOntologies[0]);
30
+ }
31
+ }
32
+ return Maybe.empty();
33
+ }
34
+ get labels() {
35
+ return this.generatedShaclCoreShape.labels;
19
36
  }
20
37
  }
21
38
  (function (Shape) {
22
39
  class Constraints {
23
- constructor(resource, shapesGraph) {
24
- this.resource = resource;
40
+ constructor(generatedShaclCoreShape, shapesGraph) {
41
+ this.generatedShaclCoreShape = generatedShaclCoreShape;
25
42
  this.shapesGraph = shapesGraph;
26
43
  }
27
44
  get and() {
28
- return this.listTakingLogicalConstraint(sh.and);
45
+ return this.shapeListTakingConstraint(this.generatedShaclCoreShape.and);
29
46
  }
30
47
  get classes() {
31
- return [...this.resource.values(sh.class)].flatMap((value) => value.toIri().toMaybe().toList());
48
+ return this.generatedShaclCoreShape.classes;
32
49
  }
33
50
  get datatype() {
34
- return this.resource
35
- .value(sh.datatype)
36
- .chain((value) => value.toIri())
37
- .toMaybe();
51
+ return this.generatedShaclCoreShape.datatype;
38
52
  }
39
- get hasValue() {
40
- return this.resource
41
- .value(sh.hasValue)
42
- .map((value) => value.toTerm())
43
- .toMaybe();
53
+ get hasValues() {
54
+ return this.generatedShaclCoreShape.hasValues;
44
55
  }
45
56
  get in_() {
46
- return this.resource
47
- .value(sh.in)
48
- .chain((value) => value.toList())
49
- .map((values) => values.map((value) => value.toTerm()))
50
- .toMaybe();
57
+ return this.generatedShaclCoreShape.in_.orDefault([]);
58
+ }
59
+ get languageIn() {
60
+ return this.generatedShaclCoreShape.languageIn.orDefault([]);
51
61
  }
52
62
  get maxCount() {
53
- return this.resource
54
- .value(sh.maxCount)
55
- .chain((value) => value.toNumber())
56
- .toMaybe();
63
+ return this.generatedShaclCoreShape.maxCount;
57
64
  }
58
65
  get maxExclusive() {
59
- return this.resource
60
- .value(sh.maxExclusive)
61
- .chain((value) => value.toLiteral())
62
- .toMaybe();
66
+ return this.generatedShaclCoreShape.maxExclusive;
63
67
  }
64
68
  get maxInclusive() {
65
- return this.resource
66
- .value(sh.maxInclusive)
67
- .chain((value) => value.toLiteral())
68
- .toMaybe();
69
+ return this.generatedShaclCoreShape.maxInclusive;
69
70
  }
70
71
  get minCount() {
71
- return this.resource
72
- .value(sh.minCount)
73
- .chain((value) => value.toNumber())
74
- .toMaybe();
72
+ return this.generatedShaclCoreShape.minCount;
75
73
  }
76
74
  get minExclusive() {
77
- return this.resource
78
- .value(sh.minExclusive)
79
- .chain((value) => value.toLiteral())
80
- .toMaybe();
75
+ return this.generatedShaclCoreShape.minExclusive;
81
76
  }
82
77
  get minInclusive() {
83
- return this.resource
84
- .value(sh.minInclusive)
85
- .chain((value) => value.toLiteral())
86
- .toMaybe();
78
+ return this.generatedShaclCoreShape.minInclusive;
87
79
  }
88
80
  get nodeKinds() {
89
- const nodeKinds = new Set();
90
- for (const nodeKindValue of this.resource.values(sh.nodeKind)) {
91
- nodeKindValue.toIri().ifRight((nodeKindIri) => {
92
- if (nodeKindIri.equals(sh.BlankNode)) {
93
- nodeKinds.add(NodeKind.BLANK_NODE);
94
- }
95
- else if (nodeKindIri.equals(sh.BlankNodeOrIRI)) {
96
- nodeKinds.add(NodeKind.BLANK_NODE);
97
- nodeKinds.add(NodeKind.IRI);
98
- }
99
- else if (nodeKindIri.equals(sh.BlankNodeOrLiteral)) {
100
- nodeKinds.add(NodeKind.BLANK_NODE);
101
- nodeKinds.add(NodeKind.LITERAL);
102
- }
103
- else if (nodeKindIri.equals(sh.IRI)) {
104
- nodeKinds.add(NodeKind.IRI);
105
- }
106
- else if (nodeKindIri.equals(sh.IRIOrLiteral)) {
107
- nodeKinds.add(NodeKind.IRI);
108
- nodeKinds.add(NodeKind.LITERAL);
109
- }
110
- else if (nodeKindIri.equals(sh.Literal)) {
111
- nodeKinds.add(NodeKind.LITERAL);
112
- }
113
- });
114
- }
115
- return nodeKinds;
81
+ return this.generatedShaclCoreShape.nodeKind.chain((iri) => {
82
+ const nodeKinds = new Set();
83
+ switch (iri.value) {
84
+ case "http://www.w3.org/ns/shacl#BlankNode":
85
+ nodeKinds.add("BlankNode");
86
+ break;
87
+ case "http://www.w3.org/ns/shacl#BlankNodeOrIRI":
88
+ nodeKinds.add("BlankNode");
89
+ nodeKinds.add("NamedNode");
90
+ break;
91
+ case "http://www.w3.org/ns/shacl#BlankNodeOrLiteral":
92
+ nodeKinds.add("BlankNode");
93
+ nodeKinds.add("Literal");
94
+ break;
95
+ case "http://www.w3.org/ns/shacl#IRI":
96
+ nodeKinds.add("NamedNode");
97
+ break;
98
+ case "http://www.w3.org/ns/shacl#IRIOrLiteral":
99
+ nodeKinds.add("Literal");
100
+ nodeKinds.add("NamedNode");
101
+ break;
102
+ case "http://www.w3.org/ns/shacl#Literal":
103
+ nodeKinds.add("Literal");
104
+ break;
105
+ }
106
+ return nodeKinds.size > 0 ? Maybe.of(nodeKinds) : Maybe.empty();
107
+ });
116
108
  }
117
109
  get nodes() {
118
- return [...this.resource.values(sh.node)].flatMap((value) => value
119
- .toIdentifier()
120
- .toMaybe()
121
- .chain((shapeNode) => this.shapesGraph.nodeShapeByNode(shapeNode))
122
- .toList());
110
+ return this.generatedShaclCoreShape.nodes.flatMap((identifier) => this.shapesGraph.nodeShapeByIdentifier(identifier).toList());
123
111
  }
124
112
  get not() {
125
- return [...this.resource.values(sh.not)].flatMap((value) => value
126
- .toIdentifier()
127
- .toMaybe()
128
- .chain((shapeNode) => this.shapesGraph.shapeByNode(shapeNode))
129
- .toList());
113
+ return this.generatedShaclCoreShape.not.flatMap((identifier) => this.shapesGraph.shapeByIdentifier(identifier).toList());
130
114
  }
131
115
  get or() {
132
- return this.listTakingLogicalConstraint(sh.or);
116
+ return this.shapeListTakingConstraint(this.generatedShaclCoreShape.or);
133
117
  }
134
118
  get xone() {
135
- return this.listTakingLogicalConstraint(sh.xone);
136
- }
137
- listTakingLogicalConstraint(predicate) {
138
- return this.resource
139
- .value(predicate)
140
- .chain((value) => value.toList())
141
- .map((values) => values.flatMap((value) => value
142
- .toIdentifier()
143
- .toMaybe()
144
- .chain((shapeNode) => this.shapesGraph.shapeByNode(shapeNode))
145
- .toList()))
146
- .orDefault([]);
119
+ return this.shapeListTakingConstraint(this.generatedShaclCoreShape.xone);
147
120
  }
148
- }
149
- Shape.Constraints = Constraints;
150
- class Targets {
151
- constructor(resource) {
152
- this.resource = resource;
153
- }
154
- get targetClasses() {
155
- return [...this.resource.values(sh.targetClass)].flatMap((value) => value.toIri().toMaybe().toList());
156
- }
157
- get targetNodes() {
158
- return [...this.resource.values(sh.targetNode)].flatMap((value) => value.toLiteral().toMaybe()
159
- .altLazy(() => value.toIri().toMaybe())
160
- .toList());
161
- }
162
- get targetObjectsOf() {
163
- return [...this.resource.values(sh.targetObjectsOf)].flatMap((value) => value.toIri().toMaybe().toList());
164
- }
165
- get targetSubjectsOf() {
166
- return [...this.resource.values(sh.targetSubjectsOf)].flatMap((value) => value.toIri().toMaybe().toList());
121
+ shapeListTakingConstraint(identifiers) {
122
+ return identifiers.flatMap((identifiers) => identifiers.flatMap((identifier) => this.shapesGraph.shapeByIdentifier(identifier).toList()));
167
123
  }
168
124
  }
169
- Shape.Targets = Targets;
125
+ Shape.Constraints = Constraints;
170
126
  })(Shape || (Shape = {}));
171
127
  //# sourceMappingURL=Shape.js.map
package/ShapesGraph.d.ts CHANGED
@@ -1,26 +1,12 @@
1
- import type { BlankNode, DatasetCore, DefaultGraph, NamedNode } from "@rdfjs/types";
2
- import { Maybe } from "purify-ts";
3
- import { NodeShape } from "./NodeShape.js";
4
- import { PropertyGroup } from "./PropertyGroup.js";
5
- import { PropertyShape } from "./PropertyShape.js";
6
- import type { Shape } from "./Shape.js";
7
- export declare class ShapesGraph {
8
- readonly dataset: DatasetCore;
9
- readonly node: BlankNode | DefaultGraph | NamedNode | null;
10
- readonly nodeShapes: readonly NodeShape[];
11
- readonly propertyGroups: readonly PropertyGroup[];
12
- readonly propertyShapes: readonly PropertyShape[];
13
- private readonly nodeShapesByNode;
14
- private readonly propertyGroupsByNode;
15
- private readonly propertyShapesByNode;
16
- private constructor();
17
- static fromDataset(dataset: DatasetCore): ShapesGraph;
18
- nodeShapeByNode(nodeShapeNode: BlankNode | NamedNode): Maybe<NodeShape>;
19
- propertyGroupByNode(propertyGroupNode: NamedNode): Maybe<PropertyGroup>;
20
- propertyShapeByNode(propertyShapeNode: BlankNode | NamedNode): Maybe<PropertyShape>;
21
- shapeByNode(node: BlankNode | NamedNode): Maybe<Shape>;
22
- private readGraph;
23
- private readPropertyGroups;
24
- private readShapes;
1
+ import type { BlankNode, NamedNode } from "@rdfjs/types";
2
+ import type { Maybe } from "purify-ts";
3
+ import type { OntologyLike } from "./OntologyLike.js";
4
+ export interface ShapesGraph<NodeShapeT extends ShapeT, OntologyT extends OntologyLike, PropertyGroupT, PropertyShapeT extends ShapeT, ShapeT> {
5
+ readonly ontologies: readonly OntologyT[];
6
+ nodeShapeByIdentifier(identifier: BlankNode | NamedNode): Maybe<NodeShapeT>;
7
+ ontologyByIdentifier(identifier: BlankNode | NamedNode): Maybe<OntologyT>;
8
+ propertyGroupByIdentifier(identifier: BlankNode | NamedNode): Maybe<PropertyGroupT>;
9
+ propertyShapeByIdentifier(identifier: BlankNode | NamedNode): Maybe<PropertyShapeT>;
10
+ shapeByIdentifier(identifier: BlankNode | NamedNode): Maybe<ShapeT>;
25
11
  }
26
12
  //# sourceMappingURL=ShapesGraph.d.ts.map