Greetings!
I am trying to get information from DBPedia about Brazilian cities.
I’m interested in getting the home page of the local administration (prefeitura), which I can find through either foaf:homepage
or dbo:wikiPageExternalLink
properties.
I also need to know which Brazilian state the city belongs to.
I’ve come up with the following SPARQL query so far:
PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dbo:<http://dbpedia.org/ontology/>
PREFIX dbr:<http://dbpedia.org/resource/>
PREFIX dbp:<http://dbpedia.org/property/>
PREFIX foaf:<http://xmlns.com/foaf/0.1/>
PREFIX yago:<http://dbpedia.org/class/yago/>
SELECT ?city, ?name, ?state_abbr, ?state_name, ?link, ?external_link WHERE {
?city a dbo:City ;
dbo:country dbr:Brazil .
OPTIONAL {
?city foaf:homepage ?link .
}
OPTIONAL {
FILTER REGEX(STR(?external_link), ".gov.br")
?city dbo:wikiPageExternalLink ?external_link .
}
OPTIONAL {
?city rdfs:label ?name
FILTER(LANG(?name) = "" || LANGMATCHES(LANG(?name), "pt"))
}
OPTIONAL {
?city dbo:isPartOf ?state .
?state a yago:WikicatStatesOfBrazil .
?state dbp:coordinatesRegion ?state_abbr .
}
OPTIONAL {
?city dbo:isPartOf ?state .
?state a yago:WikicatStatesOfBrazil .
?state rdfs:label ?state_name .
FILTER(LANG(?state_name) = "" || LANGMATCHES(LANG(?state_name), "pt"))
}
OPTIONAL { # cities linked to a state whose URI has changed
?city dbo:isPartOf ?state_old_page .
?state_old_page dbo:wikiPageRedirects ?state .
?state a yago:WikicatStatesOfBrazil .
?state dbp:coordinatesRegion ?state_abbr .
}
OPTIONAL { # cities wrongfully linked to a city instead of state
?city dbo:isPartOf ?other_city .
?other_city dbo:isPartOf ?state .
?state a yago:WikicatStatesOfBrazil .
?state dbp:coordinatesRegion ?state_abbr .
}
}
But sometimes a city doesn’t have a state assigned (such as Marataízes) or they don’t have a link to a homepage. I can do some data cleaning myself, for my own use, but I wonder if and how I could contribute to improve the data on DBPedia.
The code for the queries on Github, in case you have suggestions for improving them.