Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get to a particular page in dbpedia using sparql query?

I have a URI for a person, e.g., http://dbpedia.org/resource/Ashok_Gehlot (which, when retrieved via HTTP, redirects to http://dbpedia.org/page/Ashok_Gehlot). I want to extract information about this resource. How could I write a SPARQL query to retrieve, e.g., Ashok Gehlot's birthdate? In the following query (my attempt so far) what would I need to replace ???? with?

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbpedia: <http://dbpedia.org/resource/>PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>PREFIX category: <http://dbpedia.org/resource/Category:>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>PREFIX foaf: <http://xmlns.com/foaf/0.1/>PREFIX dbpprop: <http://dbpedia.org/property/>
PREFIX dbprop: <http://dbpedia.org/property/>PREFIX grs: <http://www.georss.org/georss/>
PREFIX category: <http://dbpedia.org/resource/Category:>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX freebase: <http://rdf.freebase.com/ns/>
PREFIX db: <http://dbpedia.org/>
PREFIX dbp: <http://dbpedia.org/property/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX http: <http://www.w3.org/2006/http#>
SELECT ?x ?y WHERE {
  ?x ?????? http://dbpedia.org/resource/Ashok_Gehlot.
  ?x owl:birthdate ?z.
}
like image 986
RamPrasadBismil Avatar asked Dec 20 '22 21:12

RamPrasadBismil


1 Answers

You don't want properties of a page, you want propreties of aresource. In this case, the resource is <http://dbpedia.org/resource/Ashok_Gehlot>. RDF is a graph based data representation, and a SPARQL query is a graph based query language. You're looking for an edge of the graph whose source is <http://dbpedia.org/resource/Ashok_Gehlot>, whose edge label is owl:birthdate (which doesn't make sense, but that's a different issue), and you want to retrieve the other end of the edge and bind its value to the variable ?z. Thus, your query would be:

select ?z where { 
  <http://dbpedia.org/resource/Ashok_Gehlot> owl:birthdate ?z
}

SPARQL results

Of course, that query has no results, because the resource has no property owl:birthdate. If you browse the data that you see at Ashok Gehlot, you'll notice that there are:

  • dbpedia-owl:birthDate 1951-05-03 (xsd:date)
  • dbpprop:birthDate 3 (xsd:integer)
  • dbpprop:dateOfBirth 1951 (xsd:integer)

The dbpedia-owl data is much cleaner than the dbpprop data, so you should use it. Also noting that the prefix dbpedia: abbreviates <http://dbpedia.org/resource/>, your query should be:

select ?birthDate where { 
  dbpedia:Ashok_Gehlot dbpedia-owl:birthDate ?birthDate
}

SPARQL results

--------------
| birthDate  |
|============|
| 1951-05-03 |
--------------

If, for some reason, it really is important to have a query that's more in the shape of your original attempt, you could use the following. The pattern ?x owl:sameAs? dbpedia:Ashok_Gehlot means that ?x will be bound to things that are zero or one step away from dbpedia:Ashok_Gehlot by the property owl:sameAs. For the zero step case, ?x is just dbpedia:Ashok_Gehlot, which is what you want. For the one case, ?x will be anything that is owl:sameAs dbpedia:Ashok_Gehlot, which should also be OK.

select ?birthDate where { 
  ?x owl:sameAs? dbpedia:Ashok_Gehlot .
  ?x dbpedia-owl:birthDate ?birthDate .
}

SPARQL results

like image 184
Joshua Taylor Avatar answered Dec 27 '22 02:12

Joshua Taylor