Question

I have an ontology like this

<rdf:Description rdf:about="http://www.semanticweb.org/li/ontologies/159702/fcd#W21">
    <prop:dm rdf:datatype="http://www.w3.org/2001/XMLSchema#double">99.87</prop:dm>
    <prop:den rdf:datatype="http://www.w3.org/2001/XMLSchema#double">0.86</prop:den>
    <prop:p rdf:datatype="http://www.w3.org/2001/XMLSchema#double">20.0</prop:p>
    <prop:glus rdf:datatype="http://www.w3.org/2001/XMLSchema#double">1.1</prop:glus>
    <prop:k rdf:datatype="http://www.w3.org/2001/XMLSchema#double">300.0</prop:k>
    <rdf:type rdf:resource="http://www.semanticweb.org/li/ontologies/159702/fcd#Food"/>
    <prop:enerc_kcal rdf:datatype="http://www.w3.org/2001/XMLSchema#double">398.24</prop:enerc_kcal>
<rdf>

Basically it discribe an individual (W21) has data property assertions (dm,den,p,glus,k and enerc_kcal).

How do I return all data property that individual has using sparql. The query I built just return bunch of "NamedIndividual"

PREFIX my: <http://www.semanticweb.org/li/ontologies/159702/fcd#>
SELECT ?x 
WHERE {  my:W21 rdf:type ?x}

any help on this?

Was it helpful?

Solution

Your query,

PREFIX my: <http://www.semanticweb.org/li/ontologies/159702/fcd#>
SELECT ?x 
WHERE {  my:W21 rdf:type ?x}

asks for the values of the rdf:type property. In the data that you've shown, there's only one of those, and that's owl:NamedIndividual. If you want the values of all properties, you'd use something like

PREFIX my: <http://www.semanticweb.org/li/ontologies/159702/fcd#>
SELECT ?p ?o  
WHERE {  my:W21 ?p ?o }

Now, in the question title, you've asked about data properties, but I'm not sure whether you're asking for the "data that is the object of a property", or if you're actually asking about OWL DatatypeProperties which have literals, but not resources, as values. If that's what you want, you could use:

PREFIX my: <http://www.semanticweb.org/li/ontologies/159702/fcd#>
PREFIX owl:     <http://www.w3.org/2002/07/owl#>
SELECT ?p ?o  
WHERE {  my:W21 ?p ?o . ?p a owl:DatatypeProperty }

to get all the values of properties that are actually declared as datatype properties. If you don't have the property declarations, though, you might just want to ask for objects that are literals:

PREFIX my: <http://www.semanticweb.org/li/ontologies/159702/fcd#>
PREFIX owl:     <http://www.w3.org/2002/07/owl#>
SELECT ?p ?o  
WHERE {  my:W21 ?p ?o . filter isLiteral(?o) }

OTHER TIPS

I don't know if I understand the question correctly, but what about:

SELECT DISTINCT * WHERE { ?s ?p ?o }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top