Database Reference
In-Depth Information
9.
We call load-data with the DBPedia SPARQL endpoint, the resource we want
information about (as a symbol), and the column map:
user=> (def d (load-data "http://dbpedia.org/sparql"
(symbol (str dbpedia dbpedia "United_Arab_
Emirates_dirham"))
col-map))
user=> (sel d :cols [:country :name :symbol])
| :country | :name | :symbol |
|----------------------+-----------------------------+---------|
| United Arab Emirates | United Arab Emirates dirham | إ.د |
How it works…
The only part of this recipe that has to do with SPARQL, really, is the make-query function.
It uses the sparql-select-query function to generate a SPARQL query string from the
query pattern. This pattern has to be interpreted in the context of the triple store that has the
namespaces deined. This context is set using the binding command. We can see how this
function works by calling it from the REPL by itself:
user=> (println
(make-query
(symbol (str dbpedia "/United_Arab_Emirates_dirham"))
(init-kb (kb-memstore))))
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?p ?o
WHERE { <http://dbpedia.org/resource/United_Arab_Emirates_dirham> ?p
?o .
FILTER ( ( ! isLiteral(?o)
|| ( datatype(?o) !=<http://www.w3.org/1999/02/22-rdf-syntax-
ns#langString> )
|| ( lang(?o) = "en" ) )
)
} LIMIT 200
The rest of the recipe is concerned with parsing the XML format of the results, and in many
ways, it's similar to the last recipe.
There's more…
For more information on RDF and linked data, see the previous recipe, Reading RDF data .
 
Search WWH ::




Custom Search