问题
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
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!
回答1:
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
回答2:
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.
来源:https://stackoverflow.com/questions/33636215/how-can-i-query-wikidata-with-a-freebase-id-from-a-youtube-video