Is it possible to know the type of the return values in a SPARQL query? For example, is there a function to define the type of ?x ?price ?p in the following query?
SELECT DISTINCT ?x ?price ?p
WHERE {
?x a :Product .
?x :price ?price .
?x ?p ?o .
}
I want to know that
typeOf(x) = resource
typeOf(?p) = property
typeOf(?price) = property target etc.
The datatype function will tell you whether a result is a resource or a literal and in the latter case tell you which datatype it has exactly.
For example, the following query on https://dbpedia.org/sparql
...
SELECT DISTINCT ?x ?code ?p datatype(?x) datatype(?code) datatype(?p)
WHERE {
?x a dbo:City.
?x dbo:areaCode ?code .
?x ?p ?o .
} limit 1
x | code | p | callret-3 | callret-4 | callret-5 |
---|---|---|---|---|---|
http://dbpedia.org/resource/Aconchi | "+52 623" | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2001/XMLSchema#anyURI | http://www.w3.org/2001/XMLSchema#string | http://www.w3.org/2001/XMLSchema#anyURI |
However this will not differentiate between "resource" and "property" because a resource may be a property. What you probably mean is "individual" and "property" but even a property can be treated as an individual, for example in the triple rdfs:label rdfs:label "label"
.
However you can always query the rdf:type of a resource, which may give you rdf:Property, owl:DatatypeProperty or owl:ObjectProperty.