@shaclmate/shacl-ast 4.0.18 → 4.0.20
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/AbstractShapesGraph.d.ts +1 -1
- package/dist/AbstractShapesGraph.js +16 -37
- package/dist/generated.d.ts +241 -241
- package/dist/generated.js +19 -20
- package/package.json +4 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type PrefixMap from "@rdfjs/prefix-map/PrefixMap.js";
|
|
2
2
|
import TermMap from "@rdfjs/term-map";
|
|
3
3
|
import type { BlankNode, DatasetCore, NamedNode } from "@rdfjs/types";
|
|
4
|
-
import { Resource, ResourceSet } from "@rdfx/resource";
|
|
4
|
+
import { type Resource, ResourceSet } from "@rdfx/resource";
|
|
5
5
|
import { Either } from "purify-ts";
|
|
6
6
|
import type * as generated from "./generated.js";
|
|
7
7
|
export declare abstract class AbstractShapesGraph<NodeShapeT extends generated.NodeShape, OntologyT extends generated.Ontology, PropertyGroupT extends generated.PropertyGroup, PropertyShapeT extends generated.PropertyShape> {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import DatasetFactory from "@rdfjs/dataset";
|
|
1
|
+
import datasetFactory from "@rdfjs/dataset";
|
|
3
2
|
import TermMap from "@rdfjs/term-map";
|
|
4
3
|
import TermSet from "@rdfjs/term-set";
|
|
5
|
-
import
|
|
4
|
+
import dataFactory from "@rdfx/data-factory";
|
|
5
|
+
import { ResourceSet } from "@rdfx/resource";
|
|
6
|
+
import { NTriplesTerm } from "@rdfx/string";
|
|
6
7
|
import { owl, sh } from "@tpluscode/rdf-ns-builders";
|
|
7
8
|
import { Either, Left } from "purify-ts";
|
|
8
9
|
import { CurieFactory } from "./CurieFactory.js";
|
|
@@ -42,25 +43,25 @@ export class AbstractShapesGraph {
|
|
|
42
43
|
const nodeShape = this.nodeShapesByIdentifier.get(identifier);
|
|
43
44
|
return nodeShape
|
|
44
45
|
? Either.of(nodeShape)
|
|
45
|
-
: Left(new Error(`no such node shape ${
|
|
46
|
+
: Left(new Error(`no such node shape ${identifier}`));
|
|
46
47
|
}
|
|
47
48
|
ontology(identifier) {
|
|
48
49
|
const ontology = this.ontologiesByIdentifier.get(identifier);
|
|
49
50
|
return ontology
|
|
50
51
|
? Either.of(ontology)
|
|
51
|
-
: Left(new Error(`no such ontology ${
|
|
52
|
+
: Left(new Error(`no such ontology ${identifier}`));
|
|
52
53
|
}
|
|
53
54
|
propertyGroup(identifier) {
|
|
54
55
|
const propertyGroup = this.propertyGroupsByIdentifier.get(identifier);
|
|
55
56
|
return propertyGroup
|
|
56
57
|
? Either.of(propertyGroup)
|
|
57
|
-
: Left(new Error(`no such property group ${
|
|
58
|
+
: Left(new Error(`no such property group ${identifier}`));
|
|
58
59
|
}
|
|
59
60
|
propertyShape(identifier) {
|
|
60
61
|
const propertyShape = this.propertyShapesByIdentifier.get(identifier);
|
|
61
62
|
return propertyShape
|
|
62
63
|
? Either.of(propertyShape)
|
|
63
|
-
: Left(new Error(`no such property shape ${
|
|
64
|
+
: Left(new Error(`no such property shape ${identifier}`));
|
|
64
65
|
}
|
|
65
66
|
shape(identifier) {
|
|
66
67
|
return this.nodeShape(identifier).alt(this.propertyShape(identifier));
|
|
@@ -69,7 +70,7 @@ export class AbstractShapesGraph {
|
|
|
69
70
|
* Convert the shapes graph to a dataset.
|
|
70
71
|
*/
|
|
71
72
|
toDataset() {
|
|
72
|
-
const dataset =
|
|
73
|
+
const dataset = datasetFactory.dataset();
|
|
73
74
|
const resourceSet = new ResourceSet(dataset);
|
|
74
75
|
for (const nodeShape of this.nodeShapes) {
|
|
75
76
|
this.typeFunctions.NodeShape.$toRdfResource(nodeShape, { resourceSet });
|
|
@@ -96,43 +97,21 @@ export class AbstractShapesGraph {
|
|
|
96
97
|
*/
|
|
97
98
|
toString(options) {
|
|
98
99
|
const format = options?.format ?? "application/n-triples";
|
|
99
|
-
function termToString(term) {
|
|
100
|
-
switch (term.termType) {
|
|
101
|
-
case "NamedNode":
|
|
102
|
-
return `<${term.value}>`;
|
|
103
|
-
case "BlankNode":
|
|
104
|
-
return `_:${term.value}`;
|
|
105
|
-
case "Literal": {
|
|
106
|
-
const escaped = term.value
|
|
107
|
-
.replace(/\\/g, "\\\\")
|
|
108
|
-
.replace(/"/g, '\\"')
|
|
109
|
-
.replace(/\n/g, "\\n")
|
|
110
|
-
.replace(/\r/g, "\\r");
|
|
111
|
-
if (term.language)
|
|
112
|
-
return `"${escaped}"@${term.language}`;
|
|
113
|
-
if (term.datatype.value !== "http://www.w3.org/2001/XMLSchema#string")
|
|
114
|
-
return `"${escaped}"^^<${term.datatype.value}>`;
|
|
115
|
-
return `"${escaped}"`;
|
|
116
|
-
}
|
|
117
|
-
default:
|
|
118
|
-
throw new Error(`unexpected term type: ${term.termType}`);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
100
|
const lines = [];
|
|
122
101
|
switch (format) {
|
|
123
102
|
case "application/n-quads": {
|
|
124
103
|
for (const quad of this.toDataset()) {
|
|
125
104
|
const graphString = quad.graph.termType === "DefaultGraph"
|
|
126
105
|
? ""
|
|
127
|
-
: ` ${
|
|
128
|
-
lines.push(`${
|
|
106
|
+
: ` ${NTriplesTerm.stringify(quad.graph)}`;
|
|
107
|
+
lines.push(`${NTriplesTerm.stringify(quad.subject)} ${NTriplesTerm.stringify(quad.predicate)} ${NTriplesTerm.stringify(quad.object)}${graphString} .\n`);
|
|
129
108
|
}
|
|
130
109
|
break;
|
|
131
110
|
}
|
|
132
111
|
case "application/n-triples":
|
|
133
112
|
{
|
|
134
113
|
for (const quad of this.toDataset()) {
|
|
135
|
-
lines.push(`${
|
|
114
|
+
lines.push(`${NTriplesTerm.stringify(quad.subject)} ${NTriplesTerm.stringify(quad.predicate)} ${NTriplesTerm.stringify(quad.object)} .\n`);
|
|
136
115
|
}
|
|
137
116
|
}
|
|
138
117
|
break;
|
|
@@ -175,7 +154,7 @@ export class AbstractShapesGraph {
|
|
|
175
154
|
let curieDataset;
|
|
176
155
|
if (options?.prefixMap) {
|
|
177
156
|
const curieCache = new Map();
|
|
178
|
-
curieDataset =
|
|
157
|
+
curieDataset = datasetFactory.dataset();
|
|
179
158
|
const curieFactory = new CurieFactory({
|
|
180
159
|
prefixMap: options.prefixMap,
|
|
181
160
|
});
|
|
@@ -196,7 +175,7 @@ export class AbstractShapesGraph {
|
|
|
196
175
|
const curieSubject = termToCurie(quad.subject);
|
|
197
176
|
if (!Object.is(curieObject, quad.object) ||
|
|
198
177
|
!Object.is(curieSubject, quad.subject)) {
|
|
199
|
-
curieDataset.add(
|
|
178
|
+
curieDataset.add(dataFactory.quad(curieSubject, quad.predicate, curieObject, quad.graph));
|
|
200
179
|
}
|
|
201
180
|
else {
|
|
202
181
|
curieDataset.add(quad);
|
|
@@ -329,7 +308,7 @@ export class AbstractShapesGraph {
|
|
|
329
308
|
addShapeNode(quad.object);
|
|
330
309
|
if (!options?.ignoreUndefinedShapes &&
|
|
331
310
|
!datasetHasMatch(quad.object)) {
|
|
332
|
-
throw new Error(`undefined shape: ${
|
|
311
|
+
throw new Error(`undefined shape: ${quad.object}`);
|
|
333
312
|
}
|
|
334
313
|
}
|
|
335
314
|
}
|
|
@@ -351,7 +330,7 @@ export class AbstractShapesGraph {
|
|
|
351
330
|
addShapeNode(identifier);
|
|
352
331
|
if (!options?.ignoreUndefinedShapes &&
|
|
353
332
|
!datasetHasMatch(identifier)) {
|
|
354
|
-
throw new Error(`undefined shape: ${
|
|
333
|
+
throw new Error(`undefined shape: ${identifier}`);
|
|
355
334
|
}
|
|
356
335
|
}
|
|
357
336
|
}
|