Type coercion to decimals?

Hi,

I have json data with floating point numbers which I'm trying to 
interpret as jsonld where the jsonld context calls for the relevant 
properties to be interpreted as xsd:decimal.

In the tools I'm using, including https://json-ld.org/playground/, this 
is generating illegal RDF. I'm trying work out if this is a bug in the 
tools or whether this form of coercion is not allowed.

A test case is:

{
   "@context": {
     "@vocab": "http://example.com/vocab",
     "long": {
       "@id": "http://www.w3.org/2003/01/geo/wgs84_pos#long",
       "@type": "http://www.w3.org/2001/XMLSchema#decimal"
     },
     "lat": {
       "@id": "http://www.w3.org/2003/01/geo/wgs84_pos#lat",
       "@type": "http://www.w3.org/2001/XMLSchema#decimal"
     }
   },
   "@graph": [
     {
       "@id": "http://example.com/graph/1",
       "@graph": {
         "@id": "http://example.com/resource/1",
         "lat": 51.449604,
         "long": -2.601738
       }
     }
   ]
}

Using the json-ld playground, and using Jena (which in turn depends on 
jsonld-java), this generates the purported n-quads:

<http://example.com/resource/1> 
<http://www.w3.org/2003/01/geo/wgs84_pos#lat> 
"5.1449604E1"^^<http://www.w3.org/2001/XMLSchema#decimal> 
<http://example.com/graph/1> .

<http://example.com/resource/1> 
<http://www.w3.org/2003/01/geo/wgs84_pos#long> 
"-2.601738E0"^^<http://www.w3.org/2001/XMLSchema#decimal> 
<http://example.com/graph/1> .

The trouble is that the E notation is not legal for XSD decimals so this 
RDF is syntactically invalid (at least for datatype-aware processors).

In this case I have some control over the source json so I could pass 
the lat/long values as strings but that would break any consumers of the 
json data. If I treat lat/longs as xsd:double instead of xsd:decimal 
that at least gets me legal RDF, just not the RDF I was looking for.

Any thoughts on whether this is just a bug in the various tools or 
something deeper? Given that both jsonld-java and jsonld.js have the 
same behaviour I'm worried it might be deeper.

Dave

Received on Friday, 11 January 2019 11:41:43 UTC