1
votes

I am new to SPARQL and Wikidata, and am trying to retrieve the following for the Hugo Award Winners:

  • Work Title
  • Author
  • Year Won

I'm finding this surprisingly difficult.

I started off querying for all tuples linking to the award for best novel with a link type of "won by".

SELECT DISTINCT ?winner WHERE {
  # P166: Award Recieved By
  # Q103360: Hugo Award for Best Novel
  ?winner ps:P1346 wd:Q255032.

  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

This works, but when I add the title link from the winner, there's no data:

SELECT DISTINCT ?winner WHERE {
  ?winner ps:P1346 wd:Q255032.

  OPTIONAL {
    # P1476: Title
    ?winner wdt:P1476 ?title.
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

What am I doing wrong? I've tried different namespaces, with little comprehension, and to no avail.

On the page for the Hugo winners, there's a section of winners: https://www.wikidata.org/wiki/Q255032#P1346

How is that generated? I tried to query that property and got back links to people (I think):

SELECT DISTINCT ?winner ?winnerLabel ?for WHERE {
  # P166: winner
  # Q103360: Hugo Award for Best Novel
  wd:Q255032 wdt:P1346 ?winner.

  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
1
Your first query does not return anything! At least not for me right now when I tried it on query.wikidata.org. So why are you not using wdt:P166 as predicate? - UninformedUser
And the second query also works when you use the predicate wdt:P166. But, to get the fields back have to have to add them to the SELECT part of course, i.e. SELECT DISTINCT ?winner ?winnerLabel ?titleLabel - UninformedUser

1 Answers

2
votes

For predicate you should use wdt: instead ps:

Please look at this example:

SELECT DISTINCT ?item ?itemLabel ?AuthorLabel ?year WHERE {  
  ?item wdt:P166 wd:Q255032.
  ?item wdt:P50 ?Author .  
  ?item wdt:P577 ?year .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }    
} 

PS. I used publication, not winning date.

UPDATE: Please see this answer:

The point in time property of the award received is what Wikidata calls a qualifier.

And this is query:

SELECT ?item ?itemLabel ?authorLabel ?publicationDate ?dateOfAwardReceived WHERE {
  ?item wdt:P50 ?author .  
  ?item wdt:P577 ?publicationDate .
  ?item p:P166 ?awardReceivedStatement .
  ?awardReceivedStatement ps:P166 wd:Q255032 .
  ?awardReceivedStatement pq:P585 ?dateOfAwardReceived .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }    
}