rdfjs / N3.js

Lightning fast, spec-compatible, streaming RDF for JavaScript
http://rdf.js.org/N3.js/
Other
714 stars 130 forks source link

N3 writer doesn't prefix correctly #372

Open gezever opened 10 months ago

gezever commented 10 months ago
const N3 = require('n3');
const { DataFactory } = N3;
const { namedNode, quad } = DataFactory;
const writer = new N3.Writer({ prefixes: {   ex1: 'http://example.org/' } });
writer.addQuad(
    namedNode('http://example.org/s1'),
    namedNode('http://example.org/p'),
    namedNode('http://example.org/1')
);
writer.addQuad(quad(
    namedNode('http://example.org/s2'),
    namedNode('http://example.org/p'),
    namedNode('http://example.org/_1')
));
writer.addQuad(quad(
    namedNode('http://example.org/s3'),
    namedNode('http://example.org/p'),
    namedNode('http://example.org/v1.0')
));
writer.end((error, result) => console.log(result));

expected results:

@prefix ex1: <http://example.org/>.

ex1:s1  ex1:p   ex1:1 .
ex1:s2  ex1:p   ex1:_1 .
ex1:s3  ex1:p   ex1:v1.0 .

results:

@prefix ex1: <http://example.org/>.

ex1:s1 ex1:p <http://example.org/1>.
ex1:s2 ex1:p ex1:_1.
ex1:s3 ex1:p <http://example.org/v1.0>.
TallTed commented 10 months ago

@gezever — I suggest that you edit your initial comment, and fence the expected results and results blocks with lines of three backticks (and nothing else), as —

``` 

This will prevent the content of those blocks from being treated as Markdown, as they currently are, making it difficult to see what you meant us to see.

(You should also delete the single backticks currently leading and trailing each block.)

gezever commented 10 months ago

@TallTed I edited the issue.

RubenVerborgh commented 9 months ago

N3.js does not strive for the shortest form; it adds some prefixes but not exhaustively, and this for performance reasons. That said, in this case, the regex can easily be adjusted, presumably without performance impact.