allow ellipses to shorten unambiguous path, e.g. /they/.../themself per #46
This commit is contained in:
parent
93c3797168
commit
5d85c1a5e7
@ -3,6 +3,7 @@ ze zir zir zirs zirself
|
|||||||
she her her hers herself
|
she her her hers herself
|
||||||
he him his his himself
|
he him his his himself
|
||||||
they them their theirs themselves
|
they them their theirs themselves
|
||||||
|
they them their theirs themself
|
||||||
xey xem xyr xyrs xemself
|
xey xem xyr xyrs xemself
|
||||||
sie hir hir hirs hirself
|
sie hir hir hirs hirself
|
||||||
it it its its itself
|
it it its its itself
|
||||||
|
@ -21,26 +21,40 @@
|
|||||||
(let [lines (s/split (slurp path) #"\n")]
|
(let [lines (s/split (slurp path) #"\n")]
|
||||||
(map #(s/split % #"\t") lines)))
|
(map #(s/split % #"\t") lines)))
|
||||||
|
|
||||||
|
(defn table-front-filter
|
||||||
|
[query-key table]
|
||||||
|
(let [arity (count query-key)]
|
||||||
|
(filter #(= query-key (take arity %)) table)))
|
||||||
|
|
||||||
|
(defn table-end-filter
|
||||||
|
[query-key table]
|
||||||
|
(let [table-arity (count (first table))
|
||||||
|
query-arity (count query-key)]
|
||||||
|
(filter #(= query-key (drop (- table-arity query-arity) %)) table)))
|
||||||
|
|
||||||
(defn table-lookup
|
(defn table-lookup
|
||||||
[query-key table]
|
[query-key table]
|
||||||
(let [arity (count query-key)
|
(if (some #(= "..." %) query-key)
|
||||||
filtered-table (filter #(= query-key (take arity %)) table)]
|
(let [[query-front query-end-] (split-with #(not= "..." %) query-key)
|
||||||
(first filtered-table)))
|
query-end (drop 1 query-end-)
|
||||||
|
front-matches (table-front-filter query-front table)]
|
||||||
|
(first (table-end-filter query-end front-matches)))
|
||||||
|
(first (table-front-filter query-key table))))
|
||||||
|
|
||||||
(defn tabfile-lookup
|
(defn tabfile-lookup
|
||||||
[query-key tabfile]
|
[query-key tabfile]
|
||||||
(table-lookup query-key (slurp-tabfile tabfile)))
|
(table-lookup query-key (slurp-tabfile tabfile)))
|
||||||
|
|
||||||
(defn minimum-unambiguous-path
|
(defn minimum-unambiguous-path
|
||||||
([table sections] (minimum-unambiguous-path table sections 1))
|
([table columns] (minimum-unambiguous-path table columns 1))
|
||||||
([table sections number-of-sections]
|
([table columns number-of-columns]
|
||||||
(let [sections-subset (take number-of-sections sections)
|
(let [columns-subset (take number-of-columns columns)
|
||||||
results (filter #(= (take number-of-sections %) sections-subset)
|
results (filter #(= (take number-of-columns %) columns-subset)
|
||||||
table)]
|
table)]
|
||||||
(case (count results)
|
(case (count results)
|
||||||
0 nil
|
0 nil
|
||||||
1 (clojure.string/join "/" sections-subset)
|
1 (clojure.string/join "/" columns-subset)
|
||||||
(recur table sections (+ number-of-sections 1))))))
|
(recur table columns (+ number-of-columns 1))))))
|
||||||
|
|
||||||
(defn abbreviate
|
(defn abbreviate
|
||||||
"given a list of pronoun rows, return a list of minimum unabiguous paths"
|
"given a list of pronoun rows, return a list of minimum unabiguous paths"
|
||||||
|
Loading…
Reference in New Issue
Block a user