Wimmics / corese

Software platform implementing and extending the standards of the Semantic Web.
https://project.inria.fr/corese/
Other
103 stars 29 forks source link

JSON-LD serializer wrongly uses `@type` #182

Open pchampin opened 7 months ago

pchampin commented 7 months ago

Issue Description:

Sometimes, Corese produces invalid JSON-LD. More specifically, it uses @type with a value object as its value.

Steps to Reproduce:

Submit the following SPARQL query, requesting the result in application/ld+json:

CONSTRUCT { <tag:s> a 42 } {}

Expected Behavior:

The result should be (something like)

{
    "@context": {
        "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
        "xsd": "http://www.w3.org/2001/XMLSchema#"
    },
    "@graph": [
        {
            "@id": "tag:s",
            "rdf:type": {
                "@type": "xsd:integer",
                "@value": "42"
            }
        }
    ]
}

Actual Behavior:

The result is

{
    "@context": {
        "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
        "xsd": "http://www.w3.org/2001/XMLSchema#"
    },
    "@graph": [
        {
            "@id": "tag:s",
            "@type": {
                "@type": "xsd:integer",
                "@value": "42"
            }
        }
    ]
}

which is invalid.

Note to Developers:

When generating JSON-LD, when the predicate is rdf:type, the @type keyword must not be used if the object is a literal. Instead, the property key rdf:type should be used (provided that the context defines the rdf prefix -- otherwise, the whole IRI should be used as the property key).

Granted, literals as the object of rdf:type are a bit of a corner case, but they are valid RDF.