Hi,
I tried to create a custom datatype with Jena and use if from a SPARQL query.
For example, I used temperatures in °C or °F. The complete example is here [1].

I found the documentation here quite useful:

 - Typed literals how-to
   http://incubator.apache.org/jena/documentation/notes/typed-literals.html

and I looked at the RomanNumeralDatatype [2] implementation in ARQ.

I created a TemperatureCelsius and TemperatureFahrenheit which extend 
BaseDatatype.
I'd like to be able to automatically compare or sort temperatures from my SPARQL
queries. For example, with a query like this:

  PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
  SELECT * WHERE {
    ?s rdf:value ?temperature .
  }
  ORDER BY ?temperature

Currently I get:

( ?temperature = "15"^^<http://jena.apache.org/datatypes/temperature/celsius> ) 
( ?s = <x2> ) -> [Root]
( ?temperature = "25"^^<http://jena.apache.org/datatypes/temperature/celsius> ) 
( ?s = <x1> ) -> [Root]
( ?temperature = 
"25"^^<http://jena.apache.org/datatypes/temperature/fahrenheit> ) ( ?s = <x3> ) 
-> [Root]

But, 25 °F = -3.89 °C, therefore 25 °F should be the first on the list.

Is there a way I can automatically apply the necessary conversions and ensure 
that
the ORDER BY sorts temperatures correctly?

An alternative is to not use custom datatypes and simply have something like 
this:

  :x :temperature [
    rdf:value "25.0" ;
    :unit :Celsius ;
  ]


A similar question is answered on http://answers.semanticweb.com/ [3], I wanted
to try the custom datatype approach anyway... and probably it's not a good idea.

What do you recommend in order to model unit of measurements and conversions
between those, making sure people can use SPARQL and/or inference to work with
their data?

I found these vocabularies/ontologies:

 - http://www.w3.org/2007/ont/unit
 - http://qudt.org/vocab/unit#
 - ...

Do you have other vocabularies/ontologies to suggest?

Thanks,
Paolo


 [1] 
https://github.com/castagna/jena-examples/blob/master/src/main/java/org/apache/jena/examples/ExampleDT_01.java
 [2] 
https://svn.apache.org/repos/asf/incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/util/RomanNumeralDatatype.java
 [3] http://answers.semanticweb.com/questions/3572/xsd-or-vocabulary

Reply via email to