问题
I'm working with an ontology OWL and making a query about it.
My query is:
"PREFIX a: http://www.owl-ontologies.com/Indoor.owl# " + "SELECT ?X " + "WHERE { ?X a:hasDay a:" + day + " . " + " ?X a:hasRoom a:" + room + " . " + " ?X a:hasStartTime a:" + startTime +" }";
At the moment to make the query, the console of NetBeans throw me:
Undefined object property used in query: http://www.owl-ontologies.com/Indoor.owl#hasStartTime
But hasStartTime in the ontology isn't an object property, it is a data type (int).
回答1:
Assuming that the value of the Java variable startTime
is e.g. 420 (7am), if you look at your SPARQL query, the last triple pattern is made by
?X a:hasStartTime a:
plus value of ``startTime,
i.e. it results in
?X a:hasStartTime a:420
RDF literals have to be put in quotes without a prefix - it's a literal and not a prefixed URI, e.g.
?X a:hasStartTime 420
or to make the datatype more explicit (for integer values the above is just a shortcut)
?X a:hasStartTime "420"^^<http://www.w3.org/2001/XMLSchema#integer>
来源:https://stackoverflow.com/questions/44036787/make-a-query-in-sparql-with-datatype-property