Created
January 12, 2016 21:42
-
-
Save WilliamParker/b109dba95f36187f54d0 to your computer and use it in GitHub Desktop.
Test namespace for duplicate rules in clara-rules
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
(ns clara.examples.duplicates | |
(:require [clara.rules.accumulators :as acc] | |
[clara.rules :refer :all] | |
[clara.rules.compiler :as c])) | |
(defrecord Temperature [t]) | |
(defrecord Cold [t]) | |
(defrule is-cold? | |
[Temperature (= ?t t)] | |
=> | |
(insert! (->Cold ?t))) | |
(defquery cold-query | |
"" | |
[] | |
[?c <- Cold]) | |
(def dup-session (mk-session [is-cold? is-cold? cold-query])) | |
(defn get-cold [] | |
(-> dup-session | |
(insert (->Temperature 10)) | |
fire-rules | |
(query cold-query))) | |
(let [productions [is-cold? is-cold?] | |
beta-struct (c/to-beta-tree productions) | |
beta-tree (c/compile-beta-tree beta-struct) | |
alpha-tree (c/to-alpha-tree beta-struct) | |
alpha-nodes (c/compile-alpha-nodes alpha-tree) | |
rulebase (c/build-network beta-tree alpha-nodes productions)] | |
(def debug {:beta-struct beta-struct | |
:beta-tree beta-tree | |
:alpha-tree alpha-tree | |
:alpha-nodes alpha-nodes | |
:rulebase rulebase})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment