n3 1.11.1 → 1.11.2
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/lib/N3DataFactory.js +6 -6
- package/lib/N3Lexer.js +63 -63
- package/lib/N3Parser.js +38 -29
- package/lib/N3Store.js +19 -19
- package/lib/N3Util.js +3 -3
- package/lib/N3Writer.js +11 -11
- package/lib/index.js +31 -31
- package/package.json +5 -5
- package/src/N3Parser.js +14 -4
package/lib/N3DataFactory.js
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.default = exports.Variable = exports.Triple = exports.Term = exports.Quad = exports.NamedNode = exports.Literal = exports.DefaultGraph = exports.BlankNode = void 0;
|
|
7
|
+
exports.escapeQuotes = escapeQuotes;
|
|
6
8
|
exports.termFromId = termFromId;
|
|
7
9
|
exports.termToId = termToId;
|
|
8
|
-
exports.escapeQuotes = escapeQuotes;
|
|
9
10
|
exports.unescapeQuotes = unescapeQuotes;
|
|
10
|
-
exports.Triple = exports.Quad = exports.DefaultGraph = exports.Variable = exports.BlankNode = exports.Literal = exports.NamedNode = exports.Term = exports.default = void 0;
|
|
11
11
|
|
|
12
12
|
var _IRIs = _interopRequireDefault(require("./IRIs"));
|
|
13
13
|
|
|
@@ -353,11 +353,11 @@ function literal(value, languageOrDataType) {
|
|
|
353
353
|
// Convert a boolean
|
|
354
354
|
if (typeof value === 'boolean') datatype = xsd.boolean; // Convert an integer or double
|
|
355
355
|
else if (typeof value === 'number') {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
}
|
|
356
|
+
if (Number.isFinite(value)) datatype = Number.isInteger(value) ? xsd.integer : xsd.double;else {
|
|
357
|
+
datatype = xsd.double;
|
|
358
|
+
if (!Number.isNaN(value)) value = value > 0 ? 'INF' : '-INF';
|
|
360
359
|
}
|
|
360
|
+
}
|
|
361
361
|
} // Create a datatyped literal
|
|
362
362
|
|
|
363
363
|
|
package/lib/N3Lexer.js
CHANGED
|
@@ -95,8 +95,8 @@ class N3Lexer {
|
|
|
95
95
|
}
|
|
96
96
|
} // When not in line mode, enable N3 functionality by default
|
|
97
97
|
else {
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
this._n3Mode = options.n3 !== false;
|
|
99
|
+
} // Don't output comment tokens by default
|
|
100
100
|
|
|
101
101
|
|
|
102
102
|
this._comments = !!options.comments; // Cache the last tested closing position of long literals
|
|
@@ -167,35 +167,35 @@ class N3Lexer {
|
|
|
167
167
|
// We need at least 3 tokens lookahead to distinguish ^^<IRI> and ^^pre:fixed
|
|
168
168
|
if (input.length < 3) break; // Try to match a type
|
|
169
169
|
else if (input[1] === '^') {
|
|
170
|
-
|
|
170
|
+
this._previousMarker = '^^'; // Move to type IRI or prefixed name
|
|
171
171
|
|
|
172
|
-
|
|
172
|
+
input = input.substr(2);
|
|
173
173
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
174
|
+
if (input[0] !== '<') {
|
|
175
|
+
inconclusive = true;
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
} // If no type, it must be a path expression
|
|
179
|
+
else {
|
|
180
|
+
if (this._n3Mode) {
|
|
181
|
+
matchLength = 1;
|
|
182
|
+
type = '^';
|
|
183
|
+
}
|
|
184
184
|
|
|
185
|
-
|
|
186
|
-
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
187
|
// Fall through in case the type is an IRI
|
|
188
188
|
|
|
189
189
|
case '<':
|
|
190
190
|
// Try to find a full IRI without escape sequences
|
|
191
191
|
if (match = this._unescapedIri.exec(input)) type = 'IRI', value = match[1]; // Try to find a full IRI with escape sequences
|
|
192
192
|
else if (match = this._iri.exec(input)) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
193
|
+
value = this._unescape(match[1]);
|
|
194
|
+
if (value === null || illegalIriChars.test(value)) return reportSyntaxError(this);
|
|
195
|
+
type = 'IRI';
|
|
196
|
+
} // Try to find a nested triple
|
|
197
|
+
else if (input.length > 1 && input[1] === '<') type = '<<', matchLength = 2; // Try to find a backwards implication arrow
|
|
198
|
+
else if (this._n3Mode && input.length > 1 && input[1] === '=') type = 'inverse', matchLength = 2, value = '>';
|
|
199
199
|
break;
|
|
200
200
|
|
|
201
201
|
case '>':
|
|
@@ -213,12 +213,12 @@ class N3Lexer {
|
|
|
213
213
|
// Try to find a literal without escape sequences
|
|
214
214
|
if (match = this._simpleQuotedString.exec(input)) value = match[1]; // Try to find a literal wrapped in three pairs of quotes
|
|
215
215
|
else {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
216
|
+
({
|
|
217
|
+
value,
|
|
218
|
+
matchLength
|
|
219
|
+
} = this._parseLiteral(input));
|
|
220
|
+
if (value === null) return reportSyntaxError(this);
|
|
221
|
+
}
|
|
222
222
|
|
|
223
223
|
if (match !== null || matchLength !== 0) {
|
|
224
224
|
type = 'literal';
|
|
@@ -232,12 +232,12 @@ class N3Lexer {
|
|
|
232
232
|
// Try to find a literal without escape sequences
|
|
233
233
|
if (match = this._simpleApostropheString.exec(input)) value = match[1]; // Try to find a literal wrapped in three pairs of quotes
|
|
234
234
|
else {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
235
|
+
({
|
|
236
|
+
value,
|
|
237
|
+
matchLength
|
|
238
|
+
} = this._parseLiteral(input));
|
|
239
|
+
if (value === null) return reportSyntaxError(this);
|
|
240
|
+
}
|
|
241
241
|
|
|
242
242
|
if (match !== null || matchLength !== 0) {
|
|
243
243
|
type = 'literal';
|
|
@@ -488,45 +488,45 @@ class N3Lexer {
|
|
|
488
488
|
|
|
489
489
|
if (typeof callback === 'function') (0, _queueMicrotask.default)(() => this._tokenizeToEnd(callback, true)); // If no callback was passed, tokenize synchronously and return
|
|
490
490
|
else {
|
|
491
|
-
|
|
492
|
-
|
|
491
|
+
const tokens = [];
|
|
492
|
+
let error;
|
|
493
493
|
|
|
494
|
-
|
|
494
|
+
this._tokenizeToEnd((e, t) => e ? error = e : tokens.push(t), true);
|
|
495
495
|
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
496
|
+
if (error) throw error;
|
|
497
|
+
return tokens;
|
|
498
|
+
}
|
|
499
499
|
} // Otherwise, the input must be a stream
|
|
500
500
|
else {
|
|
501
|
-
|
|
502
|
-
|
|
501
|
+
this._pendingBuffer = null;
|
|
502
|
+
if (typeof input.setEncoding === 'function') input.setEncoding('utf8'); // Adds the data chunk to the buffer and parses as far as possible
|
|
503
503
|
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
504
|
+
input.on('data', data => {
|
|
505
|
+
if (this._input !== null && data.length !== 0) {
|
|
506
|
+
// Prepend any previous pending writes
|
|
507
|
+
if (this._pendingBuffer) {
|
|
508
|
+
data = Buffer.concat([this._pendingBuffer, data]);
|
|
509
|
+
this._pendingBuffer = null;
|
|
510
|
+
} // Hold if the buffer ends in an incomplete unicode sequence
|
|
511
511
|
|
|
512
512
|
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
513
|
+
if (data[data.length - 1] & 0x80) {
|
|
514
|
+
this._pendingBuffer = data;
|
|
515
|
+
} // Otherwise, tokenize as far as possible
|
|
516
|
+
else {
|
|
517
|
+
// Only read a BOM at the start
|
|
518
|
+
if (typeof this._input === 'undefined') this._input = this._readStartingBom(typeof data === 'string' ? data : data.toString());else this._input += data;
|
|
519
519
|
|
|
520
|
-
|
|
521
|
-
}
|
|
520
|
+
this._tokenizeToEnd(callback, false);
|
|
522
521
|
}
|
|
523
|
-
}
|
|
522
|
+
}
|
|
523
|
+
}); // Parses until the end
|
|
524
524
|
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
525
|
+
input.on('end', () => {
|
|
526
|
+
if (typeof this._input === 'string') this._tokenizeToEnd(callback, true);
|
|
527
|
+
});
|
|
528
|
+
input.on('error', callback);
|
|
529
|
+
}
|
|
530
530
|
}
|
|
531
531
|
|
|
532
532
|
}
|
package/lib/N3Parser.js
CHANGED
|
@@ -303,6 +303,14 @@ class N3Parser {
|
|
|
303
303
|
// Additional semicolons can be safely ignored
|
|
304
304
|
return this._predicate !== null ? this._readPredicate : this._error('Expected predicate but got ;', token);
|
|
305
305
|
|
|
306
|
+
case '[':
|
|
307
|
+
if (this._n3Mode) {
|
|
308
|
+
// Start a new quad with a new blank node as subject
|
|
309
|
+
this._saveContext('blank', this._graph, this._subject, this._subject = this._blankNode(), null);
|
|
310
|
+
|
|
311
|
+
return this._readBlankNodeHead;
|
|
312
|
+
}
|
|
313
|
+
|
|
306
314
|
case 'blank':
|
|
307
315
|
if (!this._n3Mode) return this._error('Disallowed blank node as predicate', token);
|
|
308
316
|
|
|
@@ -398,12 +406,13 @@ class N3Parser {
|
|
|
398
406
|
|
|
399
407
|
const empty = this._predicate === null;
|
|
400
408
|
|
|
401
|
-
this._restoreContext(); // If the blank node was the
|
|
409
|
+
this._restoreContext(); // If the blank node was the object, restore previous context and read punctuation
|
|
402
410
|
|
|
403
411
|
|
|
404
|
-
if (this._object
|
|
405
|
-
|
|
406
|
-
else
|
|
412
|
+
if (this._object !== null) return this._getContextEndReader(); // If the blank node was the predicate, continue reading the object
|
|
413
|
+
else if (this._predicate !== null) return this._readObject; // If the blank node was the subject, continue reading the predicate
|
|
414
|
+
else // If the blank node was empty, it could be a named graph label
|
|
415
|
+
return empty ? this._readPredicateOrNamedGraph : this._readPredicateAfterBlank;
|
|
407
416
|
} // ### `_readPredicateAfterBlank` reads a predicate after an anonymous blank node
|
|
408
417
|
|
|
409
418
|
|
|
@@ -464,10 +473,10 @@ class N3Parser {
|
|
|
464
473
|
if (this._subject === this.RDF_NIL) return next;
|
|
465
474
|
} // The list was in the parent context's object
|
|
466
475
|
else {
|
|
467
|
-
|
|
476
|
+
next = this._getContextEndReader(); // No list tail if this was an empty list
|
|
468
477
|
|
|
469
|
-
|
|
470
|
-
|
|
478
|
+
if (this._object === this.RDF_NIL) return next;
|
|
479
|
+
} // Close the list by making the head nil
|
|
471
480
|
|
|
472
481
|
|
|
473
482
|
list = this.RDF_NIL;
|
|
@@ -480,9 +489,9 @@ class N3Parser {
|
|
|
480
489
|
next = this._readListItemDataTypeOrLang;
|
|
481
490
|
} // Pre-datatyped string literal (prefix stores the datatype)
|
|
482
491
|
else {
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
492
|
+
item = this._literal(token.value, this._namedNode(token.prefix));
|
|
493
|
+
next = this._getContextEndReader();
|
|
494
|
+
}
|
|
486
495
|
|
|
487
496
|
break;
|
|
488
497
|
|
|
@@ -586,9 +595,9 @@ class N3Parser {
|
|
|
586
595
|
|
|
587
596
|
if (completed.token === null) return this._getContextEndReader(); // Otherwise, consume the token now
|
|
588
597
|
else {
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
598
|
+
this._readCallback = this._getContextEndReader();
|
|
599
|
+
return this._readCallback(completed.token);
|
|
600
|
+
}
|
|
592
601
|
} // ### `_readFormulaTail` reads the end of a formula
|
|
593
602
|
|
|
594
603
|
|
|
@@ -768,12 +777,12 @@ class N3Parser {
|
|
|
768
777
|
|
|
769
778
|
if (!this._explicitQuantifiers) this._quantified[entity.id] = this._quantifier(this._blankNode().value); // With explicit quantifiers, output the reified quantifier
|
|
770
779
|
else {
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
780
|
+
// If this is the first item, start a new quantifier list
|
|
781
|
+
if (this._subject === null) this._emit(this._graph || this.DEFAULTGRAPH, this._predicate, this._subject = this._blankNode(), this.QUANTIFIERS_GRAPH); // Otherwise, continue the previous list
|
|
782
|
+
else this._emit(this._subject, this.RDF_REST, this._subject = this._blankNode(), this.QUANTIFIERS_GRAPH); // Output the list item
|
|
774
783
|
|
|
775
|
-
|
|
776
|
-
|
|
784
|
+
this._emit(this._subject, this.RDF_FIRST, entity, this.QUANTIFIERS_GRAPH);
|
|
785
|
+
}
|
|
777
786
|
return this._readQuantifierPunctuation;
|
|
778
787
|
} // Reads punctuation from a @forSome or @forAll statement
|
|
779
788
|
|
|
@@ -782,17 +791,17 @@ class N3Parser {
|
|
|
782
791
|
// Read more quantifiers
|
|
783
792
|
if (token.type === ',') return this._readQuantifierList; // End of the quantifier list
|
|
784
793
|
else {
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
794
|
+
// With explicit quantifiers, close the quantifier list
|
|
795
|
+
if (this._explicitQuantifiers) {
|
|
796
|
+
this._emit(this._subject, this.RDF_REST, this.RDF_NIL, this.QUANTIFIERS_GRAPH);
|
|
788
797
|
|
|
789
|
-
|
|
790
|
-
|
|
798
|
+
this._subject = null;
|
|
799
|
+
} // Read a dot
|
|
791
800
|
|
|
792
801
|
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
802
|
+
this._readCallback = this._getContextEndReader();
|
|
803
|
+
return this._readCallback(token);
|
|
804
|
+
}
|
|
796
805
|
} // ### `_getPathReader` reads a potential path and then resumes with the given function
|
|
797
806
|
|
|
798
807
|
|
|
@@ -889,9 +898,9 @@ class N3Parser {
|
|
|
889
898
|
return this._readPredicate;
|
|
890
899
|
} // If the triple was the object, read context end.
|
|
891
900
|
else {
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
901
|
+
this._object = quad;
|
|
902
|
+
return this._getContextEndReader();
|
|
903
|
+
}
|
|
895
904
|
} // ### `_getContextEndReader` gets the next reader function at the end of a context
|
|
896
905
|
|
|
897
906
|
|
package/lib/N3Store.js
CHANGED
|
@@ -677,10 +677,10 @@ class N3Store {
|
|
|
677
677
|
while (this._ids[name]) name = suggestedName + index++;
|
|
678
678
|
} // Generate a generic blank node name
|
|
679
679
|
else {
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
680
|
+
do {
|
|
681
|
+
name = `_:b${this._blankNodeIndex++}`;
|
|
682
|
+
} while (this._ids[name]);
|
|
683
|
+
} // Add the blank node to the entities, avoiding the generation of duplicates
|
|
684
684
|
|
|
685
685
|
|
|
686
686
|
this._ids[name] = ++this._id;
|
|
@@ -728,16 +728,16 @@ class N3Store {
|
|
|
728
728
|
quad = subjectQuads[i];
|
|
729
729
|
if (!quad.graph.equals(graph)) malformed = onError(current, 'not confined to single graph');else if (head) malformed = onError(current, 'has non-list arcs out'); // one rdf:first
|
|
730
730
|
else if (quad.predicate.value === _IRIs.default.rdf.first) {
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
731
|
+
if (first) malformed = onError(current, 'has multiple rdf:first arcs');else toRemove.push(first = quad);
|
|
732
|
+
} // one rdf:rest
|
|
733
|
+
else if (quad.predicate.value === _IRIs.default.rdf.rest) {
|
|
734
|
+
if (rest) malformed = onError(current, 'has multiple rdf:rest arcs');else toRemove.push(rest = quad);
|
|
735
|
+
} // alien triple
|
|
736
|
+
else if (objectQuads.length) malformed = onError(current, 'can\'t be subject and object');else {
|
|
737
|
+
head = quad; // e.g. { (1 2 3) :p :o }
|
|
738
|
+
|
|
739
|
+
headPos = 'subject';
|
|
740
|
+
}
|
|
741
741
|
} // { :s :p (1 2) } arrives here with no head
|
|
742
742
|
// { (1 2) :p :o } arrives here with head set to the list.
|
|
743
743
|
|
|
@@ -746,12 +746,12 @@ class N3Store {
|
|
|
746
746
|
quad = objectQuads[i];
|
|
747
747
|
if (head) malformed = onError(current, 'can\'t have coreferences'); // one rdf:rest
|
|
748
748
|
else if (quad.predicate.value === _IRIs.default.rdf.rest) {
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
749
|
+
if (parent) malformed = onError(current, 'has incoming rdf:rest arcs');else parent = quad;
|
|
750
|
+
} else {
|
|
751
|
+
head = quad; // e.g. { :s :p (1 2) }
|
|
752
752
|
|
|
753
|
-
|
|
754
|
-
|
|
753
|
+
headPos = 'object';
|
|
754
|
+
}
|
|
755
755
|
} // Store the list item and continue with parent
|
|
756
756
|
|
|
757
757
|
|
package/lib/N3Util.js
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.inDefaultGraph = inDefaultGraph;
|
|
7
7
|
exports.isBlankNode = isBlankNode;
|
|
8
|
+
exports.isDefaultGraph = isDefaultGraph;
|
|
8
9
|
exports.isLiteral = isLiteral;
|
|
10
|
+
exports.isNamedNode = isNamedNode;
|
|
9
11
|
exports.isVariable = isVariable;
|
|
10
|
-
exports.isDefaultGraph = isDefaultGraph;
|
|
11
|
-
exports.inDefaultGraph = inDefaultGraph;
|
|
12
12
|
exports.prefix = prefix;
|
|
13
13
|
exports.prefixes = prefixes;
|
|
14
14
|
|
package/lib/N3Writer.js
CHANGED
|
@@ -247,7 +247,7 @@ class N3Writer {
|
|
|
247
247
|
// The quad was given as an object, so shift parameters
|
|
248
248
|
if (object === undefined) this._writeQuad(subject.subject, subject.predicate, subject.object, subject.graph, predicate); // The optional `graph` parameter was not provided
|
|
249
249
|
else if (typeof graph === 'function') this._writeQuad(subject, predicate, object, DEFAULTGRAPH, graph); // The `graph` parameter was provided
|
|
250
|
-
|
|
250
|
+
else this._writeQuad(subject, predicate, object, graph || DEFAULTGRAPH, done);
|
|
251
251
|
} // ### `addQuads` adds the quads to the output stream
|
|
252
252
|
|
|
253
253
|
|
|
@@ -312,10 +312,10 @@ class N3Writer {
|
|
|
312
312
|
|
|
313
313
|
if (predicate === undefined) children = []; // Blank node passed as blank(Term("predicate"), Term("object"))
|
|
314
314
|
else if (predicate.termType) children = [{
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
315
|
+
predicate: predicate,
|
|
316
|
+
object: object
|
|
317
|
+
}]; // Blank node passed as blank({ predicate: predicate, object: object })
|
|
318
|
+
else if (!('length' in predicate)) children = [predicate];
|
|
319
319
|
|
|
320
320
|
switch (length = children.length) {
|
|
321
321
|
// Generate an empty blank node
|
|
@@ -336,9 +336,9 @@ class N3Writer {
|
|
|
336
336
|
|
|
337
337
|
if (child.predicate.equals(predicate)) contents += `, ${this._encodeObject(child.object)}`; // Otherwise, write the predicate and the object
|
|
338
338
|
else {
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
339
|
+
contents += `${(i ? ';\n ' : '\n ') + this._encodePredicate(child.predicate)} ${this._encodeObject(child.object)}`;
|
|
340
|
+
predicate = child.predicate;
|
|
341
|
+
}
|
|
342
342
|
}
|
|
343
343
|
|
|
344
344
|
return new SerializedTerm(`${contents}\n]`);
|
|
@@ -398,9 +398,9 @@ function characterReplacer(character) {
|
|
|
398
398
|
result = '\\u0000'.substr(0, 6 - result.length) + result;
|
|
399
399
|
} // Replace a surrogate pair with its 8-bit unicode escape sequence
|
|
400
400
|
else {
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
401
|
+
result = ((character.charCodeAt(0) - 0xD800) * 0x400 + character.charCodeAt(1) + 0x2400).toString(16);
|
|
402
|
+
result = '\\U00000000'.substr(0, 10 - result.length) + result;
|
|
403
|
+
}
|
|
404
404
|
}
|
|
405
405
|
|
|
406
406
|
return result;
|
package/lib/index.js
CHANGED
|
@@ -3,94 +3,95 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
Object.defineProperty(exports, "
|
|
6
|
+
Object.defineProperty(exports, "BlankNode", {
|
|
7
7
|
enumerable: true,
|
|
8
8
|
get: function () {
|
|
9
|
-
return
|
|
9
|
+
return _N3DataFactory.BlankNode;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
-
Object.defineProperty(exports, "
|
|
12
|
+
Object.defineProperty(exports, "DataFactory", {
|
|
13
13
|
enumerable: true,
|
|
14
14
|
get: function () {
|
|
15
|
-
return
|
|
15
|
+
return _N3DataFactory.default;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
-
Object.defineProperty(exports, "
|
|
18
|
+
Object.defineProperty(exports, "DefaultGraph", {
|
|
19
19
|
enumerable: true,
|
|
20
20
|
get: function () {
|
|
21
|
-
return
|
|
21
|
+
return _N3DataFactory.DefaultGraph;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
|
-
Object.defineProperty(exports, "
|
|
24
|
+
Object.defineProperty(exports, "Lexer", {
|
|
25
25
|
enumerable: true,
|
|
26
26
|
get: function () {
|
|
27
|
-
return
|
|
27
|
+
return _N3Lexer.default;
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
|
-
Object.defineProperty(exports, "
|
|
30
|
+
Object.defineProperty(exports, "Literal", {
|
|
31
31
|
enumerable: true,
|
|
32
32
|
get: function () {
|
|
33
|
-
return
|
|
33
|
+
return _N3DataFactory.Literal;
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
|
-
Object.defineProperty(exports, "
|
|
36
|
+
Object.defineProperty(exports, "NamedNode", {
|
|
37
37
|
enumerable: true,
|
|
38
38
|
get: function () {
|
|
39
|
-
return
|
|
39
|
+
return _N3DataFactory.NamedNode;
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
|
-
Object.defineProperty(exports, "
|
|
42
|
+
Object.defineProperty(exports, "Parser", {
|
|
43
43
|
enumerable: true,
|
|
44
44
|
get: function () {
|
|
45
|
-
return
|
|
45
|
+
return _N3Parser.default;
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
|
-
Object.defineProperty(exports, "
|
|
48
|
+
Object.defineProperty(exports, "Quad", {
|
|
49
49
|
enumerable: true,
|
|
50
50
|
get: function () {
|
|
51
|
-
return _N3DataFactory.
|
|
51
|
+
return _N3DataFactory.Quad;
|
|
52
52
|
}
|
|
53
53
|
});
|
|
54
|
-
Object.defineProperty(exports, "
|
|
54
|
+
Object.defineProperty(exports, "Store", {
|
|
55
55
|
enumerable: true,
|
|
56
56
|
get: function () {
|
|
57
|
-
return
|
|
57
|
+
return _N3Store.default;
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
|
-
Object.defineProperty(exports, "
|
|
60
|
+
Object.defineProperty(exports, "StreamParser", {
|
|
61
61
|
enumerable: true,
|
|
62
62
|
get: function () {
|
|
63
|
-
return
|
|
63
|
+
return _N3StreamParser.default;
|
|
64
64
|
}
|
|
65
65
|
});
|
|
66
|
-
Object.defineProperty(exports, "
|
|
66
|
+
Object.defineProperty(exports, "StreamWriter", {
|
|
67
67
|
enumerable: true,
|
|
68
68
|
get: function () {
|
|
69
|
-
return
|
|
69
|
+
return _N3StreamWriter.default;
|
|
70
70
|
}
|
|
71
71
|
});
|
|
72
|
-
Object.defineProperty(exports, "
|
|
72
|
+
Object.defineProperty(exports, "Term", {
|
|
73
73
|
enumerable: true,
|
|
74
74
|
get: function () {
|
|
75
|
-
return _N3DataFactory.
|
|
75
|
+
return _N3DataFactory.Term;
|
|
76
76
|
}
|
|
77
77
|
});
|
|
78
|
-
Object.defineProperty(exports, "
|
|
78
|
+
Object.defineProperty(exports, "Triple", {
|
|
79
79
|
enumerable: true,
|
|
80
80
|
get: function () {
|
|
81
|
-
return _N3DataFactory.
|
|
81
|
+
return _N3DataFactory.Triple;
|
|
82
82
|
}
|
|
83
83
|
});
|
|
84
|
-
|
|
84
|
+
exports.Util = void 0;
|
|
85
|
+
Object.defineProperty(exports, "Variable", {
|
|
85
86
|
enumerable: true,
|
|
86
87
|
get: function () {
|
|
87
|
-
return _N3DataFactory.
|
|
88
|
+
return _N3DataFactory.Variable;
|
|
88
89
|
}
|
|
89
90
|
});
|
|
90
|
-
Object.defineProperty(exports, "
|
|
91
|
+
Object.defineProperty(exports, "Writer", {
|
|
91
92
|
enumerable: true,
|
|
92
93
|
get: function () {
|
|
93
|
-
return
|
|
94
|
+
return _N3Writer.default;
|
|
94
95
|
}
|
|
95
96
|
});
|
|
96
97
|
Object.defineProperty(exports, "termFromId", {
|
|
@@ -105,7 +106,6 @@ Object.defineProperty(exports, "termToId", {
|
|
|
105
106
|
return _N3DataFactory.termToId;
|
|
106
107
|
}
|
|
107
108
|
});
|
|
108
|
-
exports.Util = void 0;
|
|
109
109
|
|
|
110
110
|
var _N3Lexer = _interopRequireDefault(require("./N3Lexer"));
|
|
111
111
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "n3",
|
|
3
|
-
"version": "1.11.
|
|
3
|
+
"version": "1.11.2",
|
|
4
4
|
"description": "Lightning fast, asynchronous, streaming Turtle / N3 / RDF library.",
|
|
5
5
|
"author": "Ruben Verborgh <ruben.verborgh@gmail.com>",
|
|
6
6
|
"keywords": [
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
"readable-stream": "^3.6.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@babel/cli": "^7.
|
|
31
|
-
"@babel/core": "^7.
|
|
32
|
-
"@babel/preset-env": "^7.
|
|
33
|
-
"@babel/register": "^7.
|
|
30
|
+
"@babel/cli": "^7.16.0",
|
|
31
|
+
"@babel/core": "^7.16.0",
|
|
32
|
+
"@babel/preset-env": "^7.16.0",
|
|
33
|
+
"@babel/register": "^7.16.0",
|
|
34
34
|
"arrayify-stream": "^1.0.0",
|
|
35
35
|
"chai": "^4.0.2",
|
|
36
36
|
"chai-things": "^0.2.0",
|
package/src/N3Parser.js
CHANGED
|
@@ -272,6 +272,13 @@ export default class N3Parser {
|
|
|
272
272
|
// Additional semicolons can be safely ignored
|
|
273
273
|
return this._predicate !== null ? this._readPredicate :
|
|
274
274
|
this._error('Expected predicate but got ;', token);
|
|
275
|
+
case '[':
|
|
276
|
+
if (this._n3Mode) {
|
|
277
|
+
// Start a new quad with a new blank node as subject
|
|
278
|
+
this._saveContext('blank', this._graph, this._subject,
|
|
279
|
+
this._subject = this._blankNode(), null);
|
|
280
|
+
return this._readBlankNodeHead;
|
|
281
|
+
}
|
|
275
282
|
case 'blank':
|
|
276
283
|
if (!this._n3Mode)
|
|
277
284
|
return this._error('Disallowed blank node as predicate', token);
|
|
@@ -368,13 +375,16 @@ export default class N3Parser {
|
|
|
368
375
|
// Restore the parent context containing this blank node
|
|
369
376
|
const empty = this._predicate === null;
|
|
370
377
|
this._restoreContext();
|
|
378
|
+
// If the blank node was the object, restore previous context and read punctuation
|
|
379
|
+
if (this._object !== null)
|
|
380
|
+
return this._getContextEndReader();
|
|
381
|
+
// If the blank node was the predicate, continue reading the object
|
|
382
|
+
else if (this._predicate !== null)
|
|
383
|
+
return this._readObject;
|
|
371
384
|
// If the blank node was the subject, continue reading the predicate
|
|
372
|
-
|
|
385
|
+
else
|
|
373
386
|
// If the blank node was empty, it could be a named graph label
|
|
374
387
|
return empty ? this._readPredicateOrNamedGraph : this._readPredicateAfterBlank;
|
|
375
|
-
// If the blank node was the object, restore previous context and read punctuation
|
|
376
|
-
else
|
|
377
|
-
return this._getContextEndReader();
|
|
378
388
|
}
|
|
379
389
|
|
|
380
390
|
// ### `_readPredicateAfterBlank` reads a predicate after an anonymous blank node
|