RDFLib / rdflib-jsonld

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

On parsing, @included section is ignored unless the JSON-LD document is flattened #98

Open anatoly-scherbakov opened 3 years ago

anatoly-scherbakov commented 3 years ago

Disposition

Full code example is in this Gist.

I am trying to import a JSON-LD document into an RDFLib ConjunctiveGraph. The document:

{
    "@context": {
        "schema": "https://schema.org/",
        "blog": "https://blog.me/",
        "ex": "https://example.org/",
        "rdfs": "http://www.w3.org/2000/01/rdf-schema#"
    },
    "@id": "blog:JSONLD-and-named-graphs",
    "@type": "schema:blogPost",
    "rdfs:label": "JSON-LD and Named Graphs",
    "@included": [
        {
            "@id": "ex:Robot",
            "@type": "rdfs:Class"
        },
        {
            "@id": "ex:Rover",
            "rdfs:subClassOf": {
                "@id": "ex:Robot"
            }
        }
    ]
}

Notice it has an @included section.

Actual Result

The contents of the @included section is NOT imported, i.e. N3 serialization looks like this:

@prefix blog: <https://blog.me/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix schema: <https://schema.org/> .

blog:JSONLD-and-named-graphs a schema:blogPost ;
    rdfs:label "JSON-LD and Named Graphs" .

...Unless

... I do jsonld.flatten() before importing, in which case everything works:

@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

<https://example.org/Robot> a rdfs:Class .

<https://blog.me/JSONLD-and-named-graphs> a <https://schema.org/blogPost> ;
    rdfs:label "JSON-LD and Named Graphs" .

<https://example.org/Rover> rdfs:subClassOf <https://example.org/Robot> .

Is this expected behavior?