Retrieving data from blank nodes in Wikidata

放肆的年华 提交于 2019-11-27 08:25:10

问题


I am attempting to retrieve data about the lifespans of certain people. This is problematic in cases of people that have lived a while ago. The dataset for e.g. Pythagoras seems to have a so called "blank node" for date of birth (P569). But this blank node references another node earliest date (P1319) which has data I could work with just fine.

But for some reason I am not able to retrieve that node. My first try looked like this, but somehow that results in a completly empty result set:

SELECT DISTINCT ?person ?name ?dateofbirth ?earliestdateofbirth WHERE {
  ?person wdt:P31 wd:Q5.         # This thing is Human
  ?person rdfs:label ?name.      # Name for better conformation
  ?person wdt:P569 ?dateofbirth. # Birthday may result in a blank node
  ?dateofbirth wdt:P1319 ?earliestdateofbirth # Problem: Plausbible Birth
}

I then found another Syntax that suggested using ?person wdt:P569/wdt:P1319 ?earliestdateofbirth as some kind of "shortcut"-syntax for the explicit navigation I did above but this also ends with a empty result set.

SELECT DISTINCT ?person ?name ?dateofbirth ?earliestdateofbirth WHERE {
  ?person wdt:P31 wd:Q5.         # Is Human
  ?person rdfs:label ?name.      # Name for better conformation
  ?person wdt:P569/wdt:P1319 ?earliestdateofbirth. 
}

So how do I access a node referenced by a blank node (in my case specifically the earliest birthdate) in Wikidata?


回答1:


But this blank node references another node…

Things are slightly different. The earliest date property is not a property of _:t550690019, but rather is a property of the statement wd:Q10261 wdt:P569 _:t550690019.

In the Wikidata data model, these annotations are expressed using qualifiers.

Your query should be:

SELECT DISTINCT ?person ?name ?dateofbirth ?earliestdateofbirth WHERE {
  VALUES (?person) {(wd:Q10261)}
  ?person wdt:P31 wd:Q5.         # --Is human
  ?person rdfs:label ?name.      # --Name for better conformation
  ?person p:P569/pq:P1319 ?earliestdateofbirth. 
  FILTER (lang(?name) = "en")
}

Try it!


By the way, time precision (which is used when date of birth is known) is yet another qualifier:

SELECT ?person ?personLabel ?value ?precisionLabel {
  VALUES (?person) {(wd:Q859) (wd:Q9235)}
  ?person  wdt:P31  wd:Q5 ;
           p:P569/psv:P569  [ wikibase:timeValue  ?value ;
                              wikibase:timePrecision  ?precisionInteger ]
  {
  SELECT ?precision (xsd:integer(?precisionDecimal) AS ?precisionInteger) {
    ?precision  wdt:P2803  ?precisionDecimal .
  }
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

Try it!



来源:https://stackoverflow.com/questions/46196832/retrieving-data-from-blank-nodes-in-wikidata

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!