Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using qualifiers in Wikidata-SPARQL

I'm new to SPARQL/Wikidata and trying to figure out how I ask for the time Angelina Jolie started dating each of her spouse.

I see the information in Jolie's Wikidata entry but I don't manage to form a valid query to obtain it. I guess it has something to do with those "qualifiers" I don't fully understand.

This is what I already tried:

PREFIX p: <http://www.wikidata.org/prop/>
PREFIX v: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
SELECT ?x ?xLabel ?start
WHERE { wd:Q13909 p:P26 ?x . ?x v:P26 wd:Q13909 . ?x pq:P580 ?start . }

I know it is wrong.. I just don't know how to fix it.. I want to express the desire to know attributes of a specific previous predicate

Thank you for your help!

p.s: The answer for my query should be: Jonny Lee Miller 1995 Billy Bob Thornton March 2000 Brad Pitt 23 August 2014

like image 289
Ori Mosenzon Avatar asked Mar 22 '16 15:03

Ori Mosenzon


1 Answers

Finally, I manged to figure out what's going on. In wikidata, any predicate that has some attributes, is actually a new entity (node) that is called a statement. The attributes are also entities (nodes) that are linked to this new node. These attributes are called qualifiers.

So, eventually, this query did the job for me:

SELECT ?sp ?t WHERE {
    wd:Q13909  p:P26   ?s  .  # ?s is the the statement node
           ?s  ps:P26  ?sp .  # that simulates the predicate 
           ?s  pq:P580 ?t  .  # this is an attribute (a qualifier) 
 }
like image 139
Ori Mosenzon Avatar answered Jan 01 '23 08:01

Ori Mosenzon