Jeroen Vuurens
Jeroen Vuurens

Reputation: 1251

Retrieve the US release date for a movie from Wikidata using Sparql

I am trying to retrieve the titles and release dates (publication date) for movies using the wikidata.org sparkql endpoint (https://query.wikidata.org/). The titles are listed in different languages, which are filtered in the query below. However, some movies also have several publication dates (e.g. for different countries), e.g. https://www.wikidata.org/wiki/Q217020. I'm not sure how the RDF triple structure is actually used to assign a country to the value of another triple, but specifically, how can I only retrieve the publication date for a movie in the US?

SELECT ?item ?title ?publicationdate
WHERE { 
    ?item wdt:P31 wd:Q11424 ;
        rdfs:label ?title ;
        wdt:P577 ?publicationdate ;
    filter ( lang(?title) = "en" )
}
ORDER BY ?movieid
LIMIT 10

Solution

The solution provided by M.Sarmini works. Apparently, facts such as publication data are stored as n-ary relations, they create a unique symbolic tag that links the resources. The value that P577 links to is just the date, when turned into a string will give the release date, while in reality it is a token that you can link to other qualifiers.

Upvotes: 0

Views: 365

Answers (1)

M.Sarmini
M.Sarmini

Reputation: 70

Just add a new variable to hold the place of publication and filter your results to just list US films like this:

PREFIX q: <http://www.wikidata.org/prop/qualifier/>
PREFIX s: <http://www.wikidata.org/prop/statement/>

SELECT distinct ?item  ?title ?publicationdate
WHERE { 
  ?item wdt:P31 wd:Q11424;
        rdfs:label ?title;             
        p:P577 ?placeofpublication.
  ?placeofpublication q:P291 wd:Q30.   
  ?placeofpublication s:P577 ?publicationdate;

  filter ( lang(?title) = "en")
}  
ORDER BY ?item

Upvotes: 1

Related Questions