Using qualifiers in Wikidata-SPARQL
Asked Answered
Z

1

9

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

Zygapophysis answered 22/3, 2016 at 15:32 Comment(1)
I see you know the answer, however some explanation: #46197332Sair
Z
14

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) 
 }
Zygapophysis answered 24/3, 2016 at 7:33 Comment(2)
Note that you don't need to define your own PREFIX as the Wikidata query service already defines PREFIX ps: <http://www.wikidata.org/prop/statement/>.Generalship
For people coming here from google: this is explained in Wikibooks' reference on SPARQL, plus that page shows the short syntax to get qualifier values.Crelin

© 2022 - 2024 — McMap. All rights reserved.