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
445 views
in Technique[技术] by (71.8m points)

sparql - Retrieving data from blank nodes in Wikidata

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?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

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.

Wikidata data model

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!


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

1.4m articles

1.4m replys

5 comments

57.0k users

...