n3 1.17.3 → 1.17.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/README.md +12 -5
- package/browser/n3.min.js +1 -1
- package/lib/N3DataFactory.js +1 -1
- package/lib/N3Lexer.js +3 -2
- package/lib/N3Parser.js +6 -6
- package/lib/N3Store.js +78 -70
- package/lib/N3StreamParser.js +1 -1
- package/lib/N3StreamWriter.js +1 -1
- package/lib/N3Util.js +1 -1
- package/lib/N3Writer.js +3 -3
- package/lib/index.js +9 -3
- package/package.json +2 -1
- package/src/N3Lexer.js +1 -0
- package/src/N3Parser.js +5 -5
- package/src/N3Store.js +68 -74
- package/src/N3Writer.js +1 -1
- package/src/index.js +2 -1
package/lib/N3DataFactory.js
CHANGED
|
@@ -9,7 +9,7 @@ exports.termFromId = termFromId;
|
|
|
9
9
|
exports.termToId = termToId;
|
|
10
10
|
exports.unescapeQuotes = unescapeQuotes;
|
|
11
11
|
var _IRIs = _interopRequireDefault(require("./IRIs"));
|
|
12
|
-
function _interopRequireDefault(
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
13
|
// N3.js implementations of the RDF/JS core data types
|
|
14
14
|
// See https://github.com/rdfjs/representation-task-force/blob/master/interface-spec.md
|
|
15
15
|
|
package/lib/N3Lexer.js
CHANGED
|
@@ -4,9 +4,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
var _buffer = require("buffer");
|
|
7
8
|
var _queueMicrotask = _interopRequireDefault(require("queue-microtask"));
|
|
8
9
|
var _IRIs = _interopRequireDefault(require("./IRIs"));
|
|
9
|
-
function _interopRequireDefault(
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
11
|
// **N3Lexer** tokenizes N3 documents.
|
|
11
12
|
|
|
12
13
|
const {
|
|
@@ -487,7 +488,7 @@ class N3Lexer {
|
|
|
487
488
|
if (this._input !== null && data.length !== 0) {
|
|
488
489
|
// Prepend any previous pending writes
|
|
489
490
|
if (this._pendingBuffer) {
|
|
490
|
-
data = Buffer.concat([this._pendingBuffer, data]);
|
|
491
|
+
data = _buffer.Buffer.concat([this._pendingBuffer, data]);
|
|
491
492
|
this._pendingBuffer = null;
|
|
492
493
|
}
|
|
493
494
|
// Hold if the buffer ends in an incomplete unicode sequence
|
package/lib/N3Parser.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.default = void 0;
|
|
|
7
7
|
var _N3Lexer = _interopRequireDefault(require("./N3Lexer"));
|
|
8
8
|
var _N3DataFactory = _interopRequireDefault(require("./N3DataFactory"));
|
|
9
9
|
var _IRIs = _interopRequireDefault(require("./IRIs"));
|
|
10
|
-
function _interopRequireDefault(
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
11
|
// **N3Parser** parses N3 documents.
|
|
12
12
|
|
|
13
13
|
let blankNodePrefix = 0;
|
|
@@ -232,7 +232,7 @@ class N3Parser {
|
|
|
232
232
|
} else this._subject = this._literal(token.value, this._namedNode(token.prefix));
|
|
233
233
|
break;
|
|
234
234
|
case '<<':
|
|
235
|
-
if (!this._supportsRDFStar) return this._error('Unexpected RDF
|
|
235
|
+
if (!this._supportsRDFStar) return this._error('Unexpected RDF-star syntax', token);
|
|
236
236
|
this._saveContext('<<', this._graph, null, null, null);
|
|
237
237
|
this._graph = null;
|
|
238
238
|
return this._readSubject;
|
|
@@ -309,7 +309,7 @@ class N3Parser {
|
|
|
309
309
|
this._saveContext('formula', this._graph, this._subject, this._predicate, this._graph = this._blankNode());
|
|
310
310
|
return this._readSubject;
|
|
311
311
|
case '<<':
|
|
312
|
-
if (!this._supportsRDFStar) return this._error('Unexpected RDF
|
|
312
|
+
if (!this._supportsRDFStar) return this._error('Unexpected RDF-star syntax', token);
|
|
313
313
|
this._saveContext('<<', this._graph, this._subject, this._predicate, null);
|
|
314
314
|
this._graph = null;
|
|
315
315
|
return this._readSubject;
|
|
@@ -574,7 +574,7 @@ class N3Parser {
|
|
|
574
574
|
break;
|
|
575
575
|
// {| means that the current triple is annotated with predicate-object pairs.
|
|
576
576
|
case '{|':
|
|
577
|
-
if (!this._supportsRDFStar) return this._error('Unexpected RDF
|
|
577
|
+
if (!this._supportsRDFStar) return this._error('Unexpected RDF-star syntax', token);
|
|
578
578
|
// Continue using the last triple as quoted triple subject for the predicate-object pairs.
|
|
579
579
|
const predicate = this._predicate,
|
|
580
580
|
object = this._object;
|
|
@@ -789,7 +789,7 @@ class N3Parser {
|
|
|
789
789
|
return this._readPath;
|
|
790
790
|
}
|
|
791
791
|
|
|
792
|
-
// ### `_readRDFStarTailOrGraph` reads the graph of a nested RDF
|
|
792
|
+
// ### `_readRDFStarTailOrGraph` reads the graph of a nested RDF-star quad or the end of a nested RDF-star triple
|
|
793
793
|
_readRDFStarTailOrGraph(token) {
|
|
794
794
|
if (token.type !== '>>') {
|
|
795
795
|
// An entity means this is a quad (only allowed if not already inside a graph)
|
|
@@ -799,7 +799,7 @@ class N3Parser {
|
|
|
799
799
|
return this._readRDFStarTail(token);
|
|
800
800
|
}
|
|
801
801
|
|
|
802
|
-
// ### `_readRDFStarTail` reads the end of a nested RDF
|
|
802
|
+
// ### `_readRDFStarTail` reads the end of a nested RDF-star triple
|
|
803
803
|
_readRDFStarTail(token) {
|
|
804
804
|
if (token.type !== '>>') return this._error(`Expected >> but got ${token.type}`, token);
|
|
805
805
|
// Read the quad and restore the previous context
|
package/lib/N3Store.js
CHANGED
|
@@ -3,47 +3,38 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = void 0;
|
|
6
|
+
exports.default = exports.N3EntityIndex = void 0;
|
|
7
7
|
var _readableStream = require("readable-stream");
|
|
8
8
|
var _N3DataFactory = _interopRequireWildcard(require("./N3DataFactory"));
|
|
9
9
|
var _IRIs = _interopRequireDefault(require("./IRIs"));
|
|
10
10
|
var _N3Util = require("./N3Util");
|
|
11
|
-
function _interopRequireDefault(
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
12
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
13
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u &&
|
|
13
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
14
14
|
// **N3Store** objects store N3 quads by graph in memory.
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// The number of quads is initially zero
|
|
20
|
-
this._size = 0;
|
|
21
|
-
// `_graphs` contains subject, predicate, and object indexes per graph
|
|
22
|
-
this._graphs = Object.create(null);
|
|
16
|
+
class N3EntityIndex {
|
|
17
|
+
constructor(options = {}) {
|
|
18
|
+
this._id = 1;
|
|
23
19
|
// `_ids` maps entities such as `http://xmlns.com/foaf/0.1/name` to numbers,
|
|
24
20
|
// saving memory by using only numbers as keys in `_graphs`
|
|
25
|
-
this._id = 0;
|
|
26
21
|
this._ids = Object.create(null);
|
|
27
|
-
this.
|
|
22
|
+
this._ids[''] = 1;
|
|
23
|
+
// inverse of `_ids`
|
|
24
|
+
this._entities = Object.create(null);
|
|
25
|
+
this._entities[1] = '';
|
|
28
26
|
// `_blankNodeIndex` is the index of the last automatically named blank node
|
|
29
27
|
this._blankNodeIndex = 0;
|
|
30
|
-
|
|
31
|
-
// Shift parameters if `quads` is not given
|
|
32
|
-
if (!options && quads && !quads[0]) options = quads, quads = null;
|
|
33
|
-
options = options || {};
|
|
34
28
|
this._factory = options.factory || _N3DataFactory.default;
|
|
35
|
-
|
|
36
|
-
// Add quads if passed
|
|
37
|
-
if (quads) this.addQuads(quads);
|
|
38
29
|
}
|
|
39
|
-
_termFromId(id
|
|
30
|
+
_termFromId(id) {
|
|
40
31
|
if (id[0] === '.') {
|
|
41
32
|
const entities = this._entities;
|
|
42
33
|
const terms = id.split('.');
|
|
43
34
|
const q = this._factory.quad(this._termFromId(entities[terms[1]]), this._termFromId(entities[terms[2]]), this._termFromId(entities[terms[3]]), terms[4] && this._termFromId(entities[terms[4]]));
|
|
44
35
|
return q;
|
|
45
36
|
}
|
|
46
|
-
return (0, _N3DataFactory.termFromId)(id,
|
|
37
|
+
return (0, _N3DataFactory.termFromId)(id, this._factory);
|
|
47
38
|
}
|
|
48
39
|
_termToNumericId(term) {
|
|
49
40
|
if (term.termType === 'Quad') {
|
|
@@ -60,6 +51,50 @@ class N3Store {
|
|
|
60
51
|
const str = term && term.termType === 'Quad' ? `.${this._termToNewNumericId(term.subject)}.${this._termToNewNumericId(term.predicate)}.${this._termToNewNumericId(term.object)}${(0, _N3Util.isDefaultGraph)(term.graph) ? '' : `.${this._termToNewNumericId(term.graph)}`}` : (0, _N3DataFactory.termToId)(term);
|
|
61
52
|
return this._ids[str] || (this._ids[this._entities[++this._id] = str] = this._id);
|
|
62
53
|
}
|
|
54
|
+
createBlankNode(suggestedName) {
|
|
55
|
+
let name, index;
|
|
56
|
+
// Generate a name based on the suggested name
|
|
57
|
+
if (suggestedName) {
|
|
58
|
+
name = suggestedName = `_:${suggestedName}`, index = 1;
|
|
59
|
+
while (this._ids[name]) name = suggestedName + index++;
|
|
60
|
+
}
|
|
61
|
+
// Generate a generic blank node name
|
|
62
|
+
else {
|
|
63
|
+
do {
|
|
64
|
+
name = `_:b${this._blankNodeIndex++}`;
|
|
65
|
+
} while (this._ids[name]);
|
|
66
|
+
}
|
|
67
|
+
// Add the blank node to the entities, avoiding the generation of duplicates
|
|
68
|
+
this._ids[name] = ++this._id;
|
|
69
|
+
this._entities[this._id] = name;
|
|
70
|
+
return this._factory.blankNode(name.substr(2));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// ## Constructor
|
|
75
|
+
exports.N3EntityIndex = N3EntityIndex;
|
|
76
|
+
class N3Store {
|
|
77
|
+
constructor(quads, options) {
|
|
78
|
+
// The number of quads is initially zero
|
|
79
|
+
this._size = 0;
|
|
80
|
+
// `_graphs` contains subject, predicate, and object indexes per graph
|
|
81
|
+
this._graphs = Object.create(null);
|
|
82
|
+
|
|
83
|
+
// Shift parameters if `quads` is not given
|
|
84
|
+
if (!options && quads && !quads[0]) options = quads, quads = null;
|
|
85
|
+
options = options || {};
|
|
86
|
+
this._factory = options.factory || _N3DataFactory.default;
|
|
87
|
+
this._entityIndex = options.entityIndex || new N3EntityIndex({
|
|
88
|
+
factory: this._factory
|
|
89
|
+
});
|
|
90
|
+
this._entities = this._entityIndex._entities;
|
|
91
|
+
this._termFromId = this._entityIndex._termFromId.bind(this._entityIndex);
|
|
92
|
+
this._termToNumericId = this._entityIndex._termToNumericId.bind(this._entityIndex);
|
|
93
|
+
this._termToNewNumericId = this._entityIndex._termToNewNumericId.bind(this._entityIndex);
|
|
94
|
+
|
|
95
|
+
// Add quads if passed
|
|
96
|
+
if (quads) this.addQuads(quads);
|
|
97
|
+
}
|
|
63
98
|
|
|
64
99
|
// ## Public properties
|
|
65
100
|
|
|
@@ -115,7 +150,7 @@ class N3Store {
|
|
|
115
150
|
*_findInIndex(index0, key0, key1, key2, name0, name1, name2, graphId) {
|
|
116
151
|
let tmp, index1, index2;
|
|
117
152
|
const entityKeys = this._entities;
|
|
118
|
-
const graph = this._termFromId(graphId
|
|
153
|
+
const graph = this._termFromId(entityKeys[graphId]);
|
|
119
154
|
const parts = {
|
|
120
155
|
subject: null,
|
|
121
156
|
predicate: null,
|
|
@@ -126,17 +161,17 @@ class N3Store {
|
|
|
126
161
|
if (key0) (tmp = index0, index0 = {})[key0] = tmp[key0];
|
|
127
162
|
for (const value0 in index0) {
|
|
128
163
|
if (index1 = index0[value0]) {
|
|
129
|
-
parts[name0] = this._termFromId(entityKeys[value0]
|
|
164
|
+
parts[name0] = this._termFromId(entityKeys[value0]);
|
|
130
165
|
// If a key is specified, use only that part of index 1.
|
|
131
166
|
if (key1) (tmp = index1, index1 = {})[key1] = tmp[key1];
|
|
132
167
|
for (const value1 in index1) {
|
|
133
168
|
if (index2 = index1[value1]) {
|
|
134
|
-
parts[name1] = this._termFromId(entityKeys[value1]
|
|
169
|
+
parts[name1] = this._termFromId(entityKeys[value1]);
|
|
135
170
|
// If a key is specified, use only that part of index 2, if it exists.
|
|
136
171
|
const values = key2 ? key2 in index2 ? [key2] : [] : Object.keys(index2);
|
|
137
172
|
// Create quads for all items found in index 2.
|
|
138
173
|
for (let l = 0; l < values.length; l++) {
|
|
139
|
-
parts[name2] = this._termFromId(entityKeys[values[l]]
|
|
174
|
+
parts[name2] = this._termFromId(entityKeys[values[l]]);
|
|
140
175
|
yield this._factory.quad(parts.subject, parts.predicate, parts.object, graph);
|
|
141
176
|
}
|
|
142
177
|
}
|
|
@@ -206,10 +241,10 @@ class N3Store {
|
|
|
206
241
|
// ### `_getGraphs` returns an array with the given graph,
|
|
207
242
|
// or all graphs if the argument is null or undefined.
|
|
208
243
|
_getGraphs(graph) {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
244
|
+
graph = graph === '' ? 1 : graph && (this._termToNumericId(graph) || -1);
|
|
245
|
+
return typeof graph !== 'number' ? this._graphs : {
|
|
246
|
+
[graph]: this._graphs[graph]
|
|
247
|
+
};
|
|
213
248
|
}
|
|
214
249
|
|
|
215
250
|
// ### `_uniqueEntities` returns a function that accepts an entity ID
|
|
@@ -241,7 +276,7 @@ class N3Store {
|
|
|
241
276
|
if (!predicate) graph = subject.graph, object = subject.object, predicate = subject.predicate, subject = subject.subject;
|
|
242
277
|
|
|
243
278
|
// Convert terms to internal string representation
|
|
244
|
-
graph =
|
|
279
|
+
graph = graph ? this._termToNewNumericId(graph) : 1;
|
|
245
280
|
|
|
246
281
|
// Find the graph that will contain the triple
|
|
247
282
|
let graphItem = this._graphs[graph];
|
|
@@ -307,9 +342,8 @@ class N3Store {
|
|
|
307
342
|
removeQuad(subject, predicate, object, graph) {
|
|
308
343
|
// Shift arguments if a quad object is given instead of components
|
|
309
344
|
if (!predicate) graph = subject.graph, object = subject.object, predicate = subject.predicate, subject = subject.subject;
|
|
310
|
-
|
|
311
345
|
// Convert terms to internal string representation
|
|
312
|
-
graph =
|
|
346
|
+
graph = graph ? this._termToNumericId(graph) : 1;
|
|
313
347
|
|
|
314
348
|
// Find internal identifiers for all components
|
|
315
349
|
// and verify the quad exists.
|
|
@@ -369,8 +403,6 @@ class N3Store {
|
|
|
369
403
|
// ### `readQuads` returns an generator of quads matching a pattern.
|
|
370
404
|
// Setting any field to `undefined` or `null` indicates a wildcard.
|
|
371
405
|
*readQuads(subject, predicate, object, graph) {
|
|
372
|
-
// Convert terms to internal string representation
|
|
373
|
-
graph = graph && (0, _N3DataFactory.termToId)(graph);
|
|
374
406
|
const graphs = this._getGraphs(graph);
|
|
375
407
|
let content, subjectId, predicateId, objectId;
|
|
376
408
|
|
|
@@ -404,14 +436,14 @@ class N3Store {
|
|
|
404
436
|
// Setting any field to `undefined` or `null` indicates a wildcard.
|
|
405
437
|
// For backwards compatibility, the object return also implements the Readable stream interface.
|
|
406
438
|
match(subject, predicate, object, graph) {
|
|
407
|
-
return new DatasetCoreAndReadableStream(this, subject, predicate, object, graph
|
|
439
|
+
return new DatasetCoreAndReadableStream(this, subject, predicate, object, graph, {
|
|
440
|
+
entityIndex: this._entityIndex
|
|
441
|
+
});
|
|
408
442
|
}
|
|
409
443
|
|
|
410
444
|
// ### `countQuads` returns the number of quads matching a pattern.
|
|
411
445
|
// Setting any field to `undefined` or `null` indicates a wildcard.
|
|
412
446
|
countQuads(subject, predicate, object, graph) {
|
|
413
|
-
// Convert terms to internal string representation
|
|
414
|
-
graph = graph && (0, _N3DataFactory.termToId)(graph);
|
|
415
447
|
const graphs = this._getGraphs(graph);
|
|
416
448
|
let count = 0,
|
|
417
449
|
content,
|
|
@@ -485,8 +517,6 @@ class N3Store {
|
|
|
485
517
|
// ### `forSubjects` executes the callback on all subjects that match the pattern.
|
|
486
518
|
// Setting any field to `undefined` or `null` indicates a wildcard.
|
|
487
519
|
forSubjects(callback, predicate, object, graph) {
|
|
488
|
-
// Convert terms to internal string representation
|
|
489
|
-
graph = graph && (0, _N3DataFactory.termToId)(graph);
|
|
490
520
|
const graphs = this._getGraphs(graph);
|
|
491
521
|
let content, predicateId, objectId;
|
|
492
522
|
callback = this._uniqueEntities(callback);
|
|
@@ -525,8 +555,6 @@ class N3Store {
|
|
|
525
555
|
// ### `forPredicates` executes the callback on all predicates that match the pattern.
|
|
526
556
|
// Setting any field to `undefined` or `null` indicates a wildcard.
|
|
527
557
|
forPredicates(callback, subject, object, graph) {
|
|
528
|
-
// Convert terms to internal string representation
|
|
529
|
-
graph = graph && (0, _N3DataFactory.termToId)(graph);
|
|
530
558
|
const graphs = this._getGraphs(graph);
|
|
531
559
|
let content, subjectId, objectId;
|
|
532
560
|
callback = this._uniqueEntities(callback);
|
|
@@ -565,8 +593,6 @@ class N3Store {
|
|
|
565
593
|
// ### `forObjects` executes the callback on all objects that match the pattern.
|
|
566
594
|
// Setting any field to `undefined` or `null` indicates a wildcard.
|
|
567
595
|
forObjects(callback, subject, predicate, graph) {
|
|
568
|
-
// Convert terms to internal string representation
|
|
569
|
-
graph = graph && (0, _N3DataFactory.termToId)(graph);
|
|
570
596
|
const graphs = this._getGraphs(graph);
|
|
571
597
|
let content, subjectId, predicateId;
|
|
572
598
|
callback = this._uniqueEntities(callback);
|
|
@@ -609,28 +635,13 @@ class N3Store {
|
|
|
609
635
|
this.some(quad => {
|
|
610
636
|
callback(quad.graph);
|
|
611
637
|
return true; // Halt iteration of some()
|
|
612
|
-
}, subject, predicate, object, graph);
|
|
638
|
+
}, subject, predicate, object, this._termFromId(this._entities[graph]));
|
|
613
639
|
}
|
|
614
640
|
}
|
|
615
641
|
|
|
616
642
|
// ### `createBlankNode` creates a new blank node, returning its name
|
|
617
643
|
createBlankNode(suggestedName) {
|
|
618
|
-
|
|
619
|
-
// Generate a name based on the suggested name
|
|
620
|
-
if (suggestedName) {
|
|
621
|
-
name = suggestedName = `_:${suggestedName}`, index = 1;
|
|
622
|
-
while (this._ids[name]) name = suggestedName + index++;
|
|
623
|
-
}
|
|
624
|
-
// Generate a generic blank node name
|
|
625
|
-
else {
|
|
626
|
-
do {
|
|
627
|
-
name = `_:b${this._blankNodeIndex++}`;
|
|
628
|
-
} while (this._ids[name]);
|
|
629
|
-
}
|
|
630
|
-
// Add the blank node to the entities, avoiding the generation of duplicates
|
|
631
|
-
this._ids[name] = ++this._id;
|
|
632
|
-
this._entities[this._id] = name;
|
|
633
|
-
return this._factory.blankNode(name.substr(2));
|
|
644
|
+
return this._entityIndex.createBlankNode(suggestedName);
|
|
634
645
|
}
|
|
635
646
|
|
|
636
647
|
// ### `extractLists` finds and removes all list triples
|
|
@@ -724,17 +735,12 @@ class N3Store {
|
|
|
724
735
|
}
|
|
725
736
|
}
|
|
726
737
|
|
|
727
|
-
// Determines whether the argument is a string
|
|
728
|
-
exports.default = N3Store;
|
|
729
|
-
function isString(s) {
|
|
730
|
-
return typeof s === 'string' || s instanceof String;
|
|
731
|
-
}
|
|
732
|
-
|
|
733
738
|
/**
|
|
734
739
|
* A class that implements both DatasetCore and Readable.
|
|
735
740
|
*/
|
|
741
|
+
exports.default = N3Store;
|
|
736
742
|
class DatasetCoreAndReadableStream extends _readableStream.Readable {
|
|
737
|
-
constructor(n3Store, subject, predicate, object, graph) {
|
|
743
|
+
constructor(n3Store, subject, predicate, object, graph, options) {
|
|
738
744
|
super({
|
|
739
745
|
objectMode: true
|
|
740
746
|
});
|
|
@@ -743,7 +749,8 @@ class DatasetCoreAndReadableStream extends _readableStream.Readable {
|
|
|
743
749
|
subject,
|
|
744
750
|
predicate,
|
|
745
751
|
object,
|
|
746
|
-
graph
|
|
752
|
+
graph,
|
|
753
|
+
options
|
|
747
754
|
});
|
|
748
755
|
}
|
|
749
756
|
get filtered() {
|
|
@@ -756,7 +763,8 @@ class DatasetCoreAndReadableStream extends _readableStream.Readable {
|
|
|
756
763
|
subject
|
|
757
764
|
} = this;
|
|
758
765
|
const newStore = this._filtered = new N3Store({
|
|
759
|
-
factory: n3Store._factory
|
|
766
|
+
factory: n3Store._factory,
|
|
767
|
+
entityIndex: this.options.entityIndex
|
|
760
768
|
});
|
|
761
769
|
for (const quad of n3Store.readQuads(subject, predicate, object, graph)) newStore.addQuad(quad);
|
|
762
770
|
}
|
|
@@ -779,7 +787,7 @@ class DatasetCoreAndReadableStream extends _readableStream.Readable {
|
|
|
779
787
|
return this.filtered.has(quad);
|
|
780
788
|
}
|
|
781
789
|
match(subject, predicate, object, graph) {
|
|
782
|
-
return new DatasetCoreAndReadableStream(this.filtered, subject, predicate, object, graph);
|
|
790
|
+
return new DatasetCoreAndReadableStream(this.filtered, subject, predicate, object, graph, this.options);
|
|
783
791
|
}
|
|
784
792
|
*[Symbol.iterator]() {
|
|
785
793
|
yield* this._filtered || this.n3Store.readQuads(this.subject, this.predicate, this.object, this.graph);
|
package/lib/N3StreamParser.js
CHANGED
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _readableStream = require("readable-stream");
|
|
8
8
|
var _N3Parser = _interopRequireDefault(require("./N3Parser"));
|
|
9
|
-
function _interopRequireDefault(
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
10
|
// **N3StreamParser** parses a text stream into a quad stream.
|
|
11
11
|
|
|
12
12
|
// ## Constructor
|
package/lib/N3StreamWriter.js
CHANGED
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _readableStream = require("readable-stream");
|
|
8
8
|
var _N3Writer = _interopRequireDefault(require("./N3Writer"));
|
|
9
|
-
function _interopRequireDefault(
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
10
|
// **N3StreamWriter** serializes a quad stream into a text stream.
|
|
11
11
|
|
|
12
12
|
// ## Constructor
|
package/lib/N3Util.js
CHANGED
|
@@ -12,7 +12,7 @@ exports.isVariable = isVariable;
|
|
|
12
12
|
exports.prefix = prefix;
|
|
13
13
|
exports.prefixes = prefixes;
|
|
14
14
|
var _N3DataFactory = _interopRequireDefault(require("./N3DataFactory"));
|
|
15
|
-
function _interopRequireDefault(
|
|
15
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
16
|
// **N3Util** provides N3 utility functions.
|
|
17
17
|
|
|
18
18
|
// Tests whether the given term represents an IRI
|
package/lib/N3Writer.js
CHANGED
|
@@ -8,8 +8,8 @@ var _IRIs = _interopRequireDefault(require("./IRIs"));
|
|
|
8
8
|
var _N3DataFactory = _interopRequireWildcard(require("./N3DataFactory"));
|
|
9
9
|
var _N3Util = require("./N3Util");
|
|
10
10
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
11
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u &&
|
|
12
|
-
function _interopRequireDefault(
|
|
11
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
13
|
// **N3Writer** writes N3 documents.
|
|
14
14
|
|
|
15
15
|
const DEFAULTGRAPH = _N3DataFactory.default.defaultGraph();
|
|
@@ -218,7 +218,7 @@ class N3Writer {
|
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
-
// ### `_encodeQuad` encodes an RDF
|
|
221
|
+
// ### `_encodeQuad` encodes an RDF-star quad
|
|
222
222
|
_encodeQuad({
|
|
223
223
|
subject,
|
|
224
224
|
predicate,
|
package/lib/index.js
CHANGED
|
@@ -21,6 +21,12 @@ Object.defineProperty(exports, "DefaultGraph", {
|
|
|
21
21
|
return _N3DataFactory.DefaultGraph;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
|
+
Object.defineProperty(exports, "EntityIndex", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _N3Store.N3EntityIndex;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
24
30
|
Object.defineProperty(exports, "Lexer", {
|
|
25
31
|
enumerable: true,
|
|
26
32
|
get: function () {
|
|
@@ -110,15 +116,15 @@ Object.defineProperty(exports, "termToId", {
|
|
|
110
116
|
var _N3Lexer = _interopRequireDefault(require("./N3Lexer"));
|
|
111
117
|
var _N3Parser = _interopRequireDefault(require("./N3Parser"));
|
|
112
118
|
var _N3Writer = _interopRequireDefault(require("./N3Writer"));
|
|
113
|
-
var _N3Store =
|
|
119
|
+
var _N3Store = _interopRequireWildcard(require("./N3Store"));
|
|
114
120
|
var _N3StreamParser = _interopRequireDefault(require("./N3StreamParser"));
|
|
115
121
|
var _N3StreamWriter = _interopRequireDefault(require("./N3StreamWriter"));
|
|
116
122
|
var Util = _interopRequireWildcard(require("./N3Util"));
|
|
117
123
|
exports.Util = Util;
|
|
118
124
|
var _N3DataFactory = _interopRequireWildcard(require("./N3DataFactory"));
|
|
119
125
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
120
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u &&
|
|
121
|
-
function _interopRequireDefault(
|
|
126
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
127
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
122
128
|
// Named exports
|
|
123
129
|
// Export all named exports as a default object for backward compatibility
|
|
124
130
|
var _default = exports.default = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "n3",
|
|
3
|
-
"version": "1.17.
|
|
3
|
+
"version": "1.17.5",
|
|
4
4
|
"description": "Lightning fast, asynchronous, streaming Turtle / N3 / RDF library.",
|
|
5
5
|
"author": "Ruben Verborgh <ruben.verborgh@gmail.com>",
|
|
6
6
|
"keywords": [
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"browser"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
+
"buffer": "^6.0.3",
|
|
27
28
|
"queue-microtask": "^1.1.2",
|
|
28
29
|
"readable-stream": "^4.0.0"
|
|
29
30
|
},
|
package/src/N3Lexer.js
CHANGED
package/src/N3Parser.js
CHANGED
|
@@ -239,7 +239,7 @@ export default class N3Parser {
|
|
|
239
239
|
break;
|
|
240
240
|
case '<<':
|
|
241
241
|
if (!this._supportsRDFStar)
|
|
242
|
-
return this._error('Unexpected RDF
|
|
242
|
+
return this._error('Unexpected RDF-star syntax', token);
|
|
243
243
|
this._saveContext('<<', this._graph, null, null, null);
|
|
244
244
|
this._graph = null;
|
|
245
245
|
return this._readSubject;
|
|
@@ -328,7 +328,7 @@ export default class N3Parser {
|
|
|
328
328
|
return this._readSubject;
|
|
329
329
|
case '<<':
|
|
330
330
|
if (!this._supportsRDFStar)
|
|
331
|
-
return this._error('Unexpected RDF
|
|
331
|
+
return this._error('Unexpected RDF-star syntax', token);
|
|
332
332
|
this._saveContext('<<', this._graph, this._subject, this._predicate, null);
|
|
333
333
|
this._graph = null;
|
|
334
334
|
return this._readSubject;
|
|
@@ -617,7 +617,7 @@ export default class N3Parser {
|
|
|
617
617
|
// {| means that the current triple is annotated with predicate-object pairs.
|
|
618
618
|
case '{|':
|
|
619
619
|
if (!this._supportsRDFStar)
|
|
620
|
-
return this._error('Unexpected RDF
|
|
620
|
+
return this._error('Unexpected RDF-star syntax', token);
|
|
621
621
|
// Continue using the last triple as quoted triple subject for the predicate-object pairs.
|
|
622
622
|
const predicate = this._predicate, object = this._object;
|
|
623
623
|
this._subject = this._quad(subject, predicate, object, this.DEFAULTGRAPH);
|
|
@@ -851,7 +851,7 @@ export default class N3Parser {
|
|
|
851
851
|
return this._readPath;
|
|
852
852
|
}
|
|
853
853
|
|
|
854
|
-
// ### `_readRDFStarTailOrGraph` reads the graph of a nested RDF
|
|
854
|
+
// ### `_readRDFStarTailOrGraph` reads the graph of a nested RDF-star quad or the end of a nested RDF-star triple
|
|
855
855
|
_readRDFStarTailOrGraph(token) {
|
|
856
856
|
if (token.type !== '>>') {
|
|
857
857
|
// An entity means this is a quad (only allowed if not already inside a graph)
|
|
@@ -862,7 +862,7 @@ export default class N3Parser {
|
|
|
862
862
|
return this._readRDFStarTail(token);
|
|
863
863
|
}
|
|
864
864
|
|
|
865
|
-
// ### `_readRDFStarTail` reads the end of a nested RDF
|
|
865
|
+
// ### `_readRDFStarTail` reads the end of a nested RDF-star triple
|
|
866
866
|
_readRDFStarTail(token) {
|
|
867
867
|
if (token.type !== '>>')
|
|
868
868
|
return this._error(`Expected >> but got ${token.type}`, token);
|