json-ld.org icon indicating copy to clipboard operation
json-ld.org copied to clipboard

Framing primitive types vs typed literals

Open MajewskiKrzysztof opened this issue 3 years ago • 1 comments

I have such data as an example:

{
  "http://example.com/test": true,
  "http://example.com/test2": {
    "@value": true,
    "@type": "http://www.w3.org/2001/XMLSchema#boolean"
  }
}

Both of these properties have boolean values. One of them is defined as a primitive type and the other one is a typed literal.

When I convert it to triples I can see that both of them are properly interpreted as xsd:boolean datatypes:

_:b0 <http://example.com/test2> "true"^^<http://www.w3.org/2001/XMLSchema#boolean> .
_:b0 <http://example.com/test> "true"^^<http://www.w3.org/2001/XMLSchema#boolean> .

But when I try to use a frame where I explicitly define both of them as an xsd:boolean:

{
  "@context": {
    "test": {
      "@id": "http://example.com/test",
      "@type": "http://www.w3.org/2001/XMLSchema#boolean"
    },
    "test2": {
      "@id": "http://example.com/test2",
      "@type": "http://www.w3.org/2001/XMLSchema#boolean"
    }
  }
}

only one is recognised:

{
  "@context": {
    "test": {
      "@id": "http://example.com/test",
      "@type": "http://www.w3.org/2001/XMLSchema#boolean"
    },
    "test2": {
      "@id": "http://example.com/test2",
      "@type": "http://www.w3.org/2001/XMLSchema#boolean"
    }
  },
  "http://example.com/test": true,
  "test2": true
}

Why is this happening?

MajewskiKrzysztof avatar Sep 14 '22 07:09 MajewskiKrzysztof

This is not an artifact of framing, but of compaction. Specifically, the term selection algorithm. That algorithm attempts to select the most appropriate term when compacting,p. Terms with at @type generally are there to interpret string values, not other native types such as Boolean. The term selection algorithm echos this bias by not favoring a term having a matching @type in the selection.

Generally, using non-string values short-circuits most special logic for expansion and compaction.

gkellogg avatar Sep 14 '22 14:09 gkellogg