Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I convert a Freebase query to a Wikidata query?

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.

like image 675
miguel Avatar asked Jan 31 '15 17:01

miguel


1 Answers

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.

like image 93
StasM Avatar answered Oct 11 '22 13:10

StasM