digitalbazaar/pyld

Compacting RDF lists with @list leaves RDF vocabulary in JSON-LD

sklarman opened this issue · 0 comments

Not sure if it's a feature or a bug, but at least my intuitive expectation is not met in the following round-trip conversion involving @list:

Initial document:

{
    "@context": {
        "@vocab": "http://example.com/",
        "myList": {
            "@container": "@list"
        }
    },
    "@graph": [
        {
            "myList": ["a"]
        }
    ]
}

Converted to N-Quads:

_:b0 <http://example.com/myList> _:b1 .
_:b1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "a" .
_:b1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .

Back to expanded JSON-LD (e.g. with https://www.easyrdf.org/converter):

[
    {
        "http://example.com/myList": [
            {
                "@id": "_:b1"
            }
        ]
    },
    {
        "@id": "_:b1",
        "http://www.w3.org/1999/02/22-rdf-syntax-ns#first": [
            {
                "@value": "a"
            }
        ],
        "http://www.w3.org/1999/02/22-rdf-syntax-ns#rest": [
            {
                "@id": "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"
            }
        ]
    },
    {
        "@id": "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"
    }
]

And then back to compacted JSON-LD with the initial context:

{
  "@context": {
    "@vocab": "http://example.com/",
    "myList": {
      "@container": "@list"
    }
  },
  "@graph": [
    {
      "http://example.com/myList": {
        "@id": "_:b1"
      }
    },
    {
      "@id": "_:b1",
      "http://www.w3.org/1999/02/22-rdf-syntax-ns#first": "a",
      "http://www.w3.org/1999/02/22-rdf-syntax-ns#rest": {
        "@id": "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"
      }
    }
  ]
}

In this last step I would expect to get the initial document again (or in any case one without explicit RDF vocabulary in it), which is the behavior I observed in most analogous cases. Note also that the key http://example.com/myList didn't get abbreviated as it normally would was it not for the @list container directive.

Could you please help me clarify if this looks ok to you or I am perhaps missing something? Thanks a lot!