简体   繁体   中英

How to get the value of a resource which is a property of another resource in sparql query

how can get the value name of the capital city not the URI from this query

SELECT ?capital 
WHERE { <http://dbpedia.org/resource/Germany><http://dbpedia.org/ontology/capital> ?capital}

In the above query I am getting the URI of the capital of germany .ie http://dbpedia.org/resource/berlin how can get Only the berlin not its URI

The value you want is actually the value of the RDFS label property. If you're using the public DBpedia SPARQL endpoint , then you can use a query like this:

select ?label where {
  dbpedia:Germany dbpedia-owl:capital/rdfs:label ?label .
  filter langMatches(lang(?label),"en")
}

The property path dbpedia-owl:capital/rdfs:label means that you're getting the capital of Germany, and then getting the label of that. The filter expression lets you select just the English label of the resource. You can remove this filter, of course, but you'll get multiple results, since the resource has labels in different languages.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM