user3335188
user3335188

Reputation: 99

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

Upvotes: 0

Views: 609

Answers (1)

Joshua Taylor
Joshua Taylor

Reputation: 85883

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.

Upvotes: 3

Related Questions