n3 2.10.0 → 2.10.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.
@@ -23,6 +23,8 @@ const {
23
23
  // eslint-disable-next-line prefer-const
24
24
  let DEFAULTGRAPH;
25
25
  let _blankNodeCounter = 0;
26
+ // The ID of the empty IRI, which cannot be '' as that is the ID of the default graph
27
+ const EMPTY_IRI_ID = '<>';
26
28
  const escapedLiteral = /^"(.*".*)(?="[^"]*$)/;
27
29
 
28
30
  // ## DataFactory singleton
@@ -82,7 +84,10 @@ class NamedNode extends Term {
82
84
  * the constructor assumes an already-validated IRI.
83
85
  */
84
86
  constructor(iri) {
85
- super(iri);
87
+ super(iri === '' ? EMPTY_IRI_ID : iri);
88
+ if (iri === '') Object.defineProperty(this, 'value', {
89
+ value: ''
90
+ });
86
91
  }
87
92
 
88
93
  // ### The term type of this term
@@ -291,6 +296,9 @@ function termFromId(id, factory, nested) {
291
296
  case '[':
292
297
  id = JSON.parse(id);
293
298
  break;
299
+ case '<':
300
+ if (id === EMPTY_IRI_ID) return factory.namedNode('');
301
+ // falls through
294
302
  default:
295
303
  if (!nested || !Array.isArray(id)) {
296
304
  return factory.namedNode(id);
@@ -312,7 +320,7 @@ function termToId(term, nested) {
312
320
  // Term instantiated with another library
313
321
  switch (term.termType) {
314
322
  case 'NamedNode':
315
- return term.value;
323
+ return term.value || EMPTY_IRI_ID;
316
324
  case 'BlankNode':
317
325
  return `_:${term.value}`;
318
326
  case 'Variable':
package/lib/N3Parser.js CHANGED
@@ -60,6 +60,8 @@ class N3Parser {
60
60
  });
61
61
  // Disable explicit quantifiers by default
62
62
  this._explicitQuantifiers = !!options.explicitQuantifiers;
63
+ // Disable formula-only blank node scoping by default
64
+ this._formulaScopedBlankNodes = !!options.formulaScopedBlankNodes;
63
65
  // Disable parsing of unsupported versions by default
64
66
  this._parseUnsupportedVersions = !!options.parseUnsupportedVersions;
65
67
  this._version = options.version;
@@ -128,11 +130,15 @@ class N3Parser {
128
130
  // Every new scope resets the predicate direction
129
131
  this._inversePredicate = false;
130
132
  this._expectOf = false;
131
- // In N3, blank nodes are scoped to a formula
132
- // (using a dot as separator, as a blank node label cannot start with it)
133
- this._prefixes._ = this._graph ? `${this._graph.value}.` : '.';
134
- // Quantifiers are scoped to a formula
135
- this._quantified = Object.create(this._quantified);
133
+ // In N3, blank nodes and quantifiers are scoped to a formula;
134
+ // with `formulaScopedBlankNodes`, lists and blank node property lists
135
+ // share the enclosing scope instead of rescoping
136
+ if (!this._formulaScopedBlankNodes || type === 'formula') {
137
+ // Label the scope with the enclosing formula's blank node
138
+ // (using a dot as separator, as a blank node label cannot start with it)
139
+ this._prefixes._ = this._graph ? `${this._graph.value}.` : '.';
140
+ this._quantified = Object.create(this._quantified);
141
+ }
136
142
  // A formula starts empty and must not inherit its parent's subject
137
143
  if (type === 'formula') {
138
144
  this._subject = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n3",
3
- "version": "2.10.0",
3
+ "version": "2.10.2",
4
4
  "description": "Lightning fast, asynchronous, streaming Turtle / N3 / RDF library.",
5
5
  "author": "Ruben Verborgh <ruben.verborgh@gmail.com>",
6
6
  "keywords": [
@@ -60,7 +60,7 @@
60
60
  "test": "jest",
61
61
  "lint": "eslint src perf test spec",
62
62
  "prepare": "npm run build",
63
- "spec": "npm run spec-1-1 && npm run spec-1-2",
63
+ "spec": "npm run spec-1-1 && npm run spec-1-2 && npm run spec-n3",
64
64
  "spec-1-1": "npm run spec-1-1-turtle && npm run spec-1-1-ntriples && npm run spec-1-1-nquads && npm run spec-1-1-trig",
65
65
  "spec-1-1-earl": "npm run spec-1-1-earl-turtle && npm run spec-1-1-earl-ntriples && npm run spec-1-1-earl-nquads && npm run spec-1-1-earl-trig",
66
66
  "spec-1-1-ntriples": "rdf-test-suite spec/parser.js https://w3c.github.io/rdf-tests/rdf/rdf11/rdf-n-triples/manifest.ttl -i '{ \"format\": \"n-triples\" }' -c .rdf-test-suite-cache/",
@@ -81,7 +81,11 @@
81
81
  "spec-1-2-earl-nquads": "rdf-test-suite spec/parser.js https://w3c.github.io/rdf-tests/rdf/rdf12/rdf-n-quads/syntax/manifest.ttl -i '{ \"format\": \"n-quads\" }' -c .rdf-test-suite-cache/ -o earl -p spec/earl-meta.json > spec/earl-nquads.ttl",
82
82
  "spec-1-2-earl-turtle": "rdf-test-suite spec/parser.js https://w3c.github.io/rdf-tests/rdf/rdf12/rdf-turtle/syntax/manifest.ttl -i '{ \"format\": \"turtle\" }' -c .rdf-test-suite-cache/ -o earl -p spec/earl-meta.json > spec/earl-turtle.ttl",
83
83
  "spec-1-2-earl-trig": "rdf-test-suite spec/parser.js https://w3c.github.io/rdf-tests/rdf/rdf12/rdf-trig/syntax/manifest.ttl -i '{ \"format\": \"trig\" }' -c .rdf-test-suite-cache/ -o earl -p spec/earl-meta.json > spec/earl-trig.ttl",
84
- "spec-clean": "rm -r .rdf-test-suite-cache/",
84
+ "spec-n3": "npm run spec-n3-parser && npm run spec-n3-extended",
85
+ "spec-n3-fetch": "sh scripts/fetch-n3-tests.sh",
86
+ "spec-n3-parser": "npm run spec-n3-fetch && rdf-test-suite spec/parser.js https://w3c-cg.github.io/N3/tests/N3Tests/manifest-parser.ttl -i '{ \"format\": \"text/n3\" }' -m 'https://w3c-cg.github.io/N3/tests/~.n3-tests/tests/'",
87
+ "spec-n3-extended": "npm run spec-n3-fetch && rdf-test-suite spec/parser.js https://w3c-cg.github.io/N3/tests/N3Tests/manifest-extended.ttl -i '{ \"format\": \"text/n3\" }' -m 'https://w3c-cg.github.io/N3/tests/~.n3-tests/tests/'",
88
+ "spec-clean": "rm -rf .rdf-test-suite-cache/ .n3-tests/",
85
89
  "docs": "cd src && docco *.js -o ../docs && cd .."
86
90
  },
87
91
  "repository": {
@@ -8,6 +8,8 @@ const { rdf, xsd } = namespaces;
8
8
  // eslint-disable-next-line prefer-const
9
9
  let DEFAULTGRAPH;
10
10
  let _blankNodeCounter = 0;
11
+ // The ID of the empty IRI, which cannot be '' as that is the ID of the default graph
12
+ const EMPTY_IRI_ID = '<>';
11
13
 
12
14
  const escapedLiteral = /^"(.*".*)(?="[^"]*$)/;
13
15
 
@@ -72,7 +74,9 @@ export class NamedNode extends Term {
72
74
  * the constructor assumes an already-validated IRI.
73
75
  */
74
76
  constructor(iri) {
75
- super(iri);
77
+ super(iri === '' ? EMPTY_IRI_ID : iri);
78
+ if (iri === '')
79
+ Object.defineProperty(this, 'value', { value: '' });
76
80
  }
77
81
 
78
82
  // ### The term type of this term
@@ -285,6 +289,10 @@ export function termFromId(id, factory, nested) {
285
289
  case '[':
286
290
  id = JSON.parse(id);
287
291
  break;
292
+ case '<':
293
+ if (id === EMPTY_IRI_ID)
294
+ return factory.namedNode('');
295
+ // falls through
288
296
  default:
289
297
  if (!nested || !Array.isArray(id)) {
290
298
  return factory.namedNode(id);
@@ -313,7 +321,7 @@ export function termToId(term, nested) {
313
321
 
314
322
  // Term instantiated with another library
315
323
  switch (term.termType) {
316
- case 'NamedNode': return term.value;
324
+ case 'NamedNode': return term.value || EMPTY_IRI_ID;
317
325
  case 'BlankNode': return `_:${term.value}`;
318
326
  case 'Variable': return `?${term.value}`;
319
327
  case 'DefaultGraph': return '';
package/src/N3Parser.js CHANGED
@@ -49,6 +49,8 @@ export default class N3Parser {
49
49
  this._lexer = options.lexer || new N3Lexer({ lineMode: isLineMode, n3: isN3, isImpliedBy: this._isImpliedBy });
50
50
  // Disable explicit quantifiers by default
51
51
  this._explicitQuantifiers = !!options.explicitQuantifiers;
52
+ // Disable formula-only blank node scoping by default
53
+ this._formulaScopedBlankNodes = !!options.formulaScopedBlankNodes;
52
54
  // Disable parsing of unsupported versions by default
53
55
  this._parseUnsupportedVersions = !!options.parseUnsupportedVersions;
54
56
  this._version = options.version;
@@ -111,11 +113,15 @@ export default class N3Parser {
111
113
  // Every new scope resets the predicate direction
112
114
  this._inversePredicate = false;
113
115
  this._expectOf = false;
114
- // In N3, blank nodes are scoped to a formula
115
- // (using a dot as separator, as a blank node label cannot start with it)
116
- this._prefixes._ = (this._graph ? `${this._graph.value}.` : '.');
117
- // Quantifiers are scoped to a formula
118
- this._quantified = Object.create(this._quantified);
116
+ // In N3, blank nodes and quantifiers are scoped to a formula;
117
+ // with `formulaScopedBlankNodes`, lists and blank node property lists
118
+ // share the enclosing scope instead of rescoping
119
+ if (!this._formulaScopedBlankNodes || type === 'formula') {
120
+ // Label the scope with the enclosing formula's blank node
121
+ // (using a dot as separator, as a blank node label cannot start with it)
122
+ this._prefixes._ = (this._graph ? `${this._graph.value}.` : '.');
123
+ this._quantified = Object.create(this._quantified);
124
+ }
119
125
  // A formula starts empty and must not inherit its parent's subject
120
126
  if (type === 'formula') {
121
127
  this._subject = null;