-
Notifications
You must be signed in to change notification settings - Fork 5
/
tests_common.clj
62 lines (43 loc) · 1.74 KB
/
tests_common.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
;; [[file:../../../README.org::*Some Background - Data Preparation][Some Background - Data Preparation:2]]
(ns msync.lucene.tests-common
(:require [msync.lucene
[analyzers :as analyzers]
[document :as ld]]
[clojure.data.csv :as csv]
[clojure.java.io :as io]
[clojure.string :as s]))
(defn read-csv-resource-file
"Locate a file on the resource path and parse it as CSV,
creating a sequence of rows - each row being a list of the
CSV column-values"
[filename]
(-> filename
io/resource
slurp
csv/read-csv))
(defonce sample-data-file "sample-data.csv")
(defonce albums-file "albumlist.csv")
(defonce sample-data (-> sample-data-file
read-csv-resource-file
ld/vecs->maps))
(defn- process-csv-column [coll column]
(assoc coll column
(map s/trim (s/split (get coll column) #","))))
(defn process-album-data-row [row]
(-> row
(process-csv-column :Genre)
(process-csv-column :Subgenre)))
(defonce album-data (->> albums-file
read-csv-resource-file
ld/vecs->maps
(map process-album-data-row)))
;; Some Background - Data Preparation:2 ends here
;; [[file:../../../README.org::*Creating Analyzers][Creating Analyzers:1]]
(defonce default-analyzer (analyzers/standard-analyzer))
(defonce keyword-analyzer (analyzers/keyword-analyzer))
(defonce album-data-analyzer
(analyzers/per-field-analyzer default-analyzer
{:Year keyword-analyzer
:Genre keyword-analyzer
:Subgenre keyword-analyzer}))
;; Creating Analyzers:1 ends here