简体   繁体   English

如何使用sparql查询进入dbpedia中的特定页面?

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

I have a URI for a person, eg, http://dbpedia.org/resource/Ashok_Gehlot (which, when retrieved via HTTP, redirects to http://dbpedia.org/page/Ashok_Gehlot ). 我有一个人的URI,例如http://dbpedia.org/resource/Ashok_Gehlot (通过HTTP检索时,它会重定向到http://dbpedia.org/page/Ashok_Gehlot )。 I want to extract information about this resource. 我想提取有关此资源的信息。 How could I write a SPARQL query to retrieve, eg, Ashok Gehlot's birthdate? 我如何编写SPARQL查询来检索例如Ashok Gehlot的生日? 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.
}

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> . 在这种情况下,资源为<http://dbpedia.org/resource/Ashok_Gehlot> RDF is a graph based data representation, and a SPARQL query is a graph based query language. RDF是基于图的数据表示形式,而SPARQL查询是基于图的查询语言。 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 . 您正在寻找源为<http://dbpedia.org/resource/Ashok_Gehlot>的图的边缘,其边缘标签为owl:birthdate (这没有道理,但这是一个不同的问题),并且您想要检索边缘的另一端并将其值绑定到变量?z Thus, your query would be: 因此,您的查询将是:

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

SPARQL results SPARQL结果

Of course, that query has no results, because the resource has no property owl:birthdate . 当然,该查询没有结果,因为该资源没有属性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) dbpedia-owl:birthDate 1951-05-03(xsd:date)
  • dbpprop:birthDate 3 (xsd:integer) dbpprop:birthDate 3(xsd:integer)
  • dbpprop:dateOfBirth 1951 (xsd:integer) dbpprop:dateOfBirth 1951(xsd:integer)

The dbpedia-owl data is much cleaner than the dbpprop data, so you should use it. dbpedia-owl数据比dbpprop数据干净得多,因此您应该使用它。 Also noting that the prefix dbpedia: abbreviates <http://dbpedia.org/resource/> , your query should be: 还注意到前缀dbpedia:缩写<http://dbpedia.org/resource/> ,您的查询应为:

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

SPARQL results SPARQL结果

--------------
| 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 模式?x owl:sameAs? dbpedia:Ashok_Gehlot ?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 . ?x owl:sameAs? dbpedia:Ashok_Gehlot意味着属性owl:sameAs?x绑定到距离dbpedia:Ashok_Gehlot为零或一步的owl:sameAs For the zero step case, ?x is just dbpedia:Ashok_Gehlot , which is what you want. 对于零步的情况, ?x只是dbpedia:Ashok_Gehlot ,这就是您想要的。 For the one case, ?x will be anything that is owl:sameAs dbpedia:Ashok_Gehlot , which should also be OK. 在一种情况下, ?x可以是owl:sameAs dbpedia:Ashok_Gehlot ,也可以。

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

SPARQL results SPARQL结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM