javaandroidapifreebasewikidata-api

How to use the Wikidata API or an alternative to Freebase


I have a couple of years of programming experience in Java (Android) and this is my first time with the use of API's to retrieve JSON data. So to get basic facts on a queried topic I thought of using Freebase API however this is now going to be deprecated and Google is moving it to Wikidata. However the query API is still in beta and I simply cannot understand the query API documentation or how to retrieve the facts. So is there an alternative to Wikidata and Freebase?

These are my final questions:


Solution

  • The data you want to access is stored in a Subject Property(also Predicate) Object (SPO) format. That means you have a subject and an object that is associated with a property for example <Albert_Einstein> <wasBornIn> <Germany>.

    Usually you can access those SPO-databases over an endpoint using SPARQL. SPARQL is a SQL like language which allows you to formulate queries to access the data. Fortunatly for you Wikidata also has a sparql endpoint you can use: https://query.wikidata.org/

    Here is a simple example which will load all subjects that are referenced, using a rdf-schema label, to the String "Titanic" and limit the results to 100 entries.

    select distinct ?a where {?a <http://www.w3.org/2000/01/rdf-schema#label> "Titanic"@en } LIMIT 100 
    

    To query Wikidata in Java you can use Jena which will allow you to use SPARQL-queries and the endpoint to access the data.

    As far as I know you can also access Wikidata using http but there a few benefits using SPARQL. There are two other big databases I know of that you can use and both of them have a SPARQL endpoint. So it's quite easy to change the endpoint to access the other two databases. It's also possible that one database contains a reference to another database which you can follow to gather more data.

    Since you also asked for alternatives the two databases I mentiond are DBpedia (SPARQL-Endpoint) and Yago (SPARQL-endpoint). Both use Wikipedia to extract facts and therefor they are huge. Yago also uses WordNet to build a nice taxonomy you can use to classify your data. DBpedia on the other hand has a lot of references to other sites you can use.