Enriching our graph with Wikidata information
In this section, we are going to use the preceding SPARQL query and the Wikidata query API to retrieve information about each person in our Neo4j graph and add their country of citizenship.
Loading data into Neo4j for one person
Using the previous query, we are going to query the Wikidata API SPARQL endpoint using APOC, and save the result into Neo4j:
- Save the query as a parameter in Neo4j Browser:
:param query=>apoc.text.urlencode("SELECT ?personLabel ?countryLabel WHERE {?person rdfs:label 'George Clooney'@en ; wdt:P27 ?country . SERVICE wikibase:label {bd:serviceParam wikibase:language 'en' .}}")
- Make sure you encode the query since it’s going to be used in the query string to perform an
HTTP GET
query. You can see what the encoded query looks like by just usingRETURN $query
, which prints the following:"SELECT+%3FpersonLabel+%3FcountryLabel+WHERE+%7B%3Fperson +rdfs%3Alabel...