rdfjs / N3.js

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

Can this write blank nodes with multiple predicate/object pairs? #360

Closed edwardsph closed 11 months ago

edwardsph commented 11 months ago

The output I am looking for is:

[ ] <a> <b> ;
    <c> <d> .

or

[
  <a> <b> ;
  <c> <d> 
] .

The workaround I have found is obviously not intended as it uses internal functions:

writer._write(writer._encodeIriOrBlank(writer.blank([
  { predicate: namedNode('a'), object: namedNode('b') },
  { predicate: namedNode('c'), object: namedNode('d') },
])));
writer._write('.\n');

This produces the second style output.

jeswr commented 11 months ago

I wouldn't think so as the design goal of this library is stream writing rather than pretty-printing.

edwardsph commented 11 months ago

I think it would still fit with the design if there was something like addBlank().

There are test cases where the blank node and its contents are a subject, or the blank node is a graph: https://github.com/rdfjs/N3.js/blob/075e606cb76463a2e1617fe7e4c6ff390cb7ec4c/test/N3Writer-test.js#L511-L533

RubenVerborgh commented 11 months ago

The output I am looking for is:

[ ] <a> <b> ;
    <c> <d> .

This one should have worked:

import { Writer, DataFactory } from './lib/index.js';

const writer = new Writer();
const { namedNode } = DataFactory;

const blank = writer.blank();
writer.addQuad(blank, namedNode('a'), namedNode('b'));
writer.addQuad(blank, namedNode('c'), namedNode('d'));

writer.end((err, result) => console.log(result));

but it returns this at the moment:

[] <a> <b>.
[] <c> <d>.

Let me check if this is an easy fix.

RubenVerborgh commented 11 months ago

Fix published as v1.17.1.