underive
(underive tag parent)
(underive h tag parent)
Source docstring:
Removes a parent/child relationship between parent and
tag. h must be a hierarchy obtained from make-hierarchy, if not
supplied defaults to, and modifies, the global hierarchy.
(defn underive
([tag parent]
(swap-global-hierarchy! underive tag parent)
nil)
([h tag parent]
(let [parentMap (:parents h)
childsParents (if (parentMap tag)
(disj (parentMap tag) parent) #{})
newParents (if (not-empty childsParents)
(assoc parentMap tag childsParents)
(dissoc parentMap tag))
deriv-seq (flatten (map #(cons (first %) (interpose (first %) (second %)))
(seq newParents)))]
(if (contains? (parentMap tag) parent)
(reduce #(apply derive %1 %2) (make-hierarchy)
(partition 2 deriv-seq))
h))))