Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@babel/core": "^7.16.0",
"@babel/preset-env": "^7.16.0",
"@babel/register": "^7.16.0",
"@rdfjs/data-model": "^1",
"arrayify-stream": "^1.0.0",
"browserify": "^17.0.0",
"chai": "^4.0.2",
Expand All @@ -42,6 +43,7 @@
"mocha": "^8.0.0",
"nyc": "^14.1.1",
"pre-commit": "^1.2.2",
"rdf-isomorphic": "^1.3.1",
"rdf-test-suite": "^1.19.2",
"streamify-string": "^1.0.1",
"uglify-js": "^3.14.3"
Expand Down
2 changes: 1 addition & 1 deletion src/N3Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default class N3Parser {
this._inversePredicate = false;
// In N3, blank nodes are scoped to a formula
// (using a dot as separator, as a blank node label cannot start with it)
this._prefixes._ = (this._graph ? `${this._graph.id.substr(2)}.` : '.');
this._prefixes._ = (this._graph ? `${this._graph.value}.` : '.');
// Quantifiers are scoped to a formula
this._quantified = Object.create(this._quantified);
}
Expand Down
81 changes: 80 additions & 1 deletion test/N3Parser-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Parser, NamedNode, BlankNode, Quad, termFromId } from '../src/';
import rdfDataModel from '@rdfjs/data-model';
import { isomorphic } from 'rdf-isomorphic';
import { Parser, NamedNode, BlankNode, Quad, termFromId, DataFactory as DF } from '../src/';

const BASE_IRI = 'http://example.org/';

Expand Down Expand Up @@ -1872,6 +1874,83 @@ describe('Parser', () => {
});
});

describe('A parser instance with external data factory', () => {
it('should parse', () => {
const parser = new Parser({
baseIRI: BASE_IRI,
format: 'n3',
factory: rdfDataModel,
});
const quads = parser.parse(`
@prefix : <http://example.com/> .
{ :weather a :Raining } => { :weather a :Cloudy } .
`);

quads.length.should.be.gt(0);

const g1 = DF.blankNode();
const g2 = DF.blankNode();

isomorphic(quads, [
DF.quad(
DF.namedNode('http://example.com/weather'),
DF.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
DF.namedNode('http://example.com/Raining'),
g1
),
DF.quad(
DF.namedNode('http://example.com/weather'),
DF.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
DF.namedNode('http://example.com/Cloudy'),
g2
),
DF.quad(
g1,
DF.namedNode('http://www.w3.org/2000/10/swap/log#implies'),
g2
),
]).should.be.true;
});
});

describe('A turtle parser instance with external data factory', () => {
it('should parse', () => {
const parser = new Parser({
baseIRI: BASE_IRI,
format: 'turtle',
factory: rdfDataModel,
});
const quads = parser.parse(`
@prefix : <http://example.com/> .
:weather a :Raining .

:jeswr :knows [
:name "Thomas" ;
] .
`);

const bnode = DF.blankNode();

isomorphic(quads, [
DF.quad(
DF.namedNode('http://example.com/weather'),
DF.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
DF.namedNode('http://example.com/Raining')
),
DF.quad(
DF.namedNode('http://example.com/jeswr'),
DF.namedNode('http://example.com/knows'),
bnode
),
DF.quad(
bnode,
DF.namedNode('http://example.com/name'),
DF.literal('Thomas')
),
]).should.be.true;
});
});

describe('IRI resolution', () => {
describe('RFC3986 normal examples', () => {
itShouldResolve('http://a/bb/ccc/d;p?q', 'g:h', 'g:h');
Expand Down