           (lazy-cat lexical phrasal)
           (lazy-cat phrasal lexical))))))
 
-(defn add-complement [bolt path spec grammar lexicon cache]
+(defn add-complement [bolt path spec grammar lexicon cache morph]
   (let [input-spec spec
         cache (if (future? cache) @cache cache)
         from-bolt bolt ;; so we can show what (add-complement) did to the input bolt, for logging.

(declare lightning-bolt)
(declare generate-all)

(defn generate [spec grammar lexicon index]
  (first (take 1 (generate-all spec grammar lexicon index))))

(defn generate-all-with-model [spec {grammar :grammar
                                     index :index
                                     lexicon :lexicon}]
  (let [index (if (future? index) @index index)
        lexicon (if (future? lexicon) @lexicon lexicon)]
    (log/info (str "using grammar of size: " (.size grammar)))
    (log/info (str "using index of size: " (.size index)))
    (if (seq? spec)
      (map generate-all spec grammar lexicon index)
      (generate spec grammar
                (flatten (vals lexicon))
                index))))

(defn generate-all [spec grammar lexicon index]
  (filter #(not (fail? %))
          (cond (and (or (seq? spec)
                         (vector? spec))
                     (not (empty? spec)))
                (lazy-cat (generate-all (first spec) grammar lexicon index)
                          (generate-all (rest spec) grammar lexicon index))
                true
                (do
                  (log/debug (str "generate-all with semantics: " (show-spec (remove-false (get-in spec [:synsem :sem])))))

(ns babel.forest
  (:refer-clojure :exclude [get-in deref resolve find future parents])
  (:require
   [babel.cache :refer (build-lex-sch-cache get-comp-phrases-of get-head-phrases-of get-lex
                                            get-parent-phrases-for-spec)]
   [babel.over :as over]
   [clojure.core :as core]
   [clojure.set :refer :all]
   [clojure.string :as string]
   [clojure.tools.logging :as log]
   [dag-unify.core :refer (dissoc-paths get-in fail? fail-path-between lazy-shuffle ref? remove-false 
                                        remove-top-values-log strip-refs show-spec unifyc)]))

