How to get individuals data property value in sparql

爱⌒轻易说出口 提交于 2020-01-24 20:08:26

问题


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.

I want to get a result like:

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


回答1:


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.



来源:https://stackoverflow.com/questions/36752918/how-to-get-individuals-data-property-value-in-sparql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!