views:

611

answers:

1

Hello,

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&gt;.
  ?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&gt;.
}

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&gt;.

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

?name skos:subject <http://dbpedia.org/resource/Ljubljana&gt;.

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

+1  A: 

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

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

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

Phil M
Thank you, I get it now!
Armen Ablak
How did you run this query. I try to run it with sparql.bat which comes with ARQ but it returns an error.
Jenea