Tim de Bruyn
Tim de Bruyn

Reputation: 23

Retrieving label names with SPARQL query

I am having an issue with the Wikidata Query Service. https://query.wikidata.org/ What I want to do is retrieve a list of all persons who have a GTAA ID.

?q wdt:P1741 ?GTAA_ID.

For these persons, I want to retrieve the following optional information:

OPTIONAL{ ?q p:P166 ?award_received
OPTIONAL{ ?award_received pq:P585 ?point_in_time. }
OPTIONAL{ ?award_received pq:P1686 ?for_work.   }

As of now, my query mostly works. However, in the 'awards_received' column, for example, it is showing the following text:

wds:Q76343-ffa729dc-4d10-eb15-3a41-5fa6bf7ed80a

When clicking this it brings me to the Wikidata page concerning the person who received the award, NOT the title of the award itself. What I would like to do is have the title of the received award retrieved, instead of a link to the receiver of the title.

The code I have is as follows:

SELECT ?GTAA_ID ?award_received ?point_in_time ?for_workLabel
   WHERE
   {
       ?q wdt:P1741 ?GTAA_ID.
       OPTIONAL{ ?q p:P166 ?award_received
       OPTIONAL{ ?award_received pq:P585 ?point_in_time. }
       OPTIONAL{ ?award_received pq:P1686 ?for_work.   }
       . }
       SERVICE wikibase:label { bd:serviceParam wikibase:language "     
       [AUTO_LANGUAGE]". }
   }

Upvotes: 2

Views: 505

Answers (1)

evsheino
evsheino

Reputation: 2277

The actual award is given as the property ps:P166 of the statement:

SELECT ?GTAA_ID ?award ?awardLabel ?point_in_time ?for_workLabel {
  ?q wdt:P1741 ?GTAA_ID.
  OPTIONAL {
    ?q p:P166 ?award_received .
    ?award_received ps:P166 ?award # Here
    OPTIONAL { ?award_received pq:P585 ?point_in_time. }
    OPTIONAL { ?award_received pq:P1686 ?for_work. }
  }
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE]".
  }
}

You can get a description of a resource with a DESCRIBE query, e.g.:

DESCRIBE wds:Q78217-3877ABD6-239F-47DA-A8BD-8035D3CBAA7A

Upvotes: 4

Related Questions