about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMorgan <m@morganastra.me>2015-07-04 01:19:36 +0000
committerMorgan <m@morganastra.me>2015-07-04 01:19:36 +0000
commit8839c2f9c7a7a898912f0624473cd41bd0219e4b (patch)
tree5ee5a6551e9c54e0a77100da31b512d19ab62fd2
parent72705caa5e4339c88d5e4dd85c3b471c124192bf (diff)
commit @duckinator's minimum-unambiguous-path fn, per #16
-rw-r--r--src/pronouns/util.clj10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/pronouns/util.clj b/src/pronouns/util.clj
index 8327568..6a27c30 100644
--- a/src/pronouns/util.clj
+++ b/src/pronouns/util.clj
@@ -43,3 +43,13 @@
           acc2 (conj acc pair)]
       (if (empty? todo) (reverse acc2)
           (recur acc2 row next (rest todo))))))
+
+(defn minimum-unambiguous-path
+  ([pronouns-table sections] (minimum-unambiguous-path pronouns-table sections 1))
+  ([pronouns-table sections number-of-sections]
+    (let [sections-subset (take number-of-sections sections)
+          results (filter (fn [pronouns] (= (take number-of-sections pronouns) sections-subset)) pronouns-table)]
+      (case (count results)
+        0 nil
+        1 (clojure.string/join "/" sections-subset)
+        (recur pronouns-table sections (+ number-of-sections 1))))))