Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
436 views
in Technique[技术] by (71.8m points)

rdf - Retrieving dbpedia-owl:type value of resource with dbpedia-owl:wikiPageRedirect value?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...