-
-
Save benfleis/ddf17381dcd7dd112236 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn explode-conjuncts [conjuncts] | |
"create sequence of [conjunct term] for all terms in all conjuncts" | |
(for [conjunct conjuncts | |
term (remove #{'not 'and} (flatten conjunct))] | |
[conjunct term])) | |
(defn make-conjunct-terms-map [conjuncts] | |
"build map of <conjunct> -> #{terms}" | |
(->> conjuncts | |
(explode-conjuncts) | |
(group-by first) ; group by conjunct | |
(map second) | |
(map (fn [ct-seq] [(ffirst ct-seq) (set (map second ct-seq))])) | |
(into {}))) | |
(def conjuncts | |
['[and f1 f2 f3] | |
'[and f1 f2] | |
'[not f4]]) | |
(def conjunct->terms (make-conjunct-terms-map conjuncts)) | |
;; > conjunct->terms | |
;; {[and f1 f2 f3] #{f1 f3 f2}, [and f1 f2] #{f1 f2}, [not f4] #{f4}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment