4

I am using the youtube API to retrieve the freebase topic details of particular videos. Since freebase is closing down how do I use wikidata to query for a specific topic id?

For example the following topic id /m/0181lj should give the following information

/m/0181lj

I have tried playing with the wikidata REST API but I haven't found a request which matches what I need.

Update

Freebase have released the Knowledge graph which allows you to query via topicId as so

https://kgsearch.googleapis.com/v1/entities:search?ids=/m/0181lj&key=API_KEY&limit=5&indent=True

However, some ids don't seem to be returning data e.g. the following music genres /m/05fqyx, /m/02w1p3

As an alternative freebase can be downloaded, but I haven't tried that just yet!

Termininja
  • 6,620
  • 12
  • 48
  • 49
david_adler
  • 9,690
  • 6
  • 57
  • 97
  • Thanks the update is helpful! BTW For anyone looking, you can get an API key here: https://console.developers.google.com/apis/api/kgsearch.googleapis.com/overview – Justin Harris May 12 '16 at 23:00

2 Answers2

5

There isn't a Wikidata equivalent to the Freebase Suggest, Search, or Topic APIs.

They've got a beta SPARQL endpoint that you could use to (painfully) roll your own replacement for Freebase Topic (details below), but if you don't have an immediate need to migrate, you might consider waiting until the new, promised, Knowledge Graph equivalents are available. Google has promised a 3 month transition period after the availability of the new APIs before they shut down Freebase. (But you need to decide how willing you are to trust them.)

The other advantage to delaying the transition is that it gives the Wikidata folks more time to get their act together and build some usable APIs. Of course, you need to be able to live with the fact that Freebase is read-only.

If you want to roll your own Wikidata query for Freebase IDs, you can use the following query as a starting point:

PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>

SELECT  ?s ?sLabel ?p ?o ?oLabel WHERE {
 ?s ?p ?o .
 ?s wdt:P646 "/m/0181lj" .

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

TinyURL to query editor http://tinyurl.com/otdc78s

You can get back JSON results by sending the query to the API endpoint with this base URL https://query.wikidata.org/bigdata/namespace/wdq/sparql?format=json&query= followed by your URL encoded query

TinyURL to API call http://tinyurl.com/nfcp2rh

Tom Morris
  • 10,490
  • 32
  • 53
  • Awesome, thanks. Do you know per chance when freebase will be going totally offline? I know it is now read only but couldn't find anything about it being totally shutdown... – david_adler Nov 12 '15 at 22:38
  • 1
    June 30, 2015 or three months after they release the new APIs (which are now something like 6 months late) whichever is later. Which reminds me, the new APIs are another alternative. KG Search / KG Suggest (or whatever they call them) will likely be drop-in replacements for their Freebase equivalents. I'll edit my answer. – Tom Morris Nov 12 '15 at 23:03
  • 1
    Yup, it's documented here: https://developers.google.com/knowledge-graph/ but I don't think they'll start the 3 month clock until the Knowledge Graph Suggest widget is available as well, since those are the two APIs they promised. *THINK* being the operative word -- that's just a guess. – Tom Morris Dec 21 '15 at 23:22
0

Both Wikidata and Google Knowledge Graph do not contain all Freebase entries, so its not clear if there will be a full replacement solution.

Freebase includes many entries that Wikipedia does not, for example, it contains automatically created entries for a large corpus of creative works, books, songs, TV shows, etc, its unlikely Wikidata would contain such data in the near future. Also, Wikidata is importing entries from Freebase manually, so it could be a very long time before all entries are matched with their corresponding Wikidata items.

Like you found, in my playing around with Google Knowledge Graph it appears to not include all Freebase entries either. It looks like it doesn't include some abstract concepts, like /m/0m1xv (talk show). I haven't found this documented so its not clear to me whether this is intentional or perhaps a beta issue.

akb
  • 61
  • 4