RDFLib / rdflib-jsonld

JSON-LD parser and serializer plugins for RDFLib
Other
283 stars 71 forks source link

Compact serialization #93

Open sharpaper opened 4 years ago

sharpaper commented 4 years ago

Is g.serialize() supposed to produce a compacted jsonld document? If I have this graph [node_a]->knows->[blank_node], when I retrieve node_a with rdflib and then serialize with rdflib-jsonld, I obtain this document

{
    "@context": [...],
    "@graph": [
        {
            "name": "Alice"
            "knows": { "id": "_:xxxxx" }
        },
        {
            "id": "_:xxxxx"
        }
    ]
}

whereas I would expect this

{
    "@context": [...],
    "name": "Alice"
    "knows": "_:xxxxx" 
}

Am I doing something wrong?

jbkoh commented 4 years ago

I'd be interested in this issue too. I understand it's easier to assign ids to blank nodes for serialization, but one of the upsides of JSON-LD is the nested format with JSON, which is more human-readable.

westurner commented 4 years ago

See also #52 :

How to use this from the command line with rdfpipe to convert from one format to another (with optional {compaction,}) could be helpfully added to README.rst.

nicholascar commented 4 years ago

The RDFlib maintainers are hoping to see JSON-LD 1.1 support completed soon and then for this package to me merged into the main RDFlib package as a main serializer/parser plugin.

If any of you are interested in completing JSON-LD 1.1 support in order to then take up other issues, such as this one, please let me or the rdflib-dev mailing list know. We have a couple of developers getting ready to look into this but more help will be greatly appreciated.

westurner commented 4 years ago

Is PyLD the only JSON-LD implementation with support for compaction at present? https://github.com/digitalbazaar/pyld/blob/316fbc2c9e25b3cf718b4ee189012a64b91f17e7/tests/runtests.py#L664

I don't think this issue should block the new rdflib major release which will hopefully contain a completed integrated json-ld 1.1 parser/serializer. Looking at https://rdflib.dev/ , JSON-LD [1.1] compaction (and docs for how to specify the serializer format parameter w/ the RDFlib API and the rdfpipe CLI [#52]) would probably entail a minor version bump to e.g. 6.1.0?

nicholascar commented 4 years ago

I don't think this issue should block the new rdflib major release

Agreed. We discussed just bringing rdflib-jsonld into main rdflib right now but I think it sensible to prove the 1.1 support and then do that, since the support is part-way implemented already. Then we retain the Issues/PRs and commit history that added the 1.1 support here for historical record but port over all issues such as this to the main rdflib Issues tracker.

sblack-usu commented 4 years ago

This is something I have interest in as well. Has there been any movement on supporting compact serialization of json-ld?

westurner commented 1 year ago

From https://github.com/google/yamlfmt/issues/125 ; it's called JSON-LD Framing :

reframe/compact/expand the underlying JSON-LD graph