n3 1.16.1 → 1.16.3
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 +21 -8
- package/browser/n3.min.js +1 -1
- package/lib/N3Store.js +20 -25
- package/lib/N3Writer.js +1 -1
- package/package.json +4 -4
- package/src/N3Store.js +13 -17
- package/src/N3Writer.js +1 -1
package/lib/N3Store.js
CHANGED
|
@@ -96,36 +96,30 @@ class N3Store {
|
|
|
96
96
|
|
|
97
97
|
|
|
98
98
|
*_findInIndex(index0, key0, key1, key2, name0, name1, name2, graphId) {
|
|
99
|
-
let tmp, index1, index2;
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
99
|
+
let tmp, index1, index2;
|
|
100
|
+
const entityKeys = this._entities;
|
|
101
|
+
const graph = (0, _N3DataFactory.termFromId)(graphId, this._factory);
|
|
102
|
+
const parts = {
|
|
103
|
+
subject: null,
|
|
104
|
+
predicate: null,
|
|
105
|
+
object: null
|
|
106
|
+
}; // If a key is specified, use only that part of index 0.
|
|
104
107
|
|
|
105
108
|
if (key0) (tmp = index0, index0 = {})[key0] = tmp[key0];
|
|
106
109
|
|
|
107
110
|
for (const value0 in index0) {
|
|
108
|
-
const entity0 = entityKeys[value0];
|
|
109
|
-
|
|
110
111
|
if (index1 = index0[value0]) {
|
|
111
|
-
// If a key is specified, use only that part of index 1.
|
|
112
|
+
parts[name0] = (0, _N3DataFactory.termFromId)(entityKeys[value0], this._factory); // If a key is specified, use only that part of index 1.
|
|
113
|
+
|
|
112
114
|
if (key1) (tmp = index1, index1 = {})[key1] = tmp[key1];
|
|
113
115
|
|
|
114
116
|
for (const value1 in index1) {
|
|
115
|
-
const entity1 = entityKeys[value1];
|
|
116
|
-
|
|
117
117
|
if (index2 = index1[value1]) {
|
|
118
|
-
// If a key is specified, use only that part of index 2, if it exists.
|
|
118
|
+
parts[name1] = (0, _N3DataFactory.termFromId)(entityKeys[value1], this._factory); // If a key is specified, use only that part of index 2, if it exists.
|
|
119
|
+
|
|
119
120
|
const values = key2 ? key2 in index2 ? [key2] : [] : Object.keys(index2); // Create quads for all items found in index 2.
|
|
120
121
|
|
|
121
122
|
for (let l = 0; l < values.length; l++) {
|
|
122
|
-
const parts = {
|
|
123
|
-
subject: null,
|
|
124
|
-
predicate: null,
|
|
125
|
-
object: null
|
|
126
|
-
};
|
|
127
|
-
parts[name0] = (0, _N3DataFactory.termFromId)(entity0, this._factory);
|
|
128
|
-
parts[name1] = (0, _N3DataFactory.termFromId)(entity1, this._factory);
|
|
129
123
|
parts[name2] = (0, _N3DataFactory.termFromId)(entityKeys[values[l]], this._factory);
|
|
130
124
|
yield this._factory.quad(parts.subject, parts.predicate, parts.object, graph);
|
|
131
125
|
}
|
|
@@ -394,12 +388,12 @@ class N3Store {
|
|
|
394
388
|
// Choose the optimal index, based on what fields are present
|
|
395
389
|
if (subjectId) {
|
|
396
390
|
if (objectId) // If subject and object are given, the object index will be the fastest
|
|
397
|
-
yield* this._findInIndex(content.objects, objectId, subjectId, predicateId, 'object', 'subject', 'predicate', graphId
|
|
398
|
-
yield* this._findInIndex(content.subjects, subjectId, predicateId, null, 'subject', 'predicate', 'object', graphId
|
|
391
|
+
yield* this._findInIndex(content.objects, objectId, subjectId, predicateId, 'object', 'subject', 'predicate', graphId);else // If only subject and possibly predicate are given, the subject index will be the fastest
|
|
392
|
+
yield* this._findInIndex(content.subjects, subjectId, predicateId, null, 'subject', 'predicate', 'object', graphId);
|
|
399
393
|
} else if (predicateId) // If only predicate and possibly object are given, the predicate index will be the fastest
|
|
400
|
-
yield* this._findInIndex(content.predicates, predicateId, objectId, null, 'predicate', 'object', 'subject', graphId
|
|
401
|
-
yield* this._findInIndex(content.objects, objectId, null, null, 'object', 'subject', 'predicate', graphId
|
|
402
|
-
yield* this._findInIndex(content.subjects, null, null, null, 'subject', 'predicate', 'object', graphId
|
|
394
|
+
yield* this._findInIndex(content.predicates, predicateId, objectId, null, 'predicate', 'object', 'subject', graphId);else if (objectId) // If only object is given, the object index will be the fastest
|
|
395
|
+
yield* this._findInIndex(content.objects, objectId, null, null, 'object', 'subject', 'predicate', graphId);else // If nothing is given, iterate subjects and predicates first
|
|
396
|
+
yield* this._findInIndex(content.subjects, null, null, null, 'subject', 'predicate', 'object', graphId);
|
|
403
397
|
}
|
|
404
398
|
}
|
|
405
399
|
} // ### `match` returns a new dataset that is comprised of all quads in the current instance matching the given arguments.
|
|
@@ -773,10 +767,11 @@ class DatasetCoreAndReadableStream extends _readableStream.Readable {
|
|
|
773
767
|
predicate,
|
|
774
768
|
subject
|
|
775
769
|
} = this;
|
|
776
|
-
const
|
|
777
|
-
this._filtered = new N3Store(quads, {
|
|
770
|
+
const newStore = this._filtered = new N3Store({
|
|
778
771
|
factory: n3Store._factory
|
|
779
772
|
});
|
|
773
|
+
|
|
774
|
+
for (const quad of n3Store.readQuads(subject, predicate, object, graph)) newStore.addQuad(quad);
|
|
780
775
|
}
|
|
781
776
|
|
|
782
777
|
return this._filtered;
|
package/lib/N3Writer.js
CHANGED
|
@@ -301,7 +301,7 @@ class N3Writer {
|
|
|
301
301
|
}
|
|
302
302
|
|
|
303
303
|
IRIlist = escapeRegex(IRIlist, /[\]\/\(\)\*\+\?\.\\\$]/g, '\\$&');
|
|
304
|
-
this._prefixRegex = new RegExp(`^(?:${prefixList})[^\/]*$|` + `^(${IRIlist})([
|
|
304
|
+
this._prefixRegex = new RegExp(`^(?:${prefixList})[^\/]*$|` + `^(${IRIlist})([_a-zA-Z][\\-_a-zA-Z0-9]*)$`);
|
|
305
305
|
} // End a prefix block with a newline
|
|
306
306
|
|
|
307
307
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "n3",
|
|
3
|
-
"version": "1.16.
|
|
3
|
+
"version": "1.16.3",
|
|
4
4
|
"description": "Lightning fast, asynchronous, streaming Turtle / N3 / RDF library.",
|
|
5
5
|
"author": "Ruben Verborgh <ruben.verborgh@gmail.com>",
|
|
6
6
|
"keywords": [
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"module": "./src/index.js",
|
|
16
16
|
"sideEffects": false,
|
|
17
17
|
"engines": {
|
|
18
|
-
"node": ">=
|
|
18
|
+
"node": ">=12.0"
|
|
19
19
|
},
|
|
20
20
|
"files": [
|
|
21
21
|
".babelrc",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"queue-microtask": "^1.1.2",
|
|
28
|
-
"readable-stream": "^
|
|
28
|
+
"readable-stream": "^4.0.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@babel/cli": "^7.16.0",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"mocha": "^8.0.0",
|
|
43
43
|
"nyc": "^14.1.1",
|
|
44
44
|
"pre-commit": "^1.2.2",
|
|
45
|
-
"rdf-test-suite": "^1.2
|
|
45
|
+
"rdf-test-suite": "^1.19.2",
|
|
46
46
|
"streamify-string": "^1.0.1",
|
|
47
47
|
"uglify-js": "^3.14.3"
|
|
48
48
|
},
|
package/src/N3Store.js
CHANGED
|
@@ -87,30 +87,24 @@ export default class N3Store {
|
|
|
87
87
|
// Finally, `graphId` will be the graph of the created quads.
|
|
88
88
|
*_findInIndex(index0, key0, key1, key2, name0, name1, name2, graphId) {
|
|
89
89
|
let tmp, index1, index2;
|
|
90
|
-
|
|
91
|
-
const varCount = !key0 + !key1 + !key2,
|
|
92
|
-
entityKeys = varCount > 1 ? Object.keys(this._ids) : this._entities;
|
|
90
|
+
const entityKeys = this._entities;
|
|
93
91
|
const graph = termFromId(graphId, this._factory);
|
|
92
|
+
const parts = { subject: null, predicate: null, object: null };
|
|
94
93
|
|
|
95
94
|
// If a key is specified, use only that part of index 0.
|
|
96
95
|
if (key0) (tmp = index0, index0 = {})[key0] = tmp[key0];
|
|
97
96
|
for (const value0 in index0) {
|
|
98
|
-
const entity0 = entityKeys[value0];
|
|
99
|
-
|
|
100
97
|
if (index1 = index0[value0]) {
|
|
98
|
+
parts[name0] = termFromId(entityKeys[value0], this._factory);
|
|
101
99
|
// If a key is specified, use only that part of index 1.
|
|
102
100
|
if (key1) (tmp = index1, index1 = {})[key1] = tmp[key1];
|
|
103
101
|
for (const value1 in index1) {
|
|
104
|
-
const entity1 = entityKeys[value1];
|
|
105
|
-
|
|
106
102
|
if (index2 = index1[value1]) {
|
|
103
|
+
parts[name1] = termFromId(entityKeys[value1], this._factory);
|
|
107
104
|
// If a key is specified, use only that part of index 2, if it exists.
|
|
108
105
|
const values = key2 ? (key2 in index2 ? [key2] : []) : Object.keys(index2);
|
|
109
106
|
// Create quads for all items found in index 2.
|
|
110
107
|
for (let l = 0; l < values.length; l++) {
|
|
111
|
-
const parts = { subject: null, predicate: null, object: null };
|
|
112
|
-
parts[name0] = termFromId(entity0, this._factory);
|
|
113
|
-
parts[name1] = termFromId(entity1, this._factory);
|
|
114
108
|
parts[name2] = termFromId(entityKeys[values[l]], this._factory);
|
|
115
109
|
yield this._factory.quad(parts.subject, parts.predicate, parts.object, graph);
|
|
116
110
|
}
|
|
@@ -378,24 +372,24 @@ export default class N3Store {
|
|
|
378
372
|
if (objectId)
|
|
379
373
|
// If subject and object are given, the object index will be the fastest
|
|
380
374
|
yield* this._findInIndex(content.objects, objectId, subjectId, predicateId,
|
|
381
|
-
'object', 'subject', 'predicate', graphId
|
|
375
|
+
'object', 'subject', 'predicate', graphId);
|
|
382
376
|
else
|
|
383
377
|
// If only subject and possibly predicate are given, the subject index will be the fastest
|
|
384
378
|
yield* this._findInIndex(content.subjects, subjectId, predicateId, null,
|
|
385
|
-
'subject', 'predicate', 'object', graphId
|
|
379
|
+
'subject', 'predicate', 'object', graphId);
|
|
386
380
|
}
|
|
387
381
|
else if (predicateId)
|
|
388
382
|
// If only predicate and possibly object are given, the predicate index will be the fastest
|
|
389
383
|
yield* this._findInIndex(content.predicates, predicateId, objectId, null,
|
|
390
|
-
'predicate', 'object', 'subject', graphId
|
|
384
|
+
'predicate', 'object', 'subject', graphId);
|
|
391
385
|
else if (objectId)
|
|
392
386
|
// If only object is given, the object index will be the fastest
|
|
393
387
|
yield* this._findInIndex(content.objects, objectId, null, null,
|
|
394
|
-
'object', 'subject', 'predicate', graphId
|
|
388
|
+
'object', 'subject', 'predicate', graphId);
|
|
395
389
|
else
|
|
396
390
|
// If nothing is given, iterate subjects and predicates first
|
|
397
391
|
yield* this._findInIndex(content.subjects, null, null, null,
|
|
398
|
-
'subject', 'predicate', 'object', graphId
|
|
392
|
+
'subject', 'predicate', 'object', graphId);
|
|
399
393
|
}
|
|
400
394
|
}
|
|
401
395
|
}
|
|
@@ -787,11 +781,13 @@ class DatasetCoreAndReadableStream extends Readable {
|
|
|
787
781
|
get filtered() {
|
|
788
782
|
if (!this._filtered) {
|
|
789
783
|
const { n3Store, graph, object, predicate, subject } = this;
|
|
790
|
-
const
|
|
791
|
-
|
|
784
|
+
const newStore = this._filtered = new N3Store({ factory: n3Store._factory });
|
|
785
|
+
for (const quad of n3Store.readQuads(subject, predicate, object, graph))
|
|
786
|
+
newStore.addQuad(quad);
|
|
792
787
|
}
|
|
793
788
|
return this._filtered;
|
|
794
789
|
}
|
|
790
|
+
|
|
795
791
|
get size() {
|
|
796
792
|
return this.filtered.size;
|
|
797
793
|
}
|
package/src/N3Writer.js
CHANGED
|
@@ -296,7 +296,7 @@ export default class N3Writer {
|
|
|
296
296
|
}
|
|
297
297
|
IRIlist = escapeRegex(IRIlist, /[\]\/\(\)\*\+\?\.\\\$]/g, '\\$&');
|
|
298
298
|
this._prefixRegex = new RegExp(`^(?:${prefixList})[^\/]*$|` +
|
|
299
|
-
`^(${IRIlist})([
|
|
299
|
+
`^(${IRIlist})([_a-zA-Z][\\-_a-zA-Z0-9]*)$`);
|
|
300
300
|
}
|
|
301
301
|
// End a prefix block with a newline
|
|
302
302
|
this._write(hasPrefixes ? '\n' : '', done);
|