From d88f645e267078572c19cbe37b37acc9798ad532 Mon Sep 17 00:00:00 2001 From: Morgan Date: Tue, 10 Mar 2015 09:29:58 +0000 Subject: factor out pages and util namespaces per #6 --- src/pronouns/util.clj | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/pronouns/util.clj (limited to 'src/pronouns/util.clj') diff --git a/src/pronouns/util.clj b/src/pronouns/util.clj new file mode 100644 index 0000000..1269664 --- /dev/null +++ b/src/pronouns/util.clj @@ -0,0 +1,16 @@ +(ns pronouns.util + (:require [clojure.string :as s])) + +(defn slurp-tabfile [path] + (let [lines (s/split (slurp path) #"\n")] + (map #(s/split % #"\t") lines))) + +(defn table-lookup + [query-key table] + (let [arity (count query-key) + filtered-table (filter #(= query-key (take arity %)) table)] + (first filtered-table))) + +(defn tabfile-lookup + [query-key tabfile] + (table-lookup query-key (slurp-tabfile tabfile))) -- cgit