Database Reference
In-Depth Information
How to do it…
Most part of this recipe will deine the data we'll query. For this, we will use a list of
companions and actors from the British television program Doctor Who . The data is in a
sequence of maps, so we'll need to transform it into several sequences of vectors, which is
what Cascalog can access. In one sequence there will be a list of the companions' lowercased
names, for which we'll use keys in other data tables. One will be the name key and the full
name, and the inal one will be a table of the companions' keys to a doctor they tagged along
with. We'll also deine a list of the actors who played the role of doctors and the years in which
they played them.
1.
At the time of writing this topic, there are about 50 companions. I've only listed 10 here,
but the examples might show the other companions. The full data is available in the
source code. You can also download just the code to create this dataset from http://
www.ericrochester.com/clj-data-analysis/data/companions.clj :
(def input-data
[{:given-name "Susan", :surname "Forman", :doctors [1]}
{:given-name "Katarina", :surname nil, :doctors [1]}
{:given-name "Victoria", :surname "Waterfield", :doctors [2]}
{:given-name "Sarah Jane", :surname "Smith", :doctors [3 4 10]}
{:given-name "Romana", :surname nil, :doctors [4]}
{:given-name "Kamelion", :surname nil, :doctors [5]}
{:given-name "Rose", :surname "Tyler", :doctors [9 10]}
{:given-name "Martha", :surname "Jones", :doctors [10]}
{:given-name "Adelaide", :surname "Brooke", :doctors [10]}
{:given-name "Craig", :surname "Owens", :doctors [11]}])
(def companion (map string/lower-case
(map :given-name input-data)))
(def full-name
(map (fn [{:keys [given-name surname]}]
[(string/lower-case given-name)
(string/trim
(string/join \space [given-name surname]))])
input-data))
(def doctor
(mapcat #(map (fn [d] [(string/lower-case (:given-name %)) d])
(:doctors %))
input-data))
 
Search WWH ::




Custom Search