Database Reference
In-Depth Information
2.
After taking a look at the data some more, we can identify what data we want to pull
out and start to formulate a query. We'll use the kr library's ( https://github.com/
drlivingston/kr ) query DSL and bind it to the name q :
(def q '((?/c rdf/type money/Currency)
(?/c money/name ?/full_name)
(?/c money/shortName ?/name)
(?/c money/symbol ?/symbol)
(?/c money/minorName ?/minor_name)
(?/c money/minorExponent ?/minor_exp)
(?/c money/isoAlpha ?/iso)
(?/c money/currencyOf ?/country)))
3.
Now, we need a function that takes a result map and converts the variable names
in the query into column names in the output dataset. The header-keyword and
fix-headers functions will do this:
(defn header-keyword
"This converts a query symbol to a keyword."
[header-symbol]
(keyword (.replace (name header-symbol) \_ \-)))
(defn fix-headers
"This changes all of the keys in the map to make them
valid header keywords."
[coll]
(into {}
(map (fn [[k v]] [(header-keyword k) v])
coll)))
4.
As usual, once all of the pieces are in place, the function that ties everything
together is short:
(defn load-data
[krdf-file q]
(load-rdf-file k rdf-file)
(to-dataset (map fix-headers (query k q))))
 
Search WWH ::




Custom Search