@faubulous/mentor-rdf 0.1.3 → 0.1.5
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/rdf/owl-reasoner.d.ts +1 -1
- package/dist/rdf/owl-reasoner.js +9 -10
- package/dist/rdf/owl-reasoner.js.map +1 -1
- package/dist/rdf/property-repository.d.ts +0 -0
- package/dist/rdf/property-repository.js +2 -0
- package/dist/rdf/property-repository.js.map +1 -0
- package/dist/rdf/rdfs-reasoner.d.ts +5 -4
- package/dist/rdf/rdfs-reasoner.js +24 -18
- package/dist/rdf/rdfs-reasoner.js.map +1 -1
- package/dist/rdf/reasoner.d.ts +10 -0
- package/dist/rdf/reasoner.js +3 -0
- package/dist/rdf/reasoner.js.map +1 -0
- package/dist/rdf/store-factory.d.ts +23 -1
- package/dist/rdf/store-factory.js +24 -7
- package/dist/rdf/store-factory.js.map +1 -1
- package/package.json +1 -1
|
@@ -4,5 +4,5 @@ import { RdfsReasoner } from "./rdfs-reasoner";
|
|
|
4
4
|
* A simple OWL reasoner that expands the graph with inferred triples.
|
|
5
5
|
*/
|
|
6
6
|
export declare class OwlReasoner extends RdfsReasoner {
|
|
7
|
-
protected inferClassAxioms(store: n3.Store,
|
|
7
|
+
protected inferClassAxioms(store: n3.Store, targetGraph: n3.Quad_Graph, lists: Record<string, n3.Term[]>, quad: n3.Quad): void;
|
|
8
8
|
}
|
package/dist/rdf/owl-reasoner.js
CHANGED
|
@@ -7,27 +7,26 @@ const rdfs_reasoner_1 = require("./rdfs-reasoner");
|
|
|
7
7
|
* A simple OWL reasoner that expands the graph with inferred triples.
|
|
8
8
|
*/
|
|
9
9
|
class OwlReasoner extends rdfs_reasoner_1.RdfsReasoner {
|
|
10
|
-
inferClassAxioms(store,
|
|
11
|
-
super.inferClassAxioms(store,
|
|
10
|
+
inferClassAxioms(store, targetGraph, lists, quad) {
|
|
11
|
+
super.inferClassAxioms(store, targetGraph, lists, quad);
|
|
12
12
|
let s = quad.subject;
|
|
13
13
|
let p = quad.predicate;
|
|
14
14
|
let o = quad.object.termType != "Literal" ? quad.object : undefined;
|
|
15
15
|
if (!o) {
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
|
-
let g = this.getInferenceGraphNode(graph);
|
|
19
18
|
// See: https://www.w3.org/TR/owl2-profiles/#Reasoning_in_OWL_2_RL_and_RDF_Graphs_using_Rules
|
|
20
19
|
switch (p.id) {
|
|
21
20
|
case ontologies_1.owl.equivalentClass.id:
|
|
22
21
|
case ontologies_1.owl.complementOf.id:
|
|
23
22
|
case ontologies_1.owl.disjointWith.id: {
|
|
24
|
-
store.addQuad(s, ontologies_1.rdf.type, ontologies_1.rdfs.Class,
|
|
23
|
+
store.addQuad(s, ontologies_1.rdf.type, ontologies_1.rdfs.Class, targetGraph);
|
|
25
24
|
if (o && !o.value.startsWith("http://www.w3.org")) {
|
|
26
|
-
store.addQuad(o, ontologies_1.rdf.type, ontologies_1.rdfs.Class,
|
|
25
|
+
store.addQuad(o, ontologies_1.rdf.type, ontologies_1.rdfs.Class, targetGraph);
|
|
27
26
|
}
|
|
28
27
|
// The opposite is also true.
|
|
29
28
|
if (o.termType == "NamedNode") {
|
|
30
|
-
store.addQuad(o, ontologies_1.owl.equivalentClass, s,
|
|
29
|
+
store.addQuad(o, ontologies_1.owl.equivalentClass, s, targetGraph);
|
|
31
30
|
}
|
|
32
31
|
break;
|
|
33
32
|
}
|
|
@@ -40,9 +39,9 @@ class OwlReasoner extends rdfs_reasoner_1.RdfsReasoner {
|
|
|
40
39
|
if (c.termType != "NamedNode") {
|
|
41
40
|
continue;
|
|
42
41
|
}
|
|
43
|
-
store.addQuad(s, ontologies_1.rdfs.subClassOf, c,
|
|
42
|
+
store.addQuad(s, ontologies_1.rdfs.subClassOf, c, targetGraph);
|
|
44
43
|
for (let es of equivalentSubjects) {
|
|
45
|
-
store.addQuad(es, ontologies_1.rdfs.subClassOf, c,
|
|
44
|
+
store.addQuad(es, ontologies_1.rdfs.subClassOf, c, targetGraph);
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
47
|
break;
|
|
@@ -56,9 +55,9 @@ class OwlReasoner extends rdfs_reasoner_1.RdfsReasoner {
|
|
|
56
55
|
if (c.termType != "NamedNode") {
|
|
57
56
|
continue;
|
|
58
57
|
}
|
|
59
|
-
store.addQuad(c, ontologies_1.rdfs.subClassOf, s,
|
|
58
|
+
store.addQuad(c, ontologies_1.rdfs.subClassOf, s, targetGraph);
|
|
60
59
|
for (let es of equivalentSubjects) {
|
|
61
|
-
store.addQuad(c, ontologies_1.rdfs.subClassOf, es,
|
|
60
|
+
store.addQuad(c, ontologies_1.rdfs.subClassOf, es, targetGraph);
|
|
62
61
|
}
|
|
63
62
|
}
|
|
64
63
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"owl-reasoner.js","sourceRoot":"","sources":["../../src/rdf/owl-reasoner.ts"],"names":[],"mappings":";;;AACA,8CAA+C;AAC/C,mDAA+C;AAE/C;;GAEG;AACH,MAAa,WAAY,SAAQ,4BAAY;
|
|
1
|
+
{"version":3,"file":"owl-reasoner.js","sourceRoot":"","sources":["../../src/rdf/owl-reasoner.ts"],"names":[],"mappings":";;;AACA,8CAA+C;AAC/C,mDAA+C;AAE/C;;GAEG;AACH,MAAa,WAAY,SAAQ,4BAAY;IAC/B,gBAAgB,CAAC,KAAe,EAAE,WAA0B,EAAE,KAAgC,EAAE,IAAa;QACnH,KAAK,CAAC,gBAAgB,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QAExD,IAAI,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC;QACrB,IAAI,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC;QACvB,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;QAEpE,IAAI,CAAC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BACZ;oBAED,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,iBAAI,CAAC,UAAU,EAAE,CAAC,EAAE,WAAW,CAAC,CAAC;oBAElD,KAAK,IAAI,EAAE,IAAI,kBAAkB,EAAE;wBAC/B,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,iBAAI,CAAC,UAAU,EAAE,CAAC,EAAE,WAAW,CAAC,CAAC;qBACtD;iBACJ;gBACD,MAAM;aACT;YACD,KAAK,gBAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;gBACjB,IAAI,kBAAkB,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,gBAAG,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC;qBAClE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;qBACnB,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,IAAI,WAAW,CAAC,CAAC;gBAE5C,gBAAgB;gBAChB,KAAK,IAAI,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE;oBAC1B,IAAI,CAAC,CAAC,QAAQ,IAAI,WAAW,EAAE;wBAC3B,SAAS;qBACZ;oBAED,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,iBAAI,CAAC,UAAU,EAAE,CAAC,EAAE,WAAW,CAAC,CAAC;oBAElD,KAAK,IAAI,EAAE,IAAI,kBAAkB,EAAE;wBAC/B,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,iBAAI,CAAC,UAAU,EAAE,EAAE,EAAE,WAAW,CAAC,CAAC;qBACtD;iBACJ;gBACD,MAAM;aACT;SACJ;IACL,CAAC;CACJ;AAtED,kCAsEC"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"property-repository.js","sourceRoot":"","sources":["../../src/rdf/property-repository.ts"],"names":[],"mappings":""}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import * as n3 from "n3";
|
|
2
|
+
import { IReasoner } from "./reasoner";
|
|
2
3
|
/**
|
|
3
4
|
* A simple RDFS reasoner that expands the graph with inferred triples.
|
|
4
5
|
*/
|
|
5
|
-
export declare class RdfsReasoner {
|
|
6
|
-
expand(store: n3.Store,
|
|
7
|
-
protected
|
|
8
|
-
protected inferClassAxioms(store: n3.Store, graph: n3.
|
|
6
|
+
export declare class RdfsReasoner implements IReasoner {
|
|
7
|
+
expand(store: n3.Store, sourceGraph: string | n3.Quad_Graph, targetGraph: string | n3.Quad_Graph): n3.Store;
|
|
8
|
+
protected getGraphNode(graph: string | n3.Quad_Graph): n3.Quad_Graph;
|
|
9
|
+
protected inferClassAxioms(store: n3.Store, graph: n3.Quad_Graph, lists: Record<string, n3.Term[]>, quad: n3.Quad): void;
|
|
9
10
|
}
|
|
@@ -8,16 +8,23 @@ const ontologies_1 = require("../ontologies");
|
|
|
8
8
|
* A simple RDFS reasoner that expands the graph with inferred triples.
|
|
9
9
|
*/
|
|
10
10
|
class RdfsReasoner {
|
|
11
|
-
expand(store,
|
|
11
|
+
expand(store, sourceGraph, targetGraph) {
|
|
12
|
+
let s = this.getGraphNode(sourceGraph);
|
|
13
|
+
let t = this.getGraphNode(targetGraph);
|
|
12
14
|
const lists = store.extractLists();
|
|
13
15
|
// Todo: Add the inferred triples to a new subgraph.
|
|
14
|
-
for (let q of store.match(null, null, null)) {
|
|
15
|
-
this.inferClassAxioms(store,
|
|
16
|
+
for (let q of store.match(null, null, null, s)) {
|
|
17
|
+
this.inferClassAxioms(store, t, lists, q);
|
|
16
18
|
}
|
|
17
19
|
return store;
|
|
18
20
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
getGraphNode(graph) {
|
|
22
|
+
if (typeof graph == "string") {
|
|
23
|
+
return new n3.NamedNode(graph);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
return graph;
|
|
27
|
+
}
|
|
21
28
|
}
|
|
22
29
|
inferClassAxioms(store, graph, lists, quad) {
|
|
23
30
|
let s = quad.subject;
|
|
@@ -26,43 +33,42 @@ class RdfsReasoner {
|
|
|
26
33
|
if (!o) {
|
|
27
34
|
return;
|
|
28
35
|
}
|
|
29
|
-
let g = this.getInferenceGraphNode(graph);
|
|
30
36
|
switch (p.id) {
|
|
31
37
|
case ontologies_1.rdf.type.id: {
|
|
32
38
|
if (o.equals(ontologies_1.owl.Class)) {
|
|
33
|
-
store.addQuad(s, ontologies_1.rdf.type, ontologies_1.rdfs.Class,
|
|
39
|
+
store.addQuad(s, ontologies_1.rdf.type, ontologies_1.rdfs.Class, graph);
|
|
34
40
|
}
|
|
35
41
|
else if (!o.value.startsWith("http://www.w3.org")) {
|
|
36
|
-
store.addQuad(o, ontologies_1.rdf.type, ontologies_1.rdfs.Class,
|
|
42
|
+
store.addQuad(o, ontologies_1.rdf.type, ontologies_1.rdfs.Class, graph);
|
|
37
43
|
}
|
|
38
44
|
break;
|
|
39
45
|
}
|
|
40
46
|
case ontologies_1.rdfs.subClassOf.id: {
|
|
41
|
-
store.addQuad(s, ontologies_1.rdf.type, ontologies_1.rdfs.Class,
|
|
47
|
+
store.addQuad(s, ontologies_1.rdf.type, ontologies_1.rdfs.Class, graph);
|
|
42
48
|
if (!o.value.startsWith("http://www.w3.org")) {
|
|
43
|
-
store.addQuad(o, ontologies_1.rdf.type, ontologies_1.rdfs.Class,
|
|
49
|
+
store.addQuad(o, ontologies_1.rdf.type, ontologies_1.rdfs.Class, graph);
|
|
44
50
|
}
|
|
45
51
|
else if (o.equals(ontologies_1.rdfs.Resource)) {
|
|
46
|
-
store.addQuad(ontologies_1.rdfs.Resource, ontologies_1.rdf.type, ontologies_1.rdfs.Class,
|
|
52
|
+
store.addQuad(ontologies_1.rdfs.Resource, ontologies_1.rdf.type, ontologies_1.rdfs.Class, graph);
|
|
47
53
|
}
|
|
48
54
|
else if (o.equals(ontologies_1.rdfs.Class)) {
|
|
49
|
-
store.addQuad(ontologies_1.rdfs.Class, ontologies_1.rdf.type, ontologies_1.rdfs.Class,
|
|
50
|
-
store.addQuad(ontologies_1.rdfs.Class, ontologies_1.rdfs.subClassOf, ontologies_1.rdfs.Resource,
|
|
55
|
+
store.addQuad(ontologies_1.rdfs.Class, ontologies_1.rdf.type, ontologies_1.rdfs.Class, graph);
|
|
56
|
+
store.addQuad(ontologies_1.rdfs.Class, ontologies_1.rdfs.subClassOf, ontologies_1.rdfs.Resource, graph);
|
|
51
57
|
}
|
|
52
58
|
else if (o.equals(ontologies_1.rdfs.Datatype)) {
|
|
53
|
-
store.addQuad(ontologies_1.rdfs.Datatype, ontologies_1.rdf.type, ontologies_1.rdfs.Class,
|
|
54
|
-
store.addQuad(ontologies_1.rdfs.Datatype, ontologies_1.rdfs.subClassOf, ontologies_1.rdfs.Class,
|
|
59
|
+
store.addQuad(ontologies_1.rdfs.Datatype, ontologies_1.rdf.type, ontologies_1.rdfs.Class, graph);
|
|
60
|
+
store.addQuad(ontologies_1.rdfs.Datatype, ontologies_1.rdfs.subClassOf, ontologies_1.rdfs.Class, graph);
|
|
55
61
|
}
|
|
56
62
|
else if (o.equals(ontologies_1.owl.Class)) {
|
|
57
|
-
store.addQuad(ontologies_1.owl.Class, ontologies_1.rdf.type, ontologies_1.rdfs.Class,
|
|
58
|
-
store.addQuad(ontologies_1.owl.Class, ontologies_1.rdfs.subClassOf, ontologies_1.rdfs.Class,
|
|
63
|
+
store.addQuad(ontologies_1.owl.Class, ontologies_1.rdf.type, ontologies_1.rdfs.Class, graph);
|
|
64
|
+
store.addQuad(ontologies_1.owl.Class, ontologies_1.rdfs.subClassOf, ontologies_1.rdfs.Class, graph);
|
|
59
65
|
}
|
|
60
66
|
break;
|
|
61
67
|
}
|
|
62
68
|
case ontologies_1.rdfs.range.id:
|
|
63
69
|
case ontologies_1.rdfs.domain.id: {
|
|
64
70
|
if (!o.value.startsWith("http://www.w3.org")) {
|
|
65
|
-
store.addQuad(o, ontologies_1.rdf.type, ontologies_1.rdfs.Class,
|
|
71
|
+
store.addQuad(o, ontologies_1.rdf.type, ontologies_1.rdfs.Class, graph);
|
|
66
72
|
}
|
|
67
73
|
break;
|
|
68
74
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rdfs-reasoner.js","sourceRoot":"","sources":["../../src/rdf/rdfs-reasoner.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,8CAA+C;
|
|
1
|
+
{"version":3,"file":"rdfs-reasoner.js","sourceRoot":"","sources":["../../src/rdf/rdfs-reasoner.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,8CAA+C;AAG/C;;GAEG;AACH,MAAa,YAAY;IACd,MAAM,CAAC,KAAe,EAAE,WAAmC,EAAE,WAAmC;QACnG,IAAI,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;QACvC,IAAI,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;QAEvC,MAAM,KAAK,GAAG,KAAK,CAAC,YAAY,EAA+B,CAAC;QAEhE,oDAAoD;QACpD,KAAK,IAAI,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE;YAC5C,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,CAAY,CAAC,CAAC;SACxD;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;IAES,YAAY,CAAC,KAA6B;QAChD,IAAI,OAAO,KAAK,IAAI,QAAQ,EAAE;YAC1B,OAAO,IAAI,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;SAClC;aAAM;YACH,OAAO,KAAK,CAAC;SAChB;IACL,CAAC;IAES,gBAAgB,CAAC,KAAe,EAAE,KAAoB,EAAE,KAAgC,EAAE,IAAa;QAC7G,IAAI,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC;QACrB,IAAI,CAAC,GAAG,IAAI,CAAC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C,CAAC,EAAE,gBAAG,CAAC,IAAI,EAAE,iBAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;iBACjD;gBACD,MAAM;aACT;SACJ;IACL,CAAC;CACJ;AArED,oCAqEC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as n3 from 'n3';
|
|
2
|
+
export interface IReasoner {
|
|
3
|
+
/**
|
|
4
|
+
* Apply inference on the source graph and store the inferred triples in the target graph.
|
|
5
|
+
* @param store The store to be inferenced.
|
|
6
|
+
* @param sourceGraph The source graph where to find the triples to be inferenced.
|
|
7
|
+
* @param targetGraph The target graph where to store the inferred triples.
|
|
8
|
+
*/
|
|
9
|
+
expand(store: n3.Store, sourceGraph: string | n3.NamedNode, targetGraph: string | n3.NamedNode): n3.Store;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reasoner.js","sourceRoot":"","sources":["../../src/rdf/reasoner.ts"],"names":[],"mappings":""}
|
|
@@ -1,4 +1,18 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import * as n3 from "n3";
|
|
3
|
+
import { EventEmitter } from "stream";
|
|
4
|
+
import { IReasoner } from "./reasoner";
|
|
5
|
+
export interface ParseOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The reasoner to be used for inference.
|
|
8
|
+
*/
|
|
9
|
+
reasoner?: IReasoner;
|
|
10
|
+
/**
|
|
11
|
+
* A callback function that will be called for each parsed triple.
|
|
12
|
+
* @param quad The parsed triple.
|
|
13
|
+
*/
|
|
14
|
+
onQuad?: (quad: n3.Quad) => void;
|
|
15
|
+
}
|
|
2
16
|
/**
|
|
3
17
|
* Factory for creating RDF stores.
|
|
4
18
|
*/
|
|
@@ -9,5 +23,13 @@ export declare class StoreFactory {
|
|
|
9
23
|
* @param inference Indicates if OWL inference should be performed on the store.
|
|
10
24
|
* @returns A promise that resolves to an RDF store.
|
|
11
25
|
*/
|
|
12
|
-
static createFromFile(path: string,
|
|
26
|
+
static createFromFile(path: string, parseOptions?: ParseOptions): Promise<n3.Store>;
|
|
27
|
+
/**
|
|
28
|
+
* Create an RDF store from a file.
|
|
29
|
+
* @param input Input data or stream in Turtle format to be parsed.
|
|
30
|
+
* @param graphUri URI of the graph to in which the triples will be created.
|
|
31
|
+
* @param parseCallback Callback function that will be called for each parsed triple.
|
|
32
|
+
* @returns A promise that resolves to an RDF store.
|
|
33
|
+
*/
|
|
34
|
+
static createFromStream(input: string | EventEmitter, graphUri: string, parseOptions?: ParseOptions): Promise<n3.Store>;
|
|
13
35
|
}
|
|
@@ -4,7 +4,6 @@ exports.StoreFactory = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fs = tslib_1.__importStar(require("fs"));
|
|
6
6
|
const n3 = tslib_1.__importStar(require("n3"));
|
|
7
|
-
const owl_reasoner_1 = require("./owl-reasoner");
|
|
8
7
|
/**
|
|
9
8
|
* Factory for creating RDF stores.
|
|
10
9
|
*/
|
|
@@ -15,22 +14,40 @@ class StoreFactory {
|
|
|
15
14
|
* @param inference Indicates if OWL inference should be performed on the store.
|
|
16
15
|
* @returns A promise that resolves to an RDF store.
|
|
17
16
|
*/
|
|
18
|
-
static createFromFile(path,
|
|
17
|
+
static createFromFile(path, parseOptions) {
|
|
18
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
const graphUri = 'file://' + process.cwd() + '/src/rdf/test/gist.ttl';
|
|
20
|
+
const stream = fs.createReadStream(path);
|
|
21
|
+
return this.createFromStream(stream, graphUri, parseOptions);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Create an RDF store from a file.
|
|
26
|
+
* @param input Input data or stream in Turtle format to be parsed.
|
|
27
|
+
* @param graphUri URI of the graph to in which the triples will be created.
|
|
28
|
+
* @param parseCallback Callback function that will be called for each parsed triple.
|
|
29
|
+
* @returns A promise that resolves to an RDF store.
|
|
30
|
+
*/
|
|
31
|
+
static createFromStream(input, graphUri, parseOptions) {
|
|
19
32
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
20
33
|
return new Promise((resolve, reject) => {
|
|
21
|
-
const graph = new n3.NamedNode(
|
|
34
|
+
const graph = new n3.NamedNode(graphUri);
|
|
22
35
|
const store = new n3.Store();
|
|
23
|
-
|
|
24
|
-
new n3.Parser({}).parse(stream, (error, quad, done) => {
|
|
36
|
+
new n3.Parser({}).parse(input, (error, quad, done) => {
|
|
25
37
|
if (quad) {
|
|
26
38
|
store.add(new n3.Quad(quad.subject, quad.predicate, quad.object, graph));
|
|
39
|
+
if (parseOptions === null || parseOptions === void 0 ? void 0 : parseOptions.onQuad) {
|
|
40
|
+
parseOptions.onQuad(quad);
|
|
41
|
+
}
|
|
27
42
|
}
|
|
28
43
|
else if (error) {
|
|
29
44
|
reject(error);
|
|
30
45
|
}
|
|
31
46
|
else if (done) {
|
|
32
|
-
if (
|
|
33
|
-
|
|
47
|
+
if (parseOptions === null || parseOptions === void 0 ? void 0 : parseOptions.reasoner) {
|
|
48
|
+
// Todo: Improve URI generation to support URIs that already have a fragment id.
|
|
49
|
+
const g = graphUri + '#inference';
|
|
50
|
+
parseOptions.reasoner.expand(store, graphUri, g);
|
|
34
51
|
}
|
|
35
52
|
resolve(store);
|
|
36
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store-factory.js","sourceRoot":"","sources":["../../src/rdf/store-factory.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,+CAAyB;
|
|
1
|
+
{"version":3,"file":"store-factory.js","sourceRoot":"","sources":["../../src/rdf/store-factory.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,+CAAyB;AAiBzB;;GAEG;AACH,MAAa,YAAY;IACrB;;;;;OAKG;IACI,MAAM,CAAO,cAAc,CAAC,IAAY,EAAE,YAA2B;;YACxE,MAAM,QAAQ,GAAG,SAAS,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,wBAAw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