Retrieving a DBpedia resource by its string name with SPARQL
Asked Answered
N

1

8

I am trying to get the resource describing country Romania by the country name with this query:

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX : <http://dbpedia.org/resource/>

SELECT DISTINCT ?x WHERE {
     ?x foaf:name 'Romania'
}

SPARQL results

However, it does not retrieve anything. How can I get the resource http://dbpedia.org/resource/Romania (:Romania) by the string 'Romania'. If I want to retrieve the name of the country by the country resource I use the following query which works fine:

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX : <http://dbpedia.org/resource/>

SELECT DISTINCT ?x WHERE {
     :Romania foaf:name ?x
}

SPARQL results

Nagoya answered 7/5, 2011 at 15:7 Comment(0)
A
10

This ought to do it:

SELECT ?c
WHERE {
  ?c a dbo:Country ;
     foaf:name "Romania"@en .
  FILTER NOT EXISTS { ?c dbo:dissolutionYear ?y }
}

SPARQL results

The critical quirk here is that "Romania" with no language tag is different from "Romania"@en. And then you also have a bunch of historical states that were also called Romania, so we filter out any of those that have years of dissolution. DBpedia's data-completeness for years of dissolution isn't terrific, but all the Romanian ones, at least, are marked.

Ardeliaardelis answered 7/5, 2011 at 16:48 Comment(2)
@glennmcdonald Interestingly, some years later, someone has used the country infobox template on the Romania page, so the results also include Commemorative_coins_of_Romania!Chiu
Even more interestingly, the dissolutionDate property was important in answering this question as well.Chiu

© 2022 - 2024 — McMap. All rights reserved.