Reputation: 139
I am very new to the semantic web, dbpedia and SPARQL. I want to find all states of the united states and their capitals. This is what i have now.
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT DISTINCT ?state_label ?capital_label
WHERE {
?state_label dct:subject dbc:States_of_the_United_States.
?state_label dbo:capital ?capital_label.
}
I only got 36 results instead of 50. Could somebody help?
Upvotes: 3
Views: 1010
Reputation: 9434
Sometimes, as in this case, the issue is in the data, not in your query.
Also note that even though the main DBpedia data set typically lags behind Wikipedia, the primary way to correct DBpedia data is still by editing Wikipedia. If DBpedia doesn't seem to have extracted the correct data from Wikipedia, it's helpful to tell DBpedia...
There are apparently only 5 yago:StateCapitalsInTheUnitedStates
in DBpedia, but we know that's not true about the world, nor about the data in Wikipedia -- so there are definitely things to be changed.
Here's a query that gets you all resources typed as yago:StatesOfTheUnitedStates
with their http://dbpedia.org/property/capital
(missing for Delaware; doubled for New Jersey) and http://dbpedia.org/ontology/capital
(missing for several states) --
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/property/>
SELECT ?state
?dbocapital
?dbpcapital
WHERE
{
?state a yago:StatesOfTheUnitedStates
OPTIONAL { ?state dbo:capital ?dbocapital }
OPTIONAL { ?state dbp:capital ?dbpcapital }
}
ORDER BY ?state
Upvotes: 1
Reputation: 85863
In looking at the resource for New Hampshire, I see that one of its types is yago:StatesOfTheUnitedStates. When I request all of those, I get 51 results, and when I request all of those and their capitals, I get 50. Those numbers sound right, but looking at the data, it's a bit more complicated; there's a non-state result (U.S. State), and New Jersey has two (the resource Trenton, and the string "Trenton"), and Delaware doesn't have a capital listed (I'm not sure why, but the triple just isn't present in DBpedia). At any rate, if you're willing to take the 49 that have capitals, you filter use this:
select ?state ?capital where {
?state a yago:StatesOfTheUnitedStates ;
dbp:capital ?capital .
filter isIRI(?capital)
}
Upvotes: 3