Question

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.

Was it helpful?

Solution

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 ]
}

SPARQL results

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")
}

SPARQL results

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")
}

SPARQL results

OTHER TIPS

Two things are wrong with the query:

  1. It's dbpprop:nationality
  2. The label doesn't appear to exist, and unless you make that variable optional, it will eliminate the row altogether. EDIT: *Joshua Taylor's answer reminded me that the label doesn't exist because the 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.
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top