Created
March 15, 2013 16:45
-
-
Save anonymous/5171258 to your computer and use it in GitHub Desktop.
tag expansion
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 expand-tags | |
"Expands set of tags using mapping of sets of base tags to | |
other (single) tags, example: | |
{#{:tomatoes :potatoes :legumes} :culinary-vegetables | |
#{:peanuts :lentils} :legumes | |
#{:tomatoes :legumes} :botanical-fruits}" | |
[tags expansions] | |
(let [matches (filter (fn [[base-set _]] (some base-set tags)) expansions) | |
new-tags (mapcat to-coll (map val matches)) | |
expanded (set (concat tags new-tags))] | |
(if (= tags expanded) | |
tags | |
(recur expanded expansions)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment