Search code examples
floating-pointxsdrdfliballegrograph

allegrograph xsd float literals


I'm uploading triples to an AG store from a graph generated in python by rdflib. Some of the objects in my triples are floats, so I add them to the graph like this:

Literal(float(float_value), datatype=XSD.float)

When I serialize the graph using rdflib I get "0.8049"^^xsd:float as intended.

But, after uploading it to the AG store, when I query the store, the literals I get back are like this (trix)

<typedLiteral datatype="http://www.w3.org/2001/XMLSchema#float">8.049E-1</typedLiteral>

I've tried all sorts of combinations, like uploading it as a string "8049E-0", or just as a string "0.8049" and such, but I haven't hit on the right incantation to get the decimal in the right place.

Any thoughts?

Jon


Solution

  • Doh!

    Not the first time I've made things more complicated than they need to be. These Literals aren't floats, they're just decimal numbers. XSD has a perfectly good datatype for these.

    added to the graph in rdflib thus:

    Literal(value, datatype=XSD.decimal)
    

    returns from the AG store thus:

    <typedLiteral datatype="http://www.w3.org/2001/XMLSchema#decimal">0.8049</typedLiteral>
    

    sorry for the noise, jjc