4 Commits
Author SHA1 Message Date
Roman Volosovskyi eb3e0b656a jdk8 2016-03-23 22:29:00 +02:00
Roman Volosovskyi a80f7c7a39 datomic component 2016-03-23 22:13:59 +02:00
Roman Volosovskyi a7a885aa0e few fixes... 2016-03-23 22:13:39 +02:00
Roman Volosovskyi 40699d5546 some onyx/datomic/system stuff 2016-03-23 16:52:58 +02:00
20 changed files with 577 additions and 207 deletions
+2
View File
@@ -12,6 +12,8 @@ pom.xml.asc
.idea
*.iml
*~
/onyx.log
/profiles.clj
\#*\#
.\#*
/src/nal/experiments.clj
+3
View File
@@ -0,0 +1,3 @@
machine:
java:
version: oraclejdk8
+11
View File
@@ -0,0 +1,11 @@
{:dev {:env {:db-uri "datomic:dev://localhost:4334/nars"
:zookeeper {:env-config {:zookeeper/address "127.0.0.1:2188"
:zookeeper/server? true
:zookeeper.server/port 2188}
:peer-config {:zookeeper/address "127.0.0.1:2188"
:onyx.peer/job-scheduler :onyx.job-scheduler/balanced
:onyx.messaging/impl :aeron
:onyx.messaging/peer-port 40200
:onyx.messaging/bind-addr "localhost"}}}}
:test {:env {:db-uri "datomic:dev://localhost:4334/nars_test"}}}
+29 -3
View File
@@ -9,14 +9,40 @@
[org.clojure/tools.nrepl "0.2.12"]
[org.clojure/data.priority-map "0.0.7"]
[org.clojure/core.match "0.3.0-alpha4"]
[org.clojure/core.unify "0.5.5"]]
[org.clojure/core.unify "0.5.5"]
[org.clojure/core.async "0.2.374"]
[org.onyxplatform/onyx "0.8.11"]
[org.onyxplatform/onyx-datomic "0.8.11.1"]
[datomic-schema "1.3.0"]
[org.danielsz/system "0.2.0"]
[environ "1.0.2"]
[com.datomic/datomic-free "0.9.5350"]]
:main ^:skip-aot narjure.core
:plugins [[lein-cloverage "1.0.6"]
[jonase/eastwood "0.2.3"]
[lein-kibit "0.1.2"]
[cider/cider-nrepl "0.11.0-SNAPSHOT"]]
[cider/cider-nrepl "0.11.0-SNAPSHOT"]
[lein-environ "1.0.2"]]
:eastwood {:exclude-namespaces [nal.rules]}
:target-path "target/%s"
:repl-options {:init-ns narjure.repl
:nrepl-middleware [narjure.repl/narsese-handler]}
:profiles {:uberjar {:aot :all}})
:env {:db-uri "datomic:dev://localhost:4334/nars"
:db-uri-onyx "datomic:dev://localhost:4334/nars_input"
:zookeeper {:env-config {:zookeeper/address "127.0.0.1:2188"
:zookeeper/server? true
:zookeeper.server/port 2188}
:peer-config {:zookeeper/address "127.0.0.1:2188"
:onyx.peer/job-scheduler :onyx.job-scheduler/balanced
:onyx.messaging/impl :aeron
:onyx.messaging/peer-port 40200
:onyx.messaging/bind-addr "localhost"}}}
:profiles {:uberjar {:aot :all}
;local configuration can be redefined on profiles.clj
;https://github.com/technomancy/leiningen/blob/master/doc/PROFILES.md#declaring-profiles
:dev {:dependencies [[com.datomic/datomic-pro "0.9.5350"]]}
:test {:dependencies [[com.datomic/datomic-free "0.9.5350"]]
:env {:db-uri "datomic:mem://localhost:4334/nars"
:db-uri-onyx "datomic:mem://localhost:4334/nars_input"}}}
:repositories {"my.datomic.com" {:url "https://my.datomic.com/repo"
:creds :gpg}})
+2 -2
View File
@@ -7,8 +7,8 @@
(if (>= c1 c2) [f1 c1] [f2 c2]))
(defn inference
[{:keys [task-type] :as task} belief]
(generate-conclusions (r/rules task-type) task belief))
[rules {:keys [task-type] :as task} belief]
(generate-conclusions (rules task-type) task belief))
(def revision t/revision)
+2 -2
View File
@@ -8,8 +8,8 @@
(defn get-matcher [rules p1 p2]
(let [matchers (->> (mall-paths p1 p2)
(filter rules)
(select-keys rules)
(map (fn [el] (:matcher (second el)))))]
(map rules)
(map (fn [el] (:matcher el))))]
(case (count matchers)
0 (constantly [])
1 (first matchers)
+11 -3
View File
@@ -26,6 +26,14 @@
`implications-and-equivalences `get-terms `empty? `intersection
`n/reduce-seq-conj})
(defn operators->placeholders
[statement]
(walk statement
(and (symbol? :el)
(operator? :el)) '_
(= :interval :el) '_
(coll? :el) (vec :el)))
(defn quote-operators
[statement]
(walk statement
@@ -93,14 +101,14 @@
(replace-occurrences
`(fn [{p1# :statement ~t1 ~truth-kw :t-occurrence :occurrence :as ~task}
{p2# :statement ~t2 :truth :b-occurrence :occurrence :as ~belief}]
(match [p1# p2#] ~(quote-operators pattern)
(let [~(operators->placeholders (first pattern)) p1#
~(operators->placeholders (second pattern)) p2#]
~(traversal {:t1 t1
:t2 t2
:task task
:belief belief
:task-type task-type}
rules)
:else nil)))))
rules))))))
(defn find-and-replace-symbols
"Replaces all terms in statemnt to placeholders that will be used in pattern
+26 -23
View File
@@ -59,7 +59,7 @@
(defn goal?
"Return true if rule allows only goal as task."
[{pre :pre [{post :post} :as concls] :conclusions}]
[{pre :pre [{post :post}] :conclusions}]
(or (some #{:goal?} pre)
(some (fn [el] (and (keyword? el)
(s/starts-with? (str el) ":d/")))
@@ -79,9 +79,9 @@
so, if we find rule with path [[--> :any :any] :and [--> [:any :any]]],
it matches to current's rule path too, hence it should be added to the set
of rules that matches [[--> [- :any :any] :any] :and [--> [:any :any]]] path."
[ac [k {:keys [all starts-with]}]]
[ac [k {:keys [all]}]]
(let [rules (mapcat :rules (vals (select-keys ac all)))]
ac #_(-> ac
(-> ac
(update-in [k :rules] concat rules)
(update-in [k :rules] set))))
@@ -102,7 +102,7 @@
values from the premises, rules will be used to generate deriver."
[ruleset task-type]
(let [rules (reduce rule->map {} ruleset)]
(generate-matching (reduce add-possible-paths rules rules) task-type)))
(generate-matching rules task-type)))
;---------------------------------------------------------------------------
@@ -117,24 +117,27 @@
`~raw-rules
pairs)))
(defmacro defrules
(defmacro defrules [name & rules]
"Define rules. Rules must be #R statements."
;TODO exception on duplication of the rule
[name & rules]
`(time
(let [rules# (rules->> (quote ~rules)
contains-list? generate-all-lists
contains-list? generate-all-lists
identity rule
order-for-all-same? generate-all-orders
allow-swapping? swap
allow-backward? expand-backward-rules)
judgement-rules# (check-duplication (filter judgement? rules#))
question-rules# (check-duplication (filter question? rules#))
goal-rules# (check-duplication (filter goal? rules#))]
(println "Q rules:" (count question-rules#))
(println "J rules:" (count judgement-rules#))
(println "G rules:" (count goal-rules#))
(def ~name {:judgement (rules-map judgement-rules# :judgement)
:question (rules-map question-rules# :question)
:goal (rules-map goal-rules# :goal)}))))
`(def ~name (quote ~rules)))
(defn compile-rules
[& rules]
(time
(let [rules# (rules->> (apply concat rules)
contains-list? generate-all-lists
contains-list? generate-all-lists
identity rule
order-for-all-same? generate-all-orders
allow-swapping? swap
allow-backward? expand-backward-rules)
judgement-rules# (check-duplication (filter judgement? rules#))
question-rules# (check-duplication (filter question? rules#))
goal-rules# (check-duplication (filter goal? rules#))]
(println "Q rules:" (count question-rules#))
(println "J rules:" (count judgement-rules#))
(println "G rules:" (count goal-rules#))
{:judgement (rules-map judgement-rules# :judgement)
:question (rules-map question-rules# :question)
:goal (rules-map goal-rules# :goal)})))
+9 -23
View File
@@ -1,10 +1,10 @@
(ns nal.rules
(:require [nal.deriver.rules :refer [defrules]]
(:require [nal.deriver.rules :refer [defrules compile-rules]]
nal.reader))
(declare --S S --P P <-> |- --> ==> M || && =|> -- A Ai B <=>)
(defrules rules
(defrules all-rules
;Similarity to Inheritance
#R[(S --> P) (S <-> P) |- (S --> P) :post (:t/struct-int :p/judgement) :pre (:question?)]
;Inheritance to Similarity
@@ -229,7 +229,7 @@
:pre ((:!= S P))]
#R[(P =/> M) (S =/> M) |- (((P || S) =/> M) :post (:t/intersection)
((P &| S) =/> M) :post (:t/union))
:pre ((:!= S P)) ]
:pre ((:!= S P))]
#R[(P =\> M) (S =\> M) |- (((P || S) =\> M) :post (:t/intersection)
((P &| S) =\> M) :post (:t/union))
:pre ((:!= S P))]
@@ -306,7 +306,7 @@
((S --> $X) ==> (P --> $X)) :post (:t/induction)
((P --> $X) <=> (S --> $X)) :post (:t/comparison)
(&& (S --> #Y) (P --> #Y)) :post (:t/intersection))
:pre ((:!= S P))]
:pre ((:!= S P))]
#R[(S --> M) (P --> M) |- (((&/ (P --> $X) I) =/> (S --> $X)) :post (:t/induction :linkage-temporal)
((S --> $X) =\> (&/ (P --> $X) I)) :post (:t/abduction :linkage-temporal)
@@ -324,7 +324,7 @@
(($X --> P) ==> ($X --> S)) :post (:t/abduction)
(($X --> S) <=> ($X --> P)) :post (:t/comparison)
(&& (#Y --> S) (#Y --> P)) :post (:t/intersection))
:pre ((:!= S P)) ]
:pre ((:!= S P))]
#R[(M --> S) (M --> P) |- (((&/ ($X --> P) I) =/> ($X --> S)) :post (:t/induction :linkage-temporal)
(($X --> S) =\> (&/ ($X --> P) I)) :post (:t/abduction :linkage-temporal)
@@ -348,11 +348,11 @@
:pre ((:!= S P))]
#R[(A ==> (P --> M)) (S --> M) |- (((&& A (P --> $X)) ==> (S --> $X)) :post (:t/abduction)
(&& (A ==> (P --> #Y)) (S --> #Y)) :post (:t/intersection)) ]
(&& (A ==> (P --> #Y)) (S --> #Y)) :post (:t/intersection))]
#R[(&& (P --> M) :list/A) (S --> M) |- (((S --> $Y) ==> (&& (P --> $Y) :list/A)) :post (:t/abduction)
(&& (S --> #Y) (P --> #Y) :list/A) :post (:t/intersection))
:pre ((:!= S P))]
:pre ((:!= S P))]
#R[(A --> L) ((A --> S) ==> R) |- ((&& (#X --> L) (#X --> S)) ==> R) :post (:t/induction)]
#R[(A --> L) ((&& (A --> S) :list/A) ==> R) |- ((&& (#X --> L) (#X --> S) :list/A) ==> R) :pre ((:substitute A #X)) :post (:t/induction)]
@@ -386,7 +386,7 @@
#R[((&& C :list/A) ==> Z) ((&& C :list/B) ==> Z) |- (((&& :list/A) ==> (&& :list/B)) :post (:t/induction)
((&& :list/B) ==> (&& :list/A)) :post (:t/induction))]
#R[(Z ==> (&& C :list/A)) (Z ==> (&& C :list/B)) |- (((&& :list/A) ==> (&& :list/B)) :post (:t/abduction)
((&& :list/B) ==> (&& :list/A)) :post (:t/abduction))]
((&& :list/B) ==> (&& :list/A)) :post (:t/abduction))]
; NAL7 specific inference
; Reasoning about temporal statements. those are using the ==> relation because relation in time is a relation of the truth between statements.
@@ -448,18 +448,4 @@
#R[A --A |- A :pre (:question?) :post (:t/belief-negation :p/judgement)]
; compound composition one premise
#R[(|| B :list/A) B |- (|| B :list/A) :pre (:question?) :post (:t/belief-structural-deduction :p/judgement)]
)
(defn freq [task-type]
"Check frequency"
(into {} (map (fn [[k v]] [(str k) (count (:rules v))]) (task-type rules))))
(defn stats [task-type]
(let [fr (freq task-type)]
(println "Total" (reduce + (vals fr)))
(println "Total keys" (count (task-type rules)))
(println "Freq" (sort (frequencies (vals fr))))
(println "Min" (reduce min (vals fr)))
(println "Max" (reduce (fn [[_ v1 :as p] [_ v :as n]]
(if (> v1 v) p n)) fr))))
#R[(|| B :list/A) B |- (|| B :list/A) :pre (:question?) :post (:t/belief-structural-deduction :p/judgement)])
+19
View File
@@ -0,0 +1,19 @@
(ns narjure.components.datomic
(:require [com.stuartsierra.component :as component]
[datomic.api :as d]))
(defrecord Datomic [uri conn schema]
component/Lifecycle
(start [component]
(println "Start Datomic " uri)
(let [db (d/create-database uri)
conn (d/connect uri)]
(d/transact conn schema)
(assoc component :conn conn)))
(stop [component]
(println "Stop Datomic " uri)
(assoc component :conn nil)))
(defn new-datomic-db [uri schema]
(map->Datomic {:uri uri
:schem schema}))
+20
View File
@@ -0,0 +1,20 @@
(ns narjure.components.deriver
(:require [com.stuartsierra.component :as component]
[nal.rules :as r]
[nal.deriver.rules :refer [compile-rules]]
[nal.core :refer [inference]]))
(defrecord Deriver [inference rules]
component/Lifecycle
(start [component]
(println "Start Deriver")
(let [rules (compile-rules r/all-rules)]
(assoc component :inference (partial inference rules)
:rules rules)))
(stop [component]
(println "Stop Deriver")
(assoc component :inference nil
:rules nil)))
(defn new-deriver []
(map->Deriver {}))
+30
View File
@@ -0,0 +1,30 @@
(ns narjure.components.onyx
(:require [com.stuartsierra.component :as component]
[onyx.api :as o])
(:import (java.util UUID)))
(defrecord Onyx [env-config peer-config env peer-group]
component/Lifecycle
(start [component]
(println "Start Onyx")
(let [id (UUID/randomUUID)
env-config (assoc env-config :onyx/id id)
peer-config (assoc peer-config :onyx/id id)
env (o/start-env env-config)
peer-group (o/start-peer-group peer-config)]
(assoc component :env-config env-config
:env env
:peer-config peer-config
:peer-group peer-group)))
(stop [component]
(println "Stop Onyx")
(o/shutdown-peer-group peer-group)
(o/shutdown-env env)
(assoc component :env-config nil
:env nil
:peer-config nil
:peer-group nil)))
(defn new-onyx [{:keys [env-config peer-config]}]
(map->Onyx {:env-config env-config
:peer-config peer-config}))
@@ -0,0 +1,25 @@
(ns narjure.components.task-processing-job
(:require [com.stuartsierra.component :as component]
[narjure.control.task-processing :as tp]
[onyx.api :as o]))
(defrecord TaskProcessingJob [db-uri db-uri-onyx onyx]
component/Lifecycle
(start [component]
(println "Start TaskProcessingJob")
(let [{:keys [peer-group peer-config]} onyx
n-peers (count (set (mapcat identity tp/workflow)))
v-peers (o/start-peers n-peers peer-group)
job (o/submit-job peer-config (tp/job-config db-uri-onyx db-uri))]
(assoc component :v-peers v-peers
:job job)))
(stop [{:keys [v-peers] :as component}]
(println "Stop TaskProcessingJob")
(doseq [v-peer v-peers]
(o/shutdown-peer v-peer))
(assoc component :v-peers nil
:job nil)))
(defn new-task-processing-job [db-uri db-uri-onyx]
(map->TaskProcessingJob {:db-uri db-uri
:db-uri-onyx db-uri-onyx}))
+13
View File
@@ -0,0 +1,13 @@
(ns narjure.control.general-inference)
(def workflow
[[:general-inference-tick :select-concept]
[:select-concept :out-update-concept-budget]
[:select-concept :select-tasklink]
[:select-tasklink :out-update-tasklink-budget]
[:select-tasklink :select-termlink]
[:select-termlink :out-update-termlink-budget]
[:select-termlink :inference]
[:inference :out-conclusions]])
+148
View File
@@ -0,0 +1,148 @@
(ns narjure.control.task-processing
(:require [clojure.core.async :refer [chan >!! <!! close! alts!!]]
[onyx.plugin.core-async :refer [take-segments!]]
[onyx.api]
[datomic.api :as d]
[narjure.control.utils :refer :all]
[onyx.plugin.tasks.datomic :as od]))
(def tp-ns :narjure.control.task-processing)
(def workflow
[[:read-task :answer-yn-question]
[:read-task :answer-general-question]
[:answer-yn-question :out-answers]
[:answer-general-question :out-answers]
[:read-task :find-related-concepts]
[:find-related-concepts :out-update-tasklinks]
[:find-related-concepts :out-check-tasklinks-capacity]
[:read-task :belief-revision]
[:belief-revision :out-update-beliefs]
[:read-task :goal-revision]
[:goal-revision :out-update-goals]])
(defn answer-yn-question [{:keys [task] :as segment}]
(println :yn)
{})
(defn answer-general-question [{:keys [task] :as segment}]
(println :general)
{})
(defn find-related-concepts [{:keys [task] :as segment}]
(println :rel)
{})
(defn belief-revision [{:keys [task] :as segment}]
(println :bel)
{})
(defn goal-revision [{:keys [task] :as segment}]
(println :goal)
{})
(def input-chan (chan))
(def output-chan (chan))
(def batch-size 10)
(def task-processing-fn
(partial onyx-fn :narjure.control.task-processing batch-size))
(defn catalog [db-uri-in db-uri-out]
(concat
[(in-datomic :read-task {:batch-size batch-size
:db-uri db-uri-in})]
(map task-processing-fn
[:answer-yn-question
:answer-general-question
:find-related-concepts
:belief-revision
:goal-revision])
(map (fn [task]
(out-datomic task :db.part/user {:batch-size batch-size
:db-uri db-uri-out}))
[:out-answers
:out-update-tasklinks
:out-check-tasklinks-capacity
:out-update-beliefs
:out-update-goals])))
(def tp-condition (partial condition :narjure.control.task-processing))
(def flow-conditions
[(tp-condition :read-task [:answer-yn-question] :yn-question?)
(tp-condition :read-task [:answer-general-question] :general-question?)
(tp-condition :read-task [:belief-revision] :judgement?)
(tp-condition :read-task [:goal-revision] :goal?)
(tp-condition :read-task [:find-related-concepts] :constantly-true)])
(defn judgement? [_ _ {{task-type :task-type} :task} _]
(= task-type :judgement))
(defn goal? [_ _ {{task-type :task-type} :task} _]
(= task-type :goal))
(defn yn-question? [_ _ {{task-type :task-type} :task} _]
(= task-type :yn-question))
(defn general-question? [_ _ {{task-type :task-type} :task} _]
(= task-type :general-question))
(def constantly-true (constantly true))
;-------------------------------------------------------------------------------
(defn inject-in-ch [event lifecycle]
{:core.async/chan input-chan})
(defn inject-out-ch [event lifecycle]
{:core.async/chan output-chan})
(def in-calls
{:lifecycle/before-task-start inject-in-ch})
(def out-calls
{:lifecycle/before-task-start inject-out-ch})
(def lifecycles
[{:lifecycle/task :read-task
:lifecycle/calls (full-fn-name tp-ns :in-calls)}
{:lifecycle/task :read-task
:lifecycle/calls :onyx.plugin.core-async/reader-calls}
{:lifecycle/task :out-answers
:lifecycle/calls (full-fn-name tp-ns :out-calls)}
{:lifecycle/task :out-answers
:lifecycle/calls :onyx.plugin.core-async/writer-calls}
{:lifecycle/task :out-update-tasklinks
:lifecycle/calls (full-fn-name tp-ns :out-calls)}
{:lifecycle/task :out-update-tasklinks
:lifecycle/calls :onyx.plugin.core-async/writer-calls}
{:lifecycle/task :out-check-tasklinks-capacity
:lifecycle/calls (full-fn-name tp-ns :out-calls)}
{:lifecycle/task :out-check-tasklinks-capacity
:lifecycle/calls :onyx.plugin.core-async/writer-calls}
{:lifecycle/task :out-update-beliefs
:lifecycle/calls (full-fn-name tp-ns :out-calls)}
{:lifecycle/task :out-update-beliefs
:lifecycle/calls :onyx.plugin.core-async/writer-calls}
{:lifecycle/task :out-update-goals
:lifecycle/calls (full-fn-name tp-ns :out-calls)}
{:lifecycle/task :out-update-goals
:lifecycle/calls :onyx.plugin.core-async/writer-calls}])
(defn job-config [db-uri-in db-uri-out]
{:catalog (catalog db-uri-in db-uri-out)
:workflow workflow
:lifecycles lifecycles
:flow-conditions flow-conditions
:task-scheduler :onyx.task-scheduler/balanced})
+64
View File
@@ -0,0 +1,64 @@
(ns narjure.control.utils)
(defn full-fn-name [namespace fn-name]
(keyword (str (name namespace) "/" (name fn-name))))
(defn onyx-fn [namespace batch-size fn-name]
(let [full-name (full-fn-name namespace fn-name)]
{:onyx/name fn-name
:onyx/fn full-name
:onyx/type :function
:onyx/batch-size batch-size}))
(defn in-async
([name] (in-async name {}))
([name {bs :batch-size peers :peers :or {peers 1 bs 1}}]
{:onyx/name name
:onyx/plugin :onyx.plugin.core-async/input
:onyx/type :input
:onyx/medium :core.async
:onyx/max-peers peers
:onyx/batch-size bs}))
(defn in-datomic
[task-name {:keys [db-uri t batch-size max-peers datoms-per-segment]
:or {datoms-per-segment 20
max-peers 1
t nil}}]
{:pre [((complement nil?) db-uri)
((complement nil?) batch-size)]}
{:onyx/name task-name
:onyx/plugin :onyx.plugin.datomic/read-datoms
:onyx/type :input
:onyx/medium :datomic
:datomic/uri db-uri
:datomic/t t
:datomic/datoms-index :eavt
:datomic/datoms-per-segment datoms-per-segment
:onyx/max-peers max-peers
:onyx/batch-size batch-size})
(defn out-async
([name] (out-async name {}))
([name {bs :batch-size peers :peers :or {peers 1 bs 1}}]
{:onyx/name name
:onyx/plugin :onyx.plugin.core-async/output
:onyx/type :output
:onyx/medium :core.async
:onyx/max-peers peers
:onyx/batch-size bs}))
(defn out-datomic
[task-name part {:keys [db-uri batch-size]}]
{:onyx/name task-name
:onyx/plugin :onyx.plugin.datomic/write-bulk-datoms
:onyx/type :output
:onyx/medium :datomic
:datomic/uri db-uri
:datomic/partition part
:onyx/batch-size batch-size})
(defn condition [namespace from to predicate]
{:flow/from from
:flow/to to
:flow/predicate (full-fn-name namespace predicate)})
+75
View File
@@ -0,0 +1,75 @@
(ns narjure.memory.schema
(:require [datomic-schema.schema :as sc]))
(def task
(sc/schema task
(sc/fields
[task-type :enum [:judgement :goal :question :quest]]
[evidences :long :many]
[eternal :boolean]
[occurrence-time :long]
[truth-value :ref :one :component]
[desire-value :ref :one :component])))
(def truth-value
(sc/schema truth-value
(sc/fields
[frequence :float]
[confidence :float])))
(def desire-value
(sc/schema desire-value
(sc/fields
[plausibility :float]
[desirability :float])))
(def dbschema
[task
desire-value
truth-value
(sc/schema concept
(sc/fields
[term :string :unique-identity]
[belief :ref :many :component]
[goal :ref :many :component]
[task-link :ref :many :component]
[term-link :ref :many :component]
[budget :ref :one :component]))
(sc/schema belief
(sc/fields
[evidences :long :many]
[eternal :boolean]
[occurrence-time :long]
[truth-value :ref :one :component]))
(sc/schema goal
(sc/fields
[evidences :long :many]
[eternal :boolean]
[occurrence-time :long]
[desire-value :ref :one :component]))
(sc/schema task-link
(sc/fields
[budget :ref :one :component]
[task :ref :one]))
(sc/schema term-link
(sc/fields
[budget :ref :one :component]
[concept :ref :one]))
(sc/schema budget
(sc/fields
[priority :float]
[durability :float]
[quality :float]))])
(def schema
(sc/generate-schema dbschema))
(def schema-onyx
(sc/generate-schema [task desire-value truth-value]))
+26
View File
@@ -0,0 +1,26 @@
(ns narjure.system
(:require
[system.core :refer [defsystem]]
[environ.core :refer [env]]
[narjure.components
[datomic :refer [new-datomic-db]]
[deriver :refer [new-deriver]]
[onyx :refer [new-onyx]]
[task-processing-job :refer [new-task-processing-job]]]
[com.stuartsierra.component :as component]
[reloaded.repl :as repl :refer [go system reset]]
[clojure.edn :as e]
[narjure.memory.schema :as s]))
(defsystem dev-system
[:datomic (new-datomic-db (env :db-uri) s/schema)
:datomic-onyx (new-datomic-db (env :db-uri-onyx) s/schema-onyx)
:deriver (new-deriver)
:onyx (new-onyx (e/read-string (env :zookeeper)))
:task-processing (component/using
(new-task-processing-job (env :db-uri) (env :db-uri-onyx))
[:onyx])])
(defn init-dev! []
(repl/set-init! dev-system)
(go))
+52 -46
View File
@@ -1,9 +1,15 @@
(ns nal.test.core
(:require [clojure.test :refer :all]
[nal.core :refer :all]))
[nal.core :refer :all]
[nal.deriver.rules :refer [compile-rules]]
[nal.rules :as r]
[environ.core]
[narjure.system :as s]))
(def rules (compile-rules r/all-rules))
(deftest test-inference
(are [a1 a2] (= (set a1) (set (apply inference a2)))
(are [a1 a2] (= (set a1) (set (apply inference rules a2)))
'({:statement [==>
[&| [--> [ext-set tim] [int-set driving]]]
@@ -27,26 +33,26 @@
:task-type :judgement
:truth [1.0
0.81]}
{:occurrence 1
:statement [--> a1 [ext-image m _ a2 a3]]
:task-type :judgement
:truth [1
0.9]}
{:occurrence 1
:statement [<|> a1 [--> [* a1 a2 a3] m]]
:task-type :judgement
:truth [1.0
0.44751381215469616]}
{:occurrence 1
:statement [=|> [--> [* a1 a2 a3] m] a1]
:task-type :judgement
:truth [1
0.44751381215469616]}
{:occurrence 1
:statement [=|> a1 [--> [* a1 a2 a3] m]]
:task-type :judgement
:truth [1
0.44751381215469616]})
{:occurrence 1
:statement [--> a1 [ext-image m _ a2 a3]]
:task-type :judgement
:truth [1
0.9]}
{:occurrence 1
:statement [<|> a1 [--> [* a1 a2 a3] m]]
:task-type :judgement
:truth [1.0
0.44751381215469616]}
{:occurrence 1
:statement [=|> [--> [* a1 a2 a3] m] a1]
:task-type :judgement
:truth [1
0.44751381215469616]}
{:occurrence 1
:statement [=|> a1 [--> [* a1 a2 a3] m]]
:task-type :judgement
:truth [1
0.44751381215469616]})
'[{:statement [--> [* a1 a2 a3] m]
:truth [1 0.9]
:task-type :judgement
@@ -85,24 +91,24 @@
:statement [&| a1 [conj a1 a2 a3]]
:task-type :judgement
:truth [1.0 0.81]}
{:occurrence 1
:statement [<|> a1 [conj a1 a2 a3]]
:task-type :judgement
:truth [1.0 0.44751381215469616]}
{:occurrence 1
:statement [=|> [conj a1 a2 a3] a1]
:task-type :judgement
:truth [1
0.44751381215469616]}
{:occurrence 1
:statement [=|> a1 [conj a1 a2 a3]]
:task-type :judgement
:truth [1
0.44751381215469616]}
{:occurrence 1
:statement a1
:task-type :judgement
:truth [1 0.44751381215469616]})
{:occurrence 1
:statement [<|> a1 [conj a1 a2 a3]]
:task-type :judgement
:truth [1.0 0.44751381215469616]}
{:occurrence 1
:statement [=|> [conj a1 a2 a3] a1]
:task-type :judgement
:truth [1
0.44751381215469616]}
{:occurrence 1
:statement [=|> a1 [conj a1 a2 a3]]
:task-type :judgement
:truth [1
0.44751381215469616]}
{:occurrence 1
:statement a1
:task-type :judgement
:truth [1 0.44751381215469616]})
'[{:statement [conj a1 a2 a3]
:truth [1 0.9]
:task-type :judgement
@@ -142,12 +148,12 @@
:truth [1.0 0.81]
:task-type :judgement
:occurrence 1}
{:statement [==>
[conj [--> [ext-set A] [int-set Y]] [--> [ind-var X] [int-set B]]]
[--> [ind-var X] P]]
:truth [1 0.44751381215469616]
:task-type :judgement
:occurrence 1})
{:statement [==>
[conj [--> [ext-set A] [int-set Y]] [--> [ind-var X] [int-set B]]]
[--> [ind-var X] P]]
:truth [1 0.44751381215469616]
:task-type :judgement
:occurrence 1})
'[{:statement [==> [--> [ext-set A] [int-set Y]] [--> [ext-set A] P]]
:truth [1 0.9]
:task-type :judgement
+10 -105
View File
@@ -1,116 +1,21 @@
(ns nal.test.deriver
(:require [clojure.test :refer :all]
[nal.deriver :refer :all]
[nal.deriver.rules :refer [compile-rules]]
[nal.rules :as r]))
(def result
'({:statement [</>
[seq-conj [--> chess competition] [:interval 1000]]
[--> sport competition]],
:task-type :judgement,
:occurrence 1000,
:truth [1.0 0.44751381215469616]}
{:statement [seq-conj
[--> chess competition]
[:interval 1000]
[--> sport competition]],
:task-type :judgement,
:occurrence 1000,
:truth [1.0 0.81]}
{:statement [pred-impl
[seq-conj [--> chess competition] [:interval 1000]]
[--> sport competition]],
:task-type :judgement,
:occurrence 1000,
:truth [1 0.44751381215469616]}
{:statement [retro-impl
[--> sport competition]
[seq-conj [--> chess competition] [:interval 1000]]],
:task-type :judgement,
:occurrence 1000,
:truth [1 0.44751381215469616]}
{:statement [--> sport chess],
:task-type :judgement,
:occurrence 1000,
:truth [1 0.44751381215469616]}
{:statement [--> chess sport],
:task-type :judgement,
:occurrence 1000,
:truth [1 0.44751381215469616]}
{:statement [<=> [--> chess [ind-var X]] [--> sport [ind-var X]]],
:task-type :judgement,
:occurrence 1000,
:truth [1.0 0.44751381215469616]}
{:statement [conj [--> chess [dep-var Y]] [--> sport [dep-var Y]]],
:task-type :judgement,
:occurrence 1000,
:truth [1.0 0.81]}
{:statement [<-> sport chess],
:task-type :judgement,
:occurrence 1000,
:truth [1.0 0.44751381215469616]}
{:statement [==> [--> chess [ind-var X]] [--> sport [ind-var X]]],
:task-type :judgement,
:occurrence 1000,
:truth [1 0.44751381215469616]}
{:statement [==> [--> chess [ind-var X]] [--> sport [ind-var X]]],
:task-type :judgement,
:occurrence 1000,
:truth [1 0.44751381215469616]}
{:statement [==> [--> sport [ind-var X]] [--> chess [ind-var X]]],
:task-type :judgement,
:occurrence 1000,
:truth [1 0.44751381215469616]}
{:statement [==> [--> sport [ind-var X]] [--> chess [ind-var X]]],
:task-type :judgement,
:occurrence 1000,
:truth [1 0.44751381215469616]}
{:statement [--> [int-dif chess sport] competition],
:task-type :judgement,
:occurrence 1000,
:truth [0.0 0.81]}
{:statement [--> [| chess sport] competition],
:task-type :judgement,
:occurrence 1000,
:truth [1.0 0.81]}
{:statement [--> [int-dif sport chess] competition],
:task-type :judgement,
:occurrence 1000,
:truth [0.0 0.81]}
{:statement [--> [ext-inter chess sport] competition],
:task-type :judgement,
:occurrence 1000,
:truth [1.0 0.81]}
{:statement [pred-impl
[seq-conj [--> chess [ind-var X]] [:interval 1000]]
[--> sport [ind-var X]]],
:task-type :judgement,
:occurrence 1000,
:truth [1 0.44751381215469616]}
{:statement [</>
[seq-conj [--> chess [ind-var X]] [:interval 1000]]
[--> sport [ind-var X]]],
:task-type :judgement,
:occurrence 1000,
:truth [1.0 0.44751381215469616]}
{:statement [retro-impl
[--> sport [ind-var X]]
[seq-conj [--> chess [ind-var X]] [:interval 1000]]],
:task-type :judgement,
:occurrence 1000,
:truth [1 0.44751381215469616]}
{:statement [seq-conj
[--> chess [dep-var Y]]
[:interval 1000]
[--> sport [dep-var Y]]],
:task-type :judgement,
:occurrence 1000,
:truth [1.0 0.81]}))
(def rules
(compile-rules '([(P --> M) (S --> M) |- (S <-> P)
:post (:t/comparison :d/weak :allow-backward)
:pre ((:!= S P))])))
(deftest test-generate-conclusions
(is (= (set result)
(is (= (set [{:occurrence 1000
:statement '[<-> sport chess]
:task-type :judgement
:truth [1.0 0.44751381215469616]}])
(set (generate-conclusions
(r/rules :judgement)
(rules :judgement)
'{:statement [--> sport competition]
:truth [1 0.9]
:task-type :judgement