@manta-eu/rdf-lib 0.1.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 +21 -0
- package/dist/action-plan-schemas.d.ts +305 -0
- package/dist/action-plan-schemas.d.ts.map +1 -0
- package/dist/action-plan-schemas.js +45 -0
- package/dist/detail-view-types.d.ts +5 -0
- package/dist/detail-view-types.d.ts.map +1 -0
- package/dist/detail-view-types.js +19 -0
- package/dist/jsonld-types.d.ts +33 -0
- package/dist/jsonld-types.d.ts.map +1 -0
- package/dist/jsonld-types.js +190 -0
- package/dist/rdf-namespaces.d.ts +321 -0
- package/dist/rdf-namespaces.d.ts.map +1 -0
- package/dist/rdf-namespaces.js +310 -0
- package/dist/shacl-shape-query.d.ts +4 -0
- package/dist/shacl-shape-query.d.ts.map +1 -0
- package/dist/shacl-shape-query.js +64 -0
- package/dist/sparql-literal-escape.d.ts +2 -0
- package/dist/sparql-literal-escape.d.ts.map +1 -0
- package/dist/sparql-literal-escape.js +14 -0
- package/package.json +67 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { namespaces, sh, shaclGraphIri } from "./rdf-namespaces.js";
|
|
2
|
+
import { DataFactory } from "ldkit/rdf";
|
|
3
|
+
import { CONSTRUCT, SELECT, sparql } from "ldkit/sparql";
|
|
4
|
+
const dataFactory = new DataFactory();
|
|
5
|
+
export function buildShaclShapeQuery(shapeIri) {
|
|
6
|
+
const anyPredicateSeed = dataFactory.namedNode(namespaces[""]);
|
|
7
|
+
return CONSTRUCT `?s ?p ?o`.WHERE `
|
|
8
|
+
GRAPH ${dataFactory.namedNode(shaclGraphIri)} {
|
|
9
|
+
VALUES ?root { ${dataFactory.namedNode(shapeIri)} }
|
|
10
|
+
?root (${anyPredicateSeed}|!${anyPredicateSeed})* ?s .
|
|
11
|
+
?s ?p ?o .
|
|
12
|
+
}
|
|
13
|
+
`.build();
|
|
14
|
+
}
|
|
15
|
+
export function buildShaclPropertyQuery(shapeIri, propertyIri) {
|
|
16
|
+
const shape = dataFactory.namedNode(shapeIri);
|
|
17
|
+
const anyPredicateSeed = dataFactory.namedNode(namespaces[""]);
|
|
18
|
+
const directProperty = sparql `
|
|
19
|
+
${shape} ${dataFactory.namedNode(sh.property)} ?propertyShape .
|
|
20
|
+
?propertyShape ${dataFactory.namedNode(sh.path)} ${dataFactory.namedNode(propertyIri)} .
|
|
21
|
+
`;
|
|
22
|
+
return CONSTRUCT `?s ?p ?o`.WHERE `
|
|
23
|
+
GRAPH ${dataFactory.namedNode(shaclGraphIri)} {
|
|
24
|
+
{
|
|
25
|
+
${directProperty}
|
|
26
|
+
BIND(${shape} AS ?s)
|
|
27
|
+
BIND(${dataFactory.namedNode(sh.property)} AS ?p)
|
|
28
|
+
BIND(?propertyShape AS ?o)
|
|
29
|
+
}
|
|
30
|
+
UNION
|
|
31
|
+
{
|
|
32
|
+
${directProperty}
|
|
33
|
+
?propertyShape (${anyPredicateSeed}|!${anyPredicateSeed})* ?s .
|
|
34
|
+
?s ?p ?o .
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
`.build();
|
|
38
|
+
}
|
|
39
|
+
export function buildShaclShapeSummaryQuery(shapeIri, propertyIri) {
|
|
40
|
+
const shape = dataFactory.namedNode(shapeIri);
|
|
41
|
+
const propertyPath = propertyIri
|
|
42
|
+
? sparql `?propertyShape ${dataFactory.namedNode(sh.path)} ?path . VALUES ?path { ${dataFactory.namedNode(propertyIri)} }`
|
|
43
|
+
: sparql `?propertyShape ${dataFactory.namedNode(sh.path)} ?path .`;
|
|
44
|
+
return SELECT `DISTINCT ?targetClass ?propertyShape ?path ?name ?description ?minCount ?maxCount ?datatype ?class ?node`
|
|
45
|
+
.WHERE `
|
|
46
|
+
GRAPH ${dataFactory.namedNode(shaclGraphIri)} {
|
|
47
|
+
{
|
|
48
|
+
${shape} ${dataFactory.namedNode(sh.targetClass)} ?targetClass .
|
|
49
|
+
}
|
|
50
|
+
UNION
|
|
51
|
+
{
|
|
52
|
+
${shape} ${dataFactory.namedNode(sh.property)} ?propertyShape .
|
|
53
|
+
${propertyPath}
|
|
54
|
+
OPTIONAL { ?propertyShape ${dataFactory.namedNode(sh.name)} ?name . }
|
|
55
|
+
OPTIONAL { ?propertyShape ${dataFactory.namedNode(sh.description)} ?description . }
|
|
56
|
+
OPTIONAL { ?propertyShape ${dataFactory.namedNode(sh.minCount)} ?minCount . }
|
|
57
|
+
OPTIONAL { ?propertyShape ${dataFactory.namedNode(sh.maxCount)} ?maxCount . }
|
|
58
|
+
OPTIONAL { ?propertyShape ${dataFactory.namedNode(sh.datatype)} ?datatype . }
|
|
59
|
+
OPTIONAL { ?propertyShape ${dataFactory.namedNode(sh.class)} ?class . }
|
|
60
|
+
OPTIONAL { ?propertyShape ${dataFactory.namedNode(sh.node)} ?node . }
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
`.ORDER_BY `?path`.build();
|
|
64
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sparql-literal-escape.d.ts","sourceRoot":"","sources":["../src/sparql-literal-escape.ts"],"names":[],"mappings":"AAAA,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAe3D"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function sanitizeSparqlLiteral(value) {
|
|
2
|
+
return (value
|
|
3
|
+
.replace(/\\/g, "\\\\")
|
|
4
|
+
.replace(/"/g, '\\"')
|
|
5
|
+
.replace(/'/g, "\\'")
|
|
6
|
+
.replace(/\n/g, "\\n")
|
|
7
|
+
.replace(/\r/g, "\\r")
|
|
8
|
+
.replace(/\t/g, "\\t")
|
|
9
|
+
// eslint-disable-next-line no-control-regex
|
|
10
|
+
.replace(/\x08/g, "\\b")
|
|
11
|
+
.replace(/\f/g, "\\f")
|
|
12
|
+
// eslint-disable-next-line no-control-regex -- remaining control chars are illegal in a SPARQL string literal
|
|
13
|
+
.replace(/[\x00-\x1f]/g, ""));
|
|
14
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@manta-eu/rdf-lib",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Namespace prefixes, CURIE helpers and JSON-LD types for the Manta knowledge graph",
|
|
5
|
+
"exports": {
|
|
6
|
+
"./action-plan-schemas": {
|
|
7
|
+
"types": "./dist/action-plan-schemas.d.ts",
|
|
8
|
+
"import": "./dist/action-plan-schemas.js"
|
|
9
|
+
},
|
|
10
|
+
"./detail-view-types": {
|
|
11
|
+
"types": "./dist/detail-view-types.d.ts",
|
|
12
|
+
"import": "./dist/detail-view-types.js"
|
|
13
|
+
},
|
|
14
|
+
"./jsonld": {
|
|
15
|
+
"types": "./dist/jsonld-types.d.ts",
|
|
16
|
+
"import": "./dist/jsonld-types.js"
|
|
17
|
+
},
|
|
18
|
+
"./namespaces": {
|
|
19
|
+
"types": "./dist/rdf-namespaces.d.ts",
|
|
20
|
+
"import": "./dist/rdf-namespaces.js"
|
|
21
|
+
},
|
|
22
|
+
"./shacl-shape-query": {
|
|
23
|
+
"types": "./dist/shacl-shape-query.d.ts",
|
|
24
|
+
"import": "./dist/shacl-shape-query.js"
|
|
25
|
+
},
|
|
26
|
+
"./sparql-literal-escape": {
|
|
27
|
+
"types": "./dist/sparql-literal-escape.d.ts",
|
|
28
|
+
"import": "./dist/sparql-literal-escape.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"type": "module",
|
|
32
|
+
"author": "",
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"ldkit": "2.8.0",
|
|
39
|
+
"@manta-eu/ldo": "0.1.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"tsc-alias": "^1.9.5",
|
|
43
|
+
"typescript": "^5.0.0",
|
|
44
|
+
"vitest": "^3.0.0"
|
|
45
|
+
},
|
|
46
|
+
"files": [
|
|
47
|
+
"dist"
|
|
48
|
+
],
|
|
49
|
+
"imports": {
|
|
50
|
+
"#*": {
|
|
51
|
+
"manta-source": [
|
|
52
|
+
"./src/*",
|
|
53
|
+
"./src/*.ts",
|
|
54
|
+
"./src/*.tsx",
|
|
55
|
+
"./src/*/index.ts",
|
|
56
|
+
"./src/*/index.tsx"
|
|
57
|
+
],
|
|
58
|
+
"types": "./dist/*.d.ts",
|
|
59
|
+
"default": "./dist/*.js"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"scripts": {
|
|
63
|
+
"test": "vitest --run",
|
|
64
|
+
"types": "tsc --noEmit",
|
|
65
|
+
"build": "tsc --project tsconfig.build.json && tsc-alias --project tsconfig.build.json --resolve-full-paths"
|
|
66
|
+
}
|
|
67
|
+
}
|