Skip to content

Commit f3898fd

Browse files
jeswrtpluscode
andauthored
fix: use BlankNode according to RDF/JS spec (#346)
Co-authored-by: Tomasz Pluskiewicz <tpluscode@users.noreply.github.com>
1 parent f4887f3 commit f3898fd

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

package-lock.json

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"@babel/core": "^7.16.0",
3333
"@babel/preset-env": "^7.16.0",
3434
"@babel/register": "^7.16.0",
35+
"@rdfjs/data-model": "^1",
3536
"arrayify-stream": "^1.0.0",
3637
"browserify": "^17.0.0",
3738
"chai": "^4.0.2",

src/N3Parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export default class N3Parser {
8686
this._inversePredicate = false;
8787
// In N3, blank nodes are scoped to a formula
8888
// (using a dot as separator, as a blank node label cannot start with it)
89-
this._prefixes._ = (this._graph ? `${this._graph.id.substr(2)}.` : '.');
89+
this._prefixes._ = (this._graph ? `${this._graph.value}.` : '.');
9090
// Quantifiers are scoped to a formula
9191
this._quantified = Object.create(this._quantified);
9292
}

test/N3Parser-test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import rdfDataModel from '@rdfjs/data-model';
12
import { Parser, termFromId } from '../src/';
23
import { NamedNode, BlankNode, Quad } from '../src/N3DataFactory';
34

@@ -2486,6 +2487,22 @@ describe('Parser', () => {
24862487
});
24872488
});
24882489

2490+
describe('A parser instance with external data factory', () => {
2491+
it('should parse', () => {
2492+
const parser = new Parser({
2493+
baseIRI: BASE_IRI,
2494+
format: 'n3',
2495+
factory: rdfDataModel,
2496+
});
2497+
const quads = parser.parse(`
2498+
@prefix : <http://example.com/> .
2499+
{ :weather a :Raining } => { :weather a :Cloudy } .
2500+
`);
2501+
2502+
quads.length.should.be.gt(0);
2503+
});
2504+
});
2505+
24892506
describe('IRI resolution', () => {
24902507
describe('RFC3986 normal examples', () => {
24912508
itShouldResolve('http://a/bb/ccc/d;p?q', 'g:h', 'g:h');

0 commit comments

Comments
 (0)