sparqlontologyprotegeprotege4

How to get individuals data property value in sparql


Hi i am in new to ontologies. I have developed a restaurant ontology by Protege software. But I badly need a SPARQL query that finds property values for all individuals of a class.

protege screenshot

I want to get a result like:

Angels_n_Gypsies
House #30, Rd No. 19/A, Dhaka 1213, Bangladesh

graph image


Solution

  • Just follow the property values...

    SELECT ?rname ?lname
    WHERE {
       ?inst a :Popular_restaurant .
       ?inst :restaurant_name ?rname .
       ?inst :Location_name ?lname .
    }
    

    But that's just the end result. A way to understand SPARQL is to start pedantically. For example:

    SELECT ?inst
    WHERE {
       ?inst a :Popular_restaurant .
    }
    

    That gets you all members of the class :Popular_restaurant. Then find what properties are defined for each member:

    SELECT ?inst ?p ?o
    WHERE {
       ?inst a :Popular_restaurant .
       ?inst ?p ?o .
    }
    

    And the bindings for p will tell you what properties are defined for members of this class. So use those values to continuously refine the query.