Retrieving data from blank nodes in Wikidata
Asked Answered
U

1

3

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?

Unguent answered 13/9, 2017 at 11:51 Comment(0)
C
5

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!

Chalybite answered 13/9, 2017 at 12:6 Comment(4)
I feel stupid, but I can't spot it right away: It does work, but what does your query do different? The FILTER and VALUES seems to only restrict it more.Unguent
Look carefully :). I'll explain in a few minutes, now I'm looking for good links.Chalybite
Ah, you are using different prefixes for P569 and P1319, I would be glad to have some good links for that!Unguent
Wow, thanks for updating your answer so thoroughly, this really helps!Unguent

© 2022 - 2024 — McMap. All rights reserved.