4

Visitng http://dbpedia.org/resource/Cupertino shows the DBpedia RDF information about Cupertino. As you can see, it has, among others, the property and value:

dbpedia-owl:type  dbpedia:City

However, this query on the DBpedia endpoint returns no results:

SELECT ?type  WHERE {
  dbpedia:Cupertino  dbpedia-owl:type ?type
}

SPARQL results

Why can't I retrieve the value of the dbpedia-owl:type property?

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
SuperUser01
  • 199
  • 1
  • 13
  • http://dbpedia.org/ontology/type thats the kind of type property whith which "City" is assigned to "Cupertino", so I should be using the correct property URI... or not? – SuperUser01 May 26 '14 at 13:28

1 Answers1

3

You've got an interactive webservice in front of you, and one of the most useful things that you can do is generalize your query into one that should return a superset of the results you're looking for, as a sort of sanity check. In this case, it's useful to see what happens if you ask for all properties and values of dbpedia:Cupertino.

select ?p ?o where {
  dbpedia:Cupertino ?p ?o 
}

SPARQL results

p                                               o
http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://www.w3.org/2002/07/owl#Thing
http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://dbpedia.org/ontology/Place
http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://dbpedia.org/ontology/PopulatedPlace
http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://dbpedia.org/ontology/Settlement
http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://schema.org/Place
http://dbpedia.org/ontology/wikiPageID          337802
http://dbpedia.org/ontology/wikiPageRevisionID  16202923
http://www.w3.org/2000/01/rdf-schema#label      "Cupertino"@en
http://dbpedia.org/ontology/wikiPageRedirects   http://dbpedia.org/resource/Cupertino,_California
http://xmlns.com/foaf/0.1/isPrimaryTopicOf      http://en.wikipedia.org/wiki/Cupertino
http://www.w3.org/ns/prov#wasDerivedFrom        http://en.wikipedia.org/wiki/Cupertino?oldid=16202923

In this case, that dbpedia-owl:wikiPageRedirects is very important. When you type in dbpedia:Cupertino or the full URI, http://dbpedia.org/resource/Cupertino, into a web browser, look carefully at where you end up. You end up at http://dbpedia.org/page/Cupertino,_California, which means that the resource you're actually asking about is http://dbpedia.org/resource/Cupertino,_California (when you retrieve them in a browser, you're redirected from /resource/ to /page/, but the naming convention is still the same.

To use dbpedia:Cupertino in a query, you'd need to add the redirect information. Thus, you could use the following query to get the results that you're looking for:

select ?type where {
  dbpedia:Cupertino dbpedia-owl:wikiPageRedirects*/dbpedia-owl:type ?type
}

SPARQL results

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
  • Thanks, I noticed the redirect too in the browser URL, but I had no idea there was a property for that! Are there diferent 'kinds' of redirects? Like 'dbpedia-ontology:wikiPagesRedirects' and other variatons? – SuperUser01 May 26 '14 at 19:34
  • select ?type where { http://dbpedia.org/resource/Cupertino http://dbpedia.org/ontology/wikiPageRedirects*/http://dbpedia.org/ontology/type ?type } Do you know why this query won't work then? – SuperUser01 May 26 '14 at 20:02
  • Code is next to unreadable in comments, and URI formatting is particularly problematic. Isn't that the same as the last query that I included in my answer? At any rate, `select ?type where { */ ?type } ` works just fine. – Joshua Taylor May 26 '14 at 20:47
  • It is the same indeed. Yes it's unreadable, but I thought answering my own question was 'bad style' too. Anyway, thanks a lot for your help, thats exactly what I needed - I was missing the "<>". – SuperUser01 May 26 '14 at 21:17
  • I'm surprised that you didn't get a parse error if you were missing some brackets! – Joshua Taylor May 26 '14 at 21:18
  • The brackets are missing due to the auto-formatting of the comments on SO. – SuperUser01 Jun 01 '14 at 14:41
  • @user3641140 That doesn't surprise me, but it highlights why you should use backticks (`\``) around code and code-like text. You can write `select ?type where { <…> … }`. – Joshua Taylor Jun 01 '14 at 17:01