9

Using this Freebase query as an example, how can I run the same query using the Wikidata api?

[{
  "id": null,
  "name": null,
  "type": "/film/film",
  "/film/film/directed_by": "Steven Spielberg",
  "/film/film/genre": "Drama",
  "/film/film/story_by": [],
  "starring": [{
    "actor": [{
      "name": "Tom Hanks",
      "key": [{
        "namespace": "/authority/imdb/name",
        "value": null
      }]
    }]
  }],
  "/film/film/initial_release_date>": "2000",
  "/film/film/initial_release_date<": "2003"
}]

Thank you.

Termininja
  • 5,689
  • 12
  • 40
  • 45
miguel
  • 321
  • 1
  • 3
  • 9

2 Answers2

1

You can not do it with the Wikidata API, however you can do it with Wikidata Query Service. Here's an example query:

PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
SELECT ?film ?filmLabel ?date WHERE {
# Is a film  
  ?film wdt:P31 wd:Q11424 .
# Director is Steven Spielberg
  ?film wdt:P57 wd:Q8877 .
# genre is drama film  
#  ?film wdt:P136 wd:Q130232 .
#  Starring Tom Hanks
  ?film wdt:P161 wd:Q2263 .
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
  }
# published on date
  ?film wdt:P577 ?date .
  FILTER(year(?date)>2000 && year(?date)<2003)
} 

You can try it here. Note that I commented out the genre check. This is because Wikidata does not have any films with your criteria and genre "drama", but does have one film which is published at given date and is filmed by Spielberg and includes Tom Hanks:

wd:Q208108* Catch Me If You Can 2002-01-01T00:00:00Z

You can find more links to documentation at the service home page and user manual, and also Query Service community pages.

StasM
  • 9,840
  • 5
  • 49
  • 96
0

As far as I know, it is not possible to create such a detail query against Wikipedia-API. But you can search Wikipedia pages by title, content, id, category, time created and many others criteria.

For basic examples, see MediaWiki API overview:

https://www.mediawiki.org/wiki/API:Main_page

Also, see complete MediaWiki API documentation:

https://www.mediawiki.org/w/api.php

Also, you can retrieve basic info about movies from article's infoBox (see this and this Q&A).

Community
  • 1
  • 1
Damjan Pavlica
  • 21,431
  • 6
  • 55
  • 65