Reputation: 543
I have the following SPARQL query:
SELECT ?nationalityLabel WHERE {
dbpedia:Henrik_Ibsen dbpedia-owl:nationality ?nationality .
?nationality rdfs:label ?nationalityLabel .
}
I have checked that Henrik Ibsen exists and that he has the nationality ontology/property on him: http://dbpedia.org/page/Henrik_Ibsen
And this is an ontology: http://dbpedia.org/ontology/nationality
A very similar query to this listed here works: https://stackoverflow.com/a/10248653/1680130
The problem I have is that the query doesn't return any result.
If I could get help solving this it would be great.
Summarized solution: Both answers were great so upvote to both but landed on Joshua's in the end because informing about dbpedia-owl being cleaner. Optimal solution in my opinion:
First check with dbpedia-owl for birth-place:
select ?label {
dbpedia:Henrik_Ibsen
dbpedia-owl:birthPlace
[ a dbpedia-owl:Country ;
rdfs:label ?label ]
filter langMatches(lang(?label),"en")
}
If found then get the demonym:
select ?label {
dbpedia:Norway dbpedia-owl:demonym ?label
filter langMatches(lang(?label),"en")
}
If above fails then do the "dirty" query:
SELECT
?nationality
WHERE {
dbpedia:Henrik_Ibsen dbpprop:nationality ?nationality .
filter langMatches(lang(?nationality),"en")
}
Of course is "dirty" means data being correct but not so often present the order might be better other way around because people can be born in a country but from a different.
Upvotes: 3
Views: 2112
Reputation: 85833
Kristian's answer is right that the property is dbpprop:nationality
that Henrik Ibsen has. You're right that there is a dbpedia-owl:nationality
property, too, but Henrik Ibsen doesn't have a value for it, unfortunately. The value of dbpprop:nationality
that Henrik Ibsen has, though, is a string, which is a literal, and literals cannot be the subjects of triples in RDF, so ?nationality rdfs:label ?nationalityLabel
in your query will never match.
The DBpedia ontology data (dbpedia-owl
) tends to be cleaner than the dbpprop
data, so you might prefer a solution using dbpedia-owl
properties that Henrik Ibsen does have. In this case, you might look to the dbpedia-owl:birthPlace
. Then you could get the name the country of the birth places:
select ?label {
dbpedia:Henrik_Ibsen
dbpedia-owl:birthPlace
[ a dbpedia-owl:Country ;
rdfs:label ?label ]
}
You might want to narrow the permissible languages:
select ?label {
dbpedia:Henrik_Ibsen
dbpedia-owl:birthPlace
[ a dbpedia-owl:Country ;
rdfs:label ?label ]
filter langMatches(lang(?label),"en")
}
Those queries will produce the name of the country, but it wanted the corresponding demonym, you can get the dbpedia-owl:demonym
value of the country, if it's available. It's probably best to make the demonym optional, since a cursory investigation suggests that lots of countries in DBpedia don't have a value for it, so the name of the country may be the only option. E.g.,
select ?name ?demonym {
dbpedia:Henrik_Ibsen dbpedia-owl:birthPlace ?country .
?country a dbpedia-owl:Country ; rdfs:label ?name .
optional { ?country dbpedia-owl:demonym ?demonym }
filter langMatches(lang(?name),"en")
filter langMatches(lang(?demonym),"en")
}
Upvotes: 3
Reputation: 21810
Two things are wrong with the query:
dbprop:nationality
value is a literal, which cannot be used as a subject resource, therefore, there will never be a label for dbpprop:nationality
. Instead, where the data exists, you would use dbpedia-owl:nationality
, which you did originally. it just so happens that Henrik_Ibsen has no dbpedia-owl:nationality
value associated with him*Updated query (updated).
SELECT
#### ?label #### See Edit
?nationality
WHERE {
dbpedia:Henrik_Ibsen dbpprop:nationality ?nationality .
#### OPTIONAL { ?nationality rdfs:label ?label . } #### See Edit.
}
Upvotes: 1