0

I'm trying to understand how to select one publication date from a list of place of publications from wikidata using SPARQL. I have a query that I think is close but I'm looking for some help in narrowing it down. What I have so far is the following:

SELECT ?item ?itemLabel ?publication_date WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  VALUES (?item) {(wd:Q18486021)}

  {SELECT ?item ?publication_date WHERE {
     ?item p:P577 ?publication_date_entry.
     ?publication_date_entry pq:P291 wd:Q30.
     ?item wdt:P577 ?publication_date.
  }}
}

I'm attempting to get the publication date for the release matching the US from https://www.wikidata.org/wiki/Q18486021 (Star Wars: The Last Jedi). If you scroll down to the publication date section you'll notice that there are 5 releases. I want to select the date for the US release (15 December 2017). It happens to be first, but I want to generalize this so that I can pull out the US release date for any film. From here I want to generalize this to matching the US release date for all films.

I think what I'm doing above is a sub query that attempts to match the US release date but it results in one row for each release (5 total).

Damon Snyder
  • 1,362
  • 1
  • 11
  • 18
  • 1
    `SELECT ?item ?itemLabel ?publication_date WHERE { SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } VALUES (?item) {(wd:Q18486021)} ?item p:P577 ?publication_date_entry. ?publication_date_entry ps:P577 ?publication_date. ?publication_date_entry pq:P291 wd:Q30. }` – UninformedUser Dec 21 '18 at 05:31
  • your main issue was that although you used the qualifier statement you still tried to get the value of the publication date "normally" instead of getting it from the statement. The general rule is `p:Pxxx` in combination with `ps:Pxxx` gets the same value as `wdt:Pxxx` would do plus that you can get the other statement qualifiers via `pq:Pyyy`. A good overview can be found [here](https://en.wikibooks.org/wiki/SPARQL/WIKIDATA_Qualifiers,_References_and_Ranks) – UninformedUser Dec 21 '18 at 05:35
  • Thank you @AKSW. I provided an answer below using your suggestion. I ended up using `OPTIONAL` because some of the entities had more than one US release date. – Damon Snyder Dec 26 '18 at 20:55

1 Answers1

0

With @AKSW's help I ended up with the following. I used an OPTIONAL, GROUP BY and GROUP_CONCAT because there were some films that had more than one US release date.

SELECT ?item ?itemLabel 
       (GROUP_CONCAT(DISTINCT ?publication_date;separator=',') as ?publication_date)
  WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  VALUES (?item) {(wd:Q23780734) (wd:Q18486021) (wd:Q23780914) (wd:Q22000542)}
  ?item wdt:P31 wd:Q11424;


  OPTIONAL {
     ?item p:P577 ?publication_date_entry.
     ?publication_date_entry ps:P577 ?publication_date. # publication date statement
     ?publication_date_entry pq:P291 wd:Q30.            # qualifier on the release date
  }

  FILTER(xsd:date(?publication_date) > "2017-01-01"^^xsd:date)
}
GROUP BY ?item ?itemLabel
LIMIT 10
Damon Snyder
  • 1,362
  • 1
  • 11
  • 18