sparqlwikidata

Sparql query to match unique item identifier from wikidata


I'm trying to get properties value for a given wikidita item from the identifier unique identifier (e.g. wd:Q200639).

Let's say I want Paul Valéry's birth date (https://www.wikidata.org/wiki/Q200639). Is it possible to write a query like this one ?

SELECT ?birth
WHERE {
  wd:Q200639 <property i'm looking for> ?person.
  ?person wdt:P569 ?birth .
}

I can't manage to find a property that could do this in the docs. I guess my approach isn't the right one, any hint to help ?


Solution

  • If you know the subject (wd:Q200639) and the property (wdt:P569), you can include both in the triple pattern, and use a variable only for the value you want to find out (i.e., the birthdate):

    wd:Q200639 wdt:P569 ?birthdate .
    

    If you want to query multiple properties, instead of repeating the subject, you can use a semicolon (;):

    wd:Q200639 wdt:P569 ?birthdate ;
               wdt:P570 ?deathdate .
    

    If, for example, having a deathdate is optional, this is not possible, though. You would have to repeat the subject inside OPTIONAL {}:

    wd:Q200639 wdt:P569 ?birthdate .
    OPTIONAL { wd:Q200639 wdt:P570 ?deathdate . }
    

    To avoid having to repeat the subject IRI, you can use BIND or VALUES to replace it with a variable:

    # with BIND, you can only have one value
    BIND( wd:Q200639 AS ?person ) .
    
    ?person wdt:P569 ?birthdate .
    OPTIONAL { ?person wdt:P570 ?deathdate . }
    
    # with VALUES, you can have multiple, space-separated values
    VALUES ?person { wd:Q200639 }
    
    ?person wdt:P569 ?birthdate .
    OPTIONAL { ?person wdt:P570 ?deathdate . }