Question

I try to get some data about a city using Sparql query on DBpedia. The problem is I can't get the query to work.

Currently I do something like this:

SELECT ?title,?name,?abs WHERE {
  ?title skos:subject 
    <http://dbpedia.org/resource/Category:Cities%2C_towns_and_villages_in_Slovenia>.
  ?title dbpprop:officialName ?name.
  ?title dbpprop:abstract ?abs 
}

I get all the towns, villages from Slovenia with all the data. The problem is, I would like to get the data (officialName and/or abstract) only for one town, for example Ljubljana. So I tried some things like this:

SELECT ?name WHERE {
  ?name dbpprop:officialName 
    <http://dbpedia.org/resource/Ljubljana>.
}

Of course it does not work. I don't exactly know why, though :), but I've been experimenting a bit and noticed some things like if I put

?name skos:subject <http://dbpedia.org/resource/Category:Ljubljana>.

I get some results (which are not relevant to me, but anyway), but if I put

?name skos:subject <http://dbpedia.org/resource/Ljubljana>.

there are no results for anything though element skos:subject exists on the page http://dbpedia.org/resource/Ljubljana.

Could someone please explain why the second example does not work and how to get the result I would like to have?

Thanks, Ablak

Thanks

Was it helpful?

Solution

You want to query for <http://dbpedia.org/resource/Ljubljana> as a subject, not an object; this would replace your ?title binding in the SPARQL query, for example:

SELECT ?name, ?abs WHERE {
   <http://dbpedia.org/resource/Ljubljana>
     skos:subject <http://dbpedia.org/resource/Category:Cities%2C_towns_and_villages_in_Slovenia> ;
     dbpprop:officialName ?name ;
     dbpprop:abstract ?abs .
}

This is why your graph match ?name skos:subject <http://dbpedia.org/resource/Ljubljana> does not return the expected results; the URI for Ljubljana should be the subject of the statement(s) you want to match.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top