N3.js icon indicating copy to clipboard operation
N3.js copied to clipboard

N3 writer doesn't prefix correctly

Open gezever opened this issue 1 year ago • 3 comments

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>.

gezever avatar Nov 15 '23 17:11 gezever

@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.)

TallTed avatar Nov 15 '23 19:11 TallTed

@TallTed I edited the issue.

gezever avatar Nov 16 '23 12:11 gezever

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.

RubenVerborgh avatar Dec 20 '23 15:12 RubenVerborgh