Skip to content

Allow to configure blank node ids in toRDF #580

Description

@nichtich

Please support to configure how blank node ids are generated in toRDF (and possibly frameMergedOrDefault).

Function createMergedNodeMap supports to override default IdentifierIssuer (being new util.IdentifierIssuer('_:b')) with option issuer. Just change this line to

const issuer = options.issuer || new util.IdentifierIssuer('_:b');

or (more user-friendly) add an option bnode:

const issuer =  new util.IdentifierIssuer(`_:${options["bnode"]||"b"}`);

The problem

Blank node identifiers are repeated when serializing multiple RDF documents to N-Triples. For instance this two documents:

{"id":"x:1","x":{"title":"1"}}
{"id":"x:2","x":{"title":"2"}}

with additional @context

{
  "title": "http://purl.org/dc/terms/title",
  "id": "@id",
  "x": "http://example.org/x"
}

converted with

jsonld.toRDF(doc[0], {format: "application/n-quads"}),
jsonld.toRDF(doc[1], {format: "application/n-quads"}),

results in

<x:1> <http://example.org/x> _:b0 .                                                                                                                                                                                                              
_:b0 <http://purl.org/dc/terms/title> "1" .                                                                                                                                                                                                                 
<x:2> <http://example.org/x> _:b0 .                                                                                                                                                                                                              
_:b0 <http://purl.org/dc/terms/title> "2" .                                                                                                                                                                                                                 

Preferred solution

jsonld.toRDF(doc[0], {format: "application/n-quads", bnode: "a" }),
jsonld.toRDF(doc[1], {format: "application/n-quads", bnode: "b" }),

results in

<x:1> <http://example.org/x> _:a0 .                                                                                                                                                                                                              
_:a0 <http://purl.org/dc/terms/title> "1" .                                                                                                                                                                                                                 
<x:2> <http://example.org/x> _:b0 .                                                                                                                                                                                                              
_:b0 <http://purl.org/dc/terms/title> "2" .                                                                                                                                                                                                                 

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions