Search code examples
sparqlwikidata

Accessing the properties of an item contained in the value of a parent item


Is it possible to access values of an item which exists in the property of another item. For example in the case of the Matterhorn. There is a property 'significant event' P793. This property's value is the item 'first ascent' Q1194369 which has the properties 'point in time' P585 and 'participant' P710.

Significant event property

I would like to be able to be able to return these values for the mountain but I do not know how to access the values using SPARQL. I have tried defining 'first ascent' as a parameter but it does not yield any results. I have also tried examining all of the available properties of the 'first ascent' but I cannot see where these values are stored. The code I have tried is:

 SELECT ?mountainLabel ?date ?climbers 
WHERE 
{
  ?mountain wdt:P31 wd:Q8502. # instance of mountain
  ?mountain wdt:P17 wd:Q39.  # country Switzerland
  ?mountain wdt:P935 "Matterhorn". # name
  ?mountain wdt:P793/wd:Q1194369* ?firstAss. # first ascent

  ?firstAss wdt:P585 ?date . #date of ascent 
  ?firstAss wdt:P710 ?climbers . #climbername 

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en, de". }
}

Solution

  • The statement qualifiers are not trivial the first times...

    Solution :

    PREFIX bd: <http://www.bigdata.com/rdf#> 
    PREFIX p: <http://www.wikidata.org/prop/> 
    PREFIX pq: <http://www.wikidata.org/prop/qualifier/> 
    PREFIX ps: <http://www.wikidata.org/prop/statement/> 
    PREFIX wd: <http://www.wikidata.org/entity/> 
    PREFIX wdt: <http://www.wikidata.org/prop/direct/> 
    PREFIX wikibase: <http://wikiba.se/ontology#> 
    
    
    SELECT ?mountainLabel ?firstAssLabel ?date ?climberLabel 
        WHERE 
        {
          ?mountain wdt:P31 wd:Q8502. # instance of mountain
          ?mountain wdt:P17 wd:Q39.  # country Switzerland
          ?mountain wdt:P935 "Matterhorn". # name
          ?mountain wdt:P793/wd:Q1194369* ?firstAss. # first ascent
    
          ?mountain p:P793 ?firstAssStat .
          ?firstAssStat ps:P793 ?firstAss .
           ?firstAssStat pq:P585 ?date . #date of ascent 
           ?firstAssStat pq:P710 ?climber . #climbername 
    
          SERVICE wikibase:label {
               bd:serviceParam wikibase:language "en,de" .
          }
    } 
    

    Demo : http://linkedwiki.com/query/Climbers_of_first_ascents

    Docs : https://www.wikidata.org/wiki/Wikidata:SPARQL_tutorial#Qualifiers

    Personally, I observe the RDF/Turtle of a item to build my query : https://www.wikidata.org/wiki/Special:EntityData/Q1374.ttl