Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
edwardsph opened this issue Aug 10, 2023 · 4 comments
Closed

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

edwardsph opened this issue Aug 10, 2023 · 4 comments

Comments

@edwardsph
Copy link

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
Copy link
Collaborator

jeswr commented Aug 10, 2023

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

@edwardsph
Copy link
Author

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:

N3.js/test/N3Writer-test.js

Lines 511 to 533 in 075e606

it('should serialize triples with a one-triple blank node as subject', done => {
const writer = new Writer();
writer.addQuad(writer.blank(new NamedNode('a'), new NamedNode('b')), new NamedNode('c'), new NamedNode('d'));
writer.addQuad(writer.blank({ predicate: new NamedNode('a'), object: new NamedNode('b') }), new NamedNode('c'), new NamedNode('d'));
writer.addQuad(writer.blank([{ predicate: new NamedNode('a'), object: new NamedNode('b') }]), new NamedNode('c'), new NamedNode('d'));
writer.end((error, output) => {
output.should.equal('[ <a> <b> ] <c> <d>.\n' +
'[ <a> <b> ] <c> <d>.\n' +
'[ <a> <b> ] <c> <d>.\n');
done(error);
});
});
it('should serialize triples with an empty blank node as graph', done => {
const writer = new Writer();
writer.addQuad(new NamedNode('a'), new NamedNode('b'), new NamedNode('c'), writer.blank());
writer.addQuad(new NamedNode('a'), new NamedNode('b'), new NamedNode('c'), writer.blank([]));
writer.end((error, output) => {
output.should.equal('[] {\n<a> <b> <c>\n}\n' +
'[] {\n<a> <b> <c>\n}\n');
done(error);
});
});

@RubenVerborgh
Copy link
Member

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
Copy link
Member

Fix published as v1.17.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants