n3 1.23.0 → 1.23.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/N3Parser.js CHANGED
@@ -165,22 +165,22 @@ class N3Parser {
165
165
  case 'typeIRI':
166
166
  const iri = this._resolveIRI(token.value);
167
167
  if (iri === null) return this._error('Invalid IRI', token);
168
- value = this._namedNode(iri);
168
+ value = this._factory.namedNode(iri);
169
169
  break;
170
170
  // Read a prefixed name
171
171
  case 'type':
172
172
  case 'prefixed':
173
173
  const prefix = this._prefixes[token.prefix];
174
174
  if (prefix === undefined) return this._error(`Undefined prefix "${token.prefix}:"`, token);
175
- value = this._namedNode(prefix + token.value);
175
+ value = this._factory.namedNode(prefix + token.value);
176
176
  break;
177
177
  // Read a blank node
178
178
  case 'blank':
179
- value = this._blankNode(this._prefixes[token.prefix] + token.value);
179
+ value = this._factory.blankNode(this._prefixes[token.prefix] + token.value);
180
180
  break;
181
181
  // Read a variable
182
182
  case 'var':
183
- value = this._variable(token.value.substr(1));
183
+ value = this._factory.variable(token.value.substr(1));
184
184
  break;
185
185
  // Everything else is not an entity
186
186
  default:
@@ -197,7 +197,7 @@ class N3Parser {
197
197
  switch (token.type) {
198
198
  case '[':
199
199
  // Start a new quad with a new blank node as subject
200
- this._saveContext('blank', this._graph, this._subject = this._blankNode(), null, null);
200
+ this._saveContext('blank', this._graph, this._subject = this._factory.blankNode(), null, null);
201
201
  return this._readBlankNodeHead;
202
202
  case '(':
203
203
  // Start a new list
@@ -207,7 +207,7 @@ class N3Parser {
207
207
  case '{':
208
208
  // Start a new formula
209
209
  if (!this._n3Mode) return this._error('Unexpected graph', token);
210
- this._saveContext('formula', this._graph, this._graph = this._blankNode(), null, null);
210
+ this._saveContext('formula', this._graph, this._graph = this._factory.blankNode(), null, null);
211
211
  return this._readSubject;
212
212
  case '}':
213
213
  // No subject; the graph in which we are reading is closed instead
@@ -216,20 +216,20 @@ class N3Parser {
216
216
  if (!this._n3Mode) return this._error('Unexpected "@forSome"', token);
217
217
  this._subject = null;
218
218
  this._predicate = this.N3_FORSOME;
219
- this._quantifier = this._blankNode;
219
+ this._quantifier = 'blankNode';
220
220
  return this._readQuantifierList;
221
221
  case '@forAll':
222
222
  if (!this._n3Mode) return this._error('Unexpected "@forAll"', token);
223
223
  this._subject = null;
224
224
  this._predicate = this.N3_FORALL;
225
- this._quantifier = this._variable;
225
+ this._quantifier = 'variable';
226
226
  return this._readQuantifierList;
227
227
  case 'literal':
228
228
  if (!this._n3Mode) return this._error('Unexpected literal', token);
229
229
  if (token.prefix.length === 0) {
230
230
  this._literalValue = token.value;
231
231
  return this._completeSubjectLiteral;
232
- } else this._subject = this._literal(token.value, this._namedNode(token.prefix));
232
+ } else this._subject = this._factory.literal(token.value, this._factory.namedNode(token.prefix));
233
233
  break;
234
234
  case '<<':
235
235
  if (!this._supportsRDFStar) return this._error('Unexpected RDF-star syntax', token);
@@ -270,7 +270,7 @@ class N3Parser {
270
270
  case '[':
271
271
  if (this._n3Mode) {
272
272
  // Start a new quad with a new blank node as subject
273
- this._saveContext('blank', this._graph, this._subject, this._subject = this._blankNode(), null);
273
+ this._saveContext('blank', this._graph, this._subject, this._subject = this._factory.blankNode(), null);
274
274
  return this._readBlankNodeHead;
275
275
  }
276
276
  case 'blank':
@@ -292,11 +292,11 @@ class N3Parser {
292
292
  return this._readDataTypeOrLang;
293
293
  }
294
294
  // Pre-datatyped string literal (prefix stores the datatype)
295
- else this._object = this._literal(token.value, this._namedNode(token.prefix));
295
+ else this._object = this._factory.literal(token.value, this._factory.namedNode(token.prefix));
296
296
  break;
297
297
  case '[':
298
298
  // Start a new quad with a new blank node as subject
299
- this._saveContext('blank', this._graph, this._subject, this._predicate, this._subject = this._blankNode());
299
+ this._saveContext('blank', this._graph, this._subject, this._predicate, this._subject = this._factory.blankNode());
300
300
  return this._readBlankNodeHead;
301
301
  case '(':
302
302
  // Start a new list
@@ -306,7 +306,7 @@ class N3Parser {
306
306
  case '{':
307
307
  // Start a new formula
308
308
  if (!this._n3Mode) return this._error('Unexpected graph', token);
309
- this._saveContext('formula', this._graph, this._subject, this._predicate, this._graph = this._blankNode());
309
+ this._saveContext('formula', this._graph, this._subject, this._predicate, this._graph = this._factory.blankNode());
310
310
  return this._readSubject;
311
311
  case '<<':
312
312
  if (!this._supportsRDFStar) return this._error('Unexpected RDF-star syntax', token);
@@ -395,12 +395,12 @@ class N3Parser {
395
395
  switch (token.type) {
396
396
  case '[':
397
397
  // Stack the current list quad and start a new quad with a blank node as subject
398
- this._saveContext('blank', this._graph, list = this._blankNode(), this.RDF_FIRST, this._subject = item = this._blankNode());
398
+ this._saveContext('blank', this._graph, list = this._factory.blankNode(), this.RDF_FIRST, this._subject = item = this._factory.blankNode());
399
399
  next = this._readBlankNodeHead;
400
400
  break;
401
401
  case '(':
402
402
  // Stack the current list quad and start a new list
403
- this._saveContext('list', this._graph, list = this._blankNode(), this.RDF_FIRST, this.RDF_NIL);
403
+ this._saveContext('list', this._graph, list = this._factory.blankNode(), this.RDF_FIRST, this.RDF_NIL);
404
404
  this._subject = null;
405
405
  break;
406
406
  case ')':
@@ -433,21 +433,21 @@ class N3Parser {
433
433
  }
434
434
  // Pre-datatyped string literal (prefix stores the datatype)
435
435
  else {
436
- item = this._literal(token.value, this._namedNode(token.prefix));
436
+ item = this._factory.literal(token.value, this._factory.namedNode(token.prefix));
437
437
  next = this._getContextEndReader();
438
438
  }
439
439
  break;
440
440
  case '{':
441
441
  // Start a new formula
442
442
  if (!this._n3Mode) return this._error('Unexpected graph', token);
443
- this._saveContext('formula', this._graph, this._subject, this._predicate, this._graph = this._blankNode());
443
+ this._saveContext('formula', this._graph, this._subject, this._predicate, this._graph = this._factory.blankNode());
444
444
  return this._readSubject;
445
445
  default:
446
446
  if ((item = this._readEntity(token)) === undefined) return;
447
447
  }
448
448
 
449
449
  // Create a new blank node if no item head was assigned yet
450
- if (list === null) this._subject = list = this._blankNode();
450
+ if (list === null) this._subject = list = this._factory.blankNode();
451
451
 
452
452
  // Is this the first element of the list?
453
453
  if (previousList === null) {
@@ -486,19 +486,19 @@ class N3Parser {
486
486
  // ### `_completeLiteral` completes a literal with an optional datatype or language
487
487
  _completeLiteral(token) {
488
488
  // Create a simple string literal by default
489
- let literal = this._literal(this._literalValue);
489
+ let literal = this._factory.literal(this._literalValue);
490
490
  switch (token.type) {
491
491
  // Create a datatyped literal
492
492
  case 'type':
493
493
  case 'typeIRI':
494
494
  const datatype = this._readEntity(token);
495
495
  if (datatype === undefined) return; // No datatype means an error occurred
496
- literal = this._literal(this._literalValue, datatype);
496
+ literal = this._factory.literal(this._literalValue, datatype);
497
497
  token = null;
498
498
  break;
499
499
  // Create a language-tagged string
500
500
  case 'langcode':
501
- literal = this._literal(this._literalValue, token.value);
501
+ literal = this._factory.literal(this._literalValue, token.value);
502
502
  token = null;
503
503
  break;
504
504
  }
@@ -578,7 +578,7 @@ class N3Parser {
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;
581
- this._subject = this._quad(subject, predicate, object, this.DEFAULTGRAPH);
581
+ this._subject = this._factory.quad(subject, predicate, object, this.DEFAULTGRAPH);
582
582
  next = this._readPredicate;
583
583
  break;
584
584
  // |} means that the current quoted triple in annotation syntax is finalized.
@@ -671,7 +671,7 @@ class N3Parser {
671
671
  // ### `_readNamedGraphLabel` reads a blank node label of a named graph
672
672
  _readNamedGraphBlankLabel(token) {
673
673
  if (token.type !== ']') return this._error('Invalid graph label', token);
674
- this._subject = this._blankNode();
674
+ this._subject = this._factory.blankNode();
675
675
  return this._readGraph;
676
676
  }
677
677
 
@@ -697,13 +697,13 @@ class N3Parser {
697
697
  return this._error(`Unexpected ${token.type}`, token);
698
698
  }
699
699
  // Without explicit quantifiers, map entities to a quantified entity
700
- if (!this._explicitQuantifiers) this._quantified[entity.id] = this._quantifier(this._blankNode().value);
700
+ if (!this._explicitQuantifiers) this._quantified[entity.id] = this._factory[this._quantifier](this._factory.blankNode().value);
701
701
  // With explicit quantifiers, output the reified quantifier
702
702
  else {
703
703
  // If this is the first item, start a new quantifier list
704
- if (this._subject === null) this._emit(this._graph || this.DEFAULTGRAPH, this._predicate, this._subject = this._blankNode(), this.QUANTIFIERS_GRAPH);
704
+ if (this._subject === null) this._emit(this._graph || this.DEFAULTGRAPH, this._predicate, this._subject = this._factory.blankNode(), this.QUANTIFIERS_GRAPH);
705
705
  // Otherwise, continue the previous list
706
- else this._emit(this._subject, this.RDF_REST, this._subject = this._blankNode(), this.QUANTIFIERS_GRAPH);
706
+ else this._emit(this._subject, this.RDF_REST, this._subject = this._factory.blankNode(), this.QUANTIFIERS_GRAPH);
707
707
  // Output the list item
708
708
  this._emit(this._subject, this.RDF_FIRST, entity, this.QUANTIFIERS_GRAPH);
709
709
  }
@@ -762,7 +762,7 @@ class N3Parser {
762
762
  // ### `_readForwardPath` reads a '!' path
763
763
  _readForwardPath(token) {
764
764
  let subject, predicate;
765
- const object = this._blankNode();
765
+ const object = this._factory.blankNode();
766
766
  // The next token is the predicate
767
767
  if ((predicate = this._readEntity(token)) === undefined) return;
768
768
  // If we were reading a subject, replace the subject by the path's object
@@ -776,7 +776,7 @@ class N3Parser {
776
776
 
777
777
  // ### `_readBackwardPath` reads a '^' path
778
778
  _readBackwardPath(token) {
779
- const subject = this._blankNode();
779
+ const subject = this._factory.blankNode();
780
780
  let predicate, object;
781
781
  // The next token is the predicate
782
782
  if ((predicate = this._readEntity(token)) === undefined) return;
@@ -803,7 +803,7 @@ class N3Parser {
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
806
- const quad = this._quad(this._subject, this._predicate, this._object, this._graph || this.DEFAULTGRAPH);
806
+ const quad = this._factory.quad(this._subject, this._predicate, this._object, this._graph || this.DEFAULTGRAPH);
807
807
  this._restoreContext('<<', token);
808
808
  // If the triple was the subject, continue by reading the predicate.
809
809
  if (this._subject === null) {
@@ -835,7 +835,7 @@ class N3Parser {
835
835
 
836
836
  // ### `_emit` sends a quad through the callback
837
837
  _emit(subject, predicate, object, graph) {
838
- this._callback(null, this._quad(subject, predicate, object, graph || this.DEFAULTGRAPH));
838
+ this._callback(null, this._factory.quad(subject, predicate, object, graph || this.DEFAULTGRAPH));
839
839
  }
840
840
 
841
841
  // ### `_error` emits an error message through the callback
@@ -1007,26 +1007,20 @@ function noop() {}
1007
1007
 
1008
1008
  // Initializes the parser with the given data factory
1009
1009
  function initDataFactory(parser, factory) {
1010
- // Set factory methods
1011
- const namedNode = factory.namedNode;
1012
- parser._namedNode = namedNode;
1013
- parser._blankNode = factory.blankNode;
1014
- parser._literal = factory.literal;
1015
- parser._variable = factory.variable;
1016
- parser._quad = factory.quad;
1010
+ parser._factory = factory;
1017
1011
  parser.DEFAULTGRAPH = factory.defaultGraph();
1018
1012
 
1019
1013
  // Set common named nodes
1020
- parser.RDF_FIRST = namedNode(_IRIs.default.rdf.first);
1021
- parser.RDF_REST = namedNode(_IRIs.default.rdf.rest);
1022
- parser.RDF_NIL = namedNode(_IRIs.default.rdf.nil);
1023
- parser.N3_FORALL = namedNode(_IRIs.default.r.forAll);
1024
- parser.N3_FORSOME = namedNode(_IRIs.default.r.forSome);
1014
+ parser.RDF_FIRST = factory.namedNode(_IRIs.default.rdf.first);
1015
+ parser.RDF_REST = factory.namedNode(_IRIs.default.rdf.rest);
1016
+ parser.RDF_NIL = factory.namedNode(_IRIs.default.rdf.nil);
1017
+ parser.N3_FORALL = factory.namedNode(_IRIs.default.r.forAll);
1018
+ parser.N3_FORSOME = factory.namedNode(_IRIs.default.r.forSome);
1025
1019
  parser.ABBREVIATIONS = {
1026
- 'a': namedNode(_IRIs.default.rdf.type),
1027
- '=': namedNode(_IRIs.default.owl.sameAs),
1028
- '>': namedNode(_IRIs.default.log.implies)
1020
+ 'a': factory.namedNode(_IRIs.default.rdf.type),
1021
+ '=': factory.namedNode(_IRIs.default.owl.sameAs),
1022
+ '>': factory.namedNode(_IRIs.default.log.implies)
1029
1023
  };
1030
- parser.QUANTIFIERS_GRAPH = namedNode('urn:n3:quantifiers');
1024
+ parser.QUANTIFIERS_GRAPH = factory.namedNode('urn:n3:quantifiers');
1031
1025
  }
1032
1026
  initDataFactory(N3Parser.prototype, _N3DataFactory.default);
package/lib/N3Store.js CHANGED
@@ -1083,26 +1083,28 @@ class DatasetCoreAndReadableStream extends _readableStream.Readable {
1083
1083
  if (subject && !(subjectId = newStore._termToNumericId(subject)) || predicate && !(predicateId = newStore._termToNumericId(predicate)) || object && !(objectId = newStore._termToNumericId(object))) return newStore;
1084
1084
  const graphs = n3Store._getGraphs(graph);
1085
1085
  for (const graphKey in graphs) {
1086
- let subjects, predicates, objects;
1087
- if (!subjectId && predicateId) {
1088
- if (predicates = indexMatch(graphs[graphKey].predicates, [predicateId, objectId, subjectId])) {
1089
- subjects = indexMatch(graphs[graphKey].subjects, [subjectId, predicateId, objectId]);
1090
- objects = indexMatch(graphs[graphKey].objects, [objectId, subjectId, predicateId]);
1091
- }
1092
- } else if (objectId) {
1093
- if (objects = indexMatch(graphs[graphKey].objects, [objectId, subjectId, predicateId])) {
1094
- subjects = indexMatch(graphs[graphKey].subjects, [subjectId, predicateId, objectId]);
1095
- predicates = indexMatch(graphs[graphKey].predicates, [predicateId, objectId, subjectId]);
1086
+ let subjects, predicates, objects, content;
1087
+ if (content = graphs[graphKey]) {
1088
+ if (!subjectId && predicateId) {
1089
+ if (predicates = indexMatch(content.predicates, [predicateId, objectId, subjectId])) {
1090
+ subjects = indexMatch(content.subjects, [subjectId, predicateId, objectId]);
1091
+ objects = indexMatch(content.objects, [objectId, subjectId, predicateId]);
1092
+ }
1093
+ } else if (objectId) {
1094
+ if (objects = indexMatch(content.objects, [objectId, subjectId, predicateId])) {
1095
+ subjects = indexMatch(content.subjects, [subjectId, predicateId, objectId]);
1096
+ predicates = indexMatch(content.predicates, [predicateId, objectId, subjectId]);
1097
+ }
1098
+ } else if (subjects = indexMatch(content.subjects, [subjectId, predicateId, objectId])) {
1099
+ predicates = indexMatch(content.predicates, [predicateId, objectId, subjectId]);
1100
+ objects = indexMatch(content.objects, [objectId, subjectId, predicateId]);
1096
1101
  }
1097
- } else if (subjects = indexMatch(graphs[graphKey].subjects, [subjectId, predicateId, objectId])) {
1098
- predicates = indexMatch(graphs[graphKey].predicates, [predicateId, objectId, subjectId]);
1099
- objects = indexMatch(graphs[graphKey].objects, [objectId, subjectId, predicateId]);
1102
+ if (subjects) newStore._graphs[graphKey] = {
1103
+ subjects,
1104
+ predicates,
1105
+ objects
1106
+ };
1100
1107
  }
1101
- if (subjects) newStore._graphs[graphKey] = {
1102
- subjects,
1103
- predicates,
1104
- objects
1105
- };
1106
1108
  }
1107
1109
  newStore._size = null;
1108
1110
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n3",
3
- "version": "1.23.0",
3
+ "version": "1.23.2",
4
4
  "description": "Lightning fast, asynchronous, streaming Turtle / N3 / RDF library.",
5
5
  "author": "Ruben Verborgh <ruben.verborgh@gmail.com>",
6
6
  "keywords": [
@@ -38,12 +38,12 @@
38
38
  "browserify": "^17.0.0",
39
39
  "deep-taxonomy-benchmark": "^2.0.0",
40
40
  "docco": "^0.9.1",
41
- "eslint": "^9.12.0",
41
+ "eslint": "^8.57.1",
42
42
  "eslint-plugin-import": "^2.29.1",
43
43
  "eslint-plugin-jest": "^28.8.3",
44
44
  "jest": "^29.7.0",
45
45
  "pre-commit": "^1.2.2",
46
- "rdf-isomorphic": "^1.3.1",
46
+ "rdf-isomorphic": "^2.0.0",
47
47
  "rdf-test-suite": "^1.25.0",
48
48
  "streamify-string": "^1.0.1",
49
49
  "uglify-js": "^3.14.3"
package/src/N3Parser.js CHANGED
@@ -159,7 +159,7 @@ export default class N3Parser {
159
159
  const iri = this._resolveIRI(token.value);
160
160
  if (iri === null)
161
161
  return this._error('Invalid IRI', token);
162
- value = this._namedNode(iri);
162
+ value = this._factory.namedNode(iri);
163
163
  break;
164
164
  // Read a prefixed name
165
165
  case 'type':
@@ -167,15 +167,15 @@ export default class N3Parser {
167
167
  const prefix = this._prefixes[token.prefix];
168
168
  if (prefix === undefined)
169
169
  return this._error(`Undefined prefix "${token.prefix}:"`, token);
170
- value = this._namedNode(prefix + token.value);
170
+ value = this._factory.namedNode(prefix + token.value);
171
171
  break;
172
172
  // Read a blank node
173
173
  case 'blank':
174
- value = this._blankNode(this._prefixes[token.prefix] + token.value);
174
+ value = this._factory.blankNode(this._prefixes[token.prefix] + token.value);
175
175
  break;
176
176
  // Read a variable
177
177
  case 'var':
178
- value = this._variable(token.value.substr(1));
178
+ value = this._factory.variable(token.value.substr(1));
179
179
  break;
180
180
  // Everything else is not an entity
181
181
  default:
@@ -194,7 +194,7 @@ export default class N3Parser {
194
194
  case '[':
195
195
  // Start a new quad with a new blank node as subject
196
196
  this._saveContext('blank', this._graph,
197
- this._subject = this._blankNode(), null, null);
197
+ this._subject = this._factory.blankNode(), null, null);
198
198
  return this._readBlankNodeHead;
199
199
  case '(':
200
200
  // Start a new list
@@ -206,7 +206,7 @@ export default class N3Parser {
206
206
  if (!this._n3Mode)
207
207
  return this._error('Unexpected graph', token);
208
208
  this._saveContext('formula', this._graph,
209
- this._graph = this._blankNode(), null, null);
209
+ this._graph = this._factory.blankNode(), null, null);
210
210
  return this._readSubject;
211
211
  case '}':
212
212
  // No subject; the graph in which we are reading is closed instead
@@ -216,14 +216,14 @@ export default class N3Parser {
216
216
  return this._error('Unexpected "@forSome"', token);
217
217
  this._subject = null;
218
218
  this._predicate = this.N3_FORSOME;
219
- this._quantifier = this._blankNode;
219
+ this._quantifier = 'blankNode';
220
220
  return this._readQuantifierList;
221
221
  case '@forAll':
222
222
  if (!this._n3Mode)
223
223
  return this._error('Unexpected "@forAll"', token);
224
224
  this._subject = null;
225
225
  this._predicate = this.N3_FORALL;
226
- this._quantifier = this._variable;
226
+ this._quantifier = 'variable';
227
227
  return this._readQuantifierList;
228
228
  case 'literal':
229
229
  if (!this._n3Mode)
@@ -234,7 +234,7 @@ export default class N3Parser {
234
234
  return this._completeSubjectLiteral;
235
235
  }
236
236
  else
237
- this._subject = this._literal(token.value, this._namedNode(token.prefix));
237
+ this._subject = this._factory.literal(token.value, this._factory.namedNode(token.prefix));
238
238
 
239
239
  break;
240
240
  case '<<':
@@ -282,7 +282,7 @@ export default class N3Parser {
282
282
  if (this._n3Mode) {
283
283
  // Start a new quad with a new blank node as subject
284
284
  this._saveContext('blank', this._graph, this._subject,
285
- this._subject = this._blankNode(), null);
285
+ this._subject = this._factory.blankNode(), null);
286
286
  return this._readBlankNodeHead;
287
287
  }
288
288
  case 'blank':
@@ -307,12 +307,12 @@ export default class N3Parser {
307
307
  }
308
308
  // Pre-datatyped string literal (prefix stores the datatype)
309
309
  else
310
- this._object = this._literal(token.value, this._namedNode(token.prefix));
310
+ this._object = this._factory.literal(token.value, this._factory.namedNode(token.prefix));
311
311
  break;
312
312
  case '[':
313
313
  // Start a new quad with a new blank node as subject
314
314
  this._saveContext('blank', this._graph, this._subject, this._predicate,
315
- this._subject = this._blankNode());
315
+ this._subject = this._factory.blankNode());
316
316
  return this._readBlankNodeHead;
317
317
  case '(':
318
318
  // Start a new list
@@ -324,7 +324,7 @@ export default class N3Parser {
324
324
  if (!this._n3Mode)
325
325
  return this._error('Unexpected graph', token);
326
326
  this._saveContext('formula', this._graph, this._subject, this._predicate,
327
- this._graph = this._blankNode());
327
+ this._graph = this._factory.blankNode());
328
328
  return this._readSubject;
329
329
  case '<<':
330
330
  if (!this._supportsRDFStar)
@@ -419,14 +419,14 @@ export default class N3Parser {
419
419
  case '[':
420
420
  // Stack the current list quad and start a new quad with a blank node as subject
421
421
  this._saveContext('blank', this._graph,
422
- list = this._blankNode(), this.RDF_FIRST,
423
- this._subject = item = this._blankNode());
422
+ list = this._factory.blankNode(), this.RDF_FIRST,
423
+ this._subject = item = this._factory.blankNode());
424
424
  next = this._readBlankNodeHead;
425
425
  break;
426
426
  case '(':
427
427
  // Stack the current list quad and start a new list
428
428
  this._saveContext('list', this._graph,
429
- list = this._blankNode(), this.RDF_FIRST, this.RDF_NIL);
429
+ list = this._factory.blankNode(), this.RDF_FIRST, this.RDF_NIL);
430
430
  this._subject = null;
431
431
  break;
432
432
  case ')':
@@ -462,7 +462,7 @@ export default class N3Parser {
462
462
  }
463
463
  // Pre-datatyped string literal (prefix stores the datatype)
464
464
  else {
465
- item = this._literal(token.value, this._namedNode(token.prefix));
465
+ item = this._factory.literal(token.value, this._factory.namedNode(token.prefix));
466
466
  next = this._getContextEndReader();
467
467
  }
468
468
  break;
@@ -471,7 +471,7 @@ export default class N3Parser {
471
471
  if (!this._n3Mode)
472
472
  return this._error('Unexpected graph', token);
473
473
  this._saveContext('formula', this._graph, this._subject, this._predicate,
474
- this._graph = this._blankNode());
474
+ this._graph = this._factory.blankNode());
475
475
  return this._readSubject;
476
476
  default:
477
477
  if ((item = this._readEntity(token)) === undefined)
@@ -480,7 +480,7 @@ export default class N3Parser {
480
480
 
481
481
  // Create a new blank node if no item head was assigned yet
482
482
  if (list === null)
483
- this._subject = list = this._blankNode();
483
+ this._subject = list = this._factory.blankNode();
484
484
 
485
485
  // Is this the first element of the list?
486
486
  if (previousList === null) {
@@ -524,7 +524,7 @@ export default class N3Parser {
524
524
  // ### `_completeLiteral` completes a literal with an optional datatype or language
525
525
  _completeLiteral(token) {
526
526
  // Create a simple string literal by default
527
- let literal = this._literal(this._literalValue);
527
+ let literal = this._factory.literal(this._literalValue);
528
528
 
529
529
  switch (token.type) {
530
530
  // Create a datatyped literal
@@ -532,12 +532,12 @@ export default class N3Parser {
532
532
  case 'typeIRI':
533
533
  const datatype = this._readEntity(token);
534
534
  if (datatype === undefined) return; // No datatype means an error occurred
535
- literal = this._literal(this._literalValue, datatype);
535
+ literal = this._factory.literal(this._literalValue, datatype);
536
536
  token = null;
537
537
  break;
538
538
  // Create a language-tagged string
539
539
  case 'langcode':
540
- literal = this._literal(this._literalValue, token.value);
540
+ literal = this._factory.literal(this._literalValue, token.value);
541
541
  token = null;
542
542
  break;
543
543
  }
@@ -620,7 +620,7 @@ export default class N3Parser {
620
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
- this._subject = this._quad(subject, predicate, object, this.DEFAULTGRAPH);
623
+ this._subject = this._factory.quad(subject, predicate, object, this.DEFAULTGRAPH);
624
624
  next = this._readPredicate;
625
625
  break;
626
626
  // |} means that the current quoted triple in annotation syntax is finalized.
@@ -721,7 +721,7 @@ export default class N3Parser {
721
721
  _readNamedGraphBlankLabel(token) {
722
722
  if (token.type !== ']')
723
723
  return this._error('Invalid graph label', token);
724
- this._subject = this._blankNode();
724
+ this._subject = this._factory.blankNode();
725
725
  return this._readGraph;
726
726
  }
727
727
 
@@ -751,17 +751,17 @@ export default class N3Parser {
751
751
  }
752
752
  // Without explicit quantifiers, map entities to a quantified entity
753
753
  if (!this._explicitQuantifiers)
754
- this._quantified[entity.id] = this._quantifier(this._blankNode().value);
754
+ this._quantified[entity.id] = this._factory[this._quantifier](this._factory.blankNode().value);
755
755
  // With explicit quantifiers, output the reified quantifier
756
756
  else {
757
757
  // If this is the first item, start a new quantifier list
758
758
  if (this._subject === null)
759
759
  this._emit(this._graph || this.DEFAULTGRAPH, this._predicate,
760
- this._subject = this._blankNode(), this.QUANTIFIERS_GRAPH);
760
+ this._subject = this._factory.blankNode(), this.QUANTIFIERS_GRAPH);
761
761
  // Otherwise, continue the previous list
762
762
  else
763
763
  this._emit(this._subject, this.RDF_REST,
764
- this._subject = this._blankNode(), this.QUANTIFIERS_GRAPH);
764
+ this._subject = this._factory.blankNode(), this.QUANTIFIERS_GRAPH);
765
765
  // Output the list item
766
766
  this._emit(this._subject, this.RDF_FIRST, entity, this.QUANTIFIERS_GRAPH);
767
767
  }
@@ -818,7 +818,7 @@ export default class N3Parser {
818
818
  // ### `_readForwardPath` reads a '!' path
819
819
  _readForwardPath(token) {
820
820
  let subject, predicate;
821
- const object = this._blankNode();
821
+ const object = this._factory.blankNode();
822
822
  // The next token is the predicate
823
823
  if ((predicate = this._readEntity(token)) === undefined)
824
824
  return;
@@ -835,7 +835,7 @@ export default class N3Parser {
835
835
 
836
836
  // ### `_readBackwardPath` reads a '^' path
837
837
  _readBackwardPath(token) {
838
- const subject = this._blankNode();
838
+ const subject = this._factory.blankNode();
839
839
  let predicate, object;
840
840
  // The next token is the predicate
841
841
  if ((predicate = this._readEntity(token)) === undefined)
@@ -867,7 +867,7 @@ export default class N3Parser {
867
867
  if (token.type !== '>>')
868
868
  return this._error(`Expected >> but got ${token.type}`, token);
869
869
  // Read the quad and restore the previous context
870
- const quad = this._quad(this._subject, this._predicate, this._object,
870
+ const quad = this._factory.quad(this._subject, this._predicate, this._object,
871
871
  this._graph || this.DEFAULTGRAPH);
872
872
  this._restoreContext('<<', token);
873
873
  // If the triple was the subject, continue by reading the predicate.
@@ -902,7 +902,7 @@ export default class N3Parser {
902
902
 
903
903
  // ### `_emit` sends a quad through the callback
904
904
  _emit(subject, predicate, object, graph) {
905
- this._callback(null, this._quad(subject, predicate, object, graph || this.DEFAULTGRAPH));
905
+ this._callback(null, this._factory.quad(subject, predicate, object, graph || this.DEFAULTGRAPH));
906
906
  }
907
907
 
908
908
  // ### `_error` emits an error message through the callback
@@ -1082,26 +1082,21 @@ function noop() {}
1082
1082
 
1083
1083
  // Initializes the parser with the given data factory
1084
1084
  function initDataFactory(parser, factory) {
1085
- // Set factory methods
1086
- const namedNode = factory.namedNode;
1087
- parser._namedNode = namedNode;
1088
- parser._blankNode = factory.blankNode;
1089
- parser._literal = factory.literal;
1090
- parser._variable = factory.variable;
1091
- parser._quad = factory.quad;
1085
+ parser._factory = factory;
1086
+
1092
1087
  parser.DEFAULTGRAPH = factory.defaultGraph();
1093
1088
 
1094
1089
  // Set common named nodes
1095
- parser.RDF_FIRST = namedNode(namespaces.rdf.first);
1096
- parser.RDF_REST = namedNode(namespaces.rdf.rest);
1097
- parser.RDF_NIL = namedNode(namespaces.rdf.nil);
1098
- parser.N3_FORALL = namedNode(namespaces.r.forAll);
1099
- parser.N3_FORSOME = namedNode(namespaces.r.forSome);
1090
+ parser.RDF_FIRST = factory.namedNode(namespaces.rdf.first);
1091
+ parser.RDF_REST = factory.namedNode(namespaces.rdf.rest);
1092
+ parser.RDF_NIL = factory.namedNode(namespaces.rdf.nil);
1093
+ parser.N3_FORALL = factory.namedNode(namespaces.r.forAll);
1094
+ parser.N3_FORSOME = factory.namedNode(namespaces.r.forSome);
1100
1095
  parser.ABBREVIATIONS = {
1101
- 'a': namedNode(namespaces.rdf.type),
1102
- '=': namedNode(namespaces.owl.sameAs),
1103
- '>': namedNode(namespaces.log.implies),
1096
+ 'a': factory.namedNode(namespaces.rdf.type),
1097
+ '=': factory.namedNode(namespaces.owl.sameAs),
1098
+ '>': factory.namedNode(namespaces.log.implies),
1104
1099
  };
1105
- parser.QUANTIFIERS_GRAPH = namedNode('urn:n3:quantifiers');
1100
+ parser.QUANTIFIERS_GRAPH = factory.namedNode('urn:n3:quantifiers');
1106
1101
  }
1107
1102
  initDataFactory(N3Parser.prototype, N3DataFactory);