 (ns aurora.language
-  (:require [aurora.btree :as btree])
+  (:require [aurora.btree :as btree]
+            [aurora.join :as join])
   (:require-macros [aurora.macros :refer [apush set!!]]))
+
+;; KNOWLEDGE
 
 (defn keymap [from-fields to-fields]
   (let [keymap (make-array (alength to-fields))]

(defn knowledge []
  (Knowledge. {} 0))


(comment



  (.get-or-create-index kn "know" "heights" #js ["height" "name"])

  (.get-or-create-index kn "know" "edge" #js ["x" "y"])

  (.get-or-create-index kn "know" "connected" #js ["x" "y"])

  (.add-facts kn "know" "edge" #js ["x" "y"] #js [#js ["a" "b"] #js ["b" "c"] #js ["c" "d"] #js ["d" "b"]])

  (def edge-flow
    (Join. #js ["magic_iterator"] #js [#js [(.get-or-create-index kn "know" "edge" #js ["x" "y"]) #js [0 1]]]
           #js ["know"] #js ["connected"] #js [#js ["x" "y"]]))

  (def connected-flow
    (Join. #js ["magic_iterator" "magic_iterator"] #js [#js [(.get-or-create-index kn "know" "edge" #js ["x" "y"]) #js [0 1 nil]]
                                                        #js [(.get-or-create-index kn "know" "connected" #js ["x" "y"]) #js [nil 0 1]]]
           #js ["know"] #js ["connected"] #js [#js ["x" nil "y"]]))

  (def transitive-flow
    (Chain. #js [edge-flow (Fixpoint. connected-flow)]))

  (.run transitive-flow kn)

  (.get-or-create-index kn "know" "connected" #js ["x" "y"])
  )
