9 Commits
22 changed files with 225 additions and 569 deletions
-2
View File
@@ -12,8 +12,6 @@ pom.xml.asc
.idea
*.iml
*~
/onyx.log
/profiles.clj
\#*\#
.\#*
/src/nal/experiments.clj
-3
View File
@@ -1,3 +0,0 @@
machine:
java:
version: oraclejdk8
-11
View File
@@ -1,11 +0,0 @@
{: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"}}}
+3 -29
View File
@@ -9,40 +9,14 @@
[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.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"]]
[org.clojure/core.unify "0.5.5"]]
: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"]
[lein-environ "1.0.2"]]
[cider/cider-nrepl "0.11.0-SNAPSHOT"]]
:eastwood {:exclude-namespaces [nal.rules]}
:target-path "target/%s"
:repl-options {:init-ns narjure.repl
:nrepl-middleware [narjure.repl/narsese-handler]}
: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}})
:profiles {:uberjar {:aot :all}})
+2 -2
View File
@@ -7,8 +7,8 @@
(if (>= c1 c2) [f1 c1] [f2 c2]))
(defn inference
[rules {:keys [task-type] :as task} belief]
(generate-conclusions (rules task-type) task belief))
[{:keys [task-type] :as task} belief]
(generate-conclusions (r/rules task-type) task belief))
(def revision t/revision)
+1 -2
View File
@@ -8,8 +8,7 @@
(defn get-matcher [rules p1 p2]
(let [matchers (->> (mall-paths p1 p2)
(filter rules)
(map rules)
(map (fn [el] (:matcher el))))]
(map rules))]
(case (count matchers)
0 (constantly [])
1 (first matchers)
+14 -11
View File
@@ -1,7 +1,6 @@
(ns nal.deriver.matching
(:require
[nal.deriver.utils :refer [walk operator? not-operator?]]
[clojure.core.match :refer [match]]
[clojure.core.unify :as u]
[clojure.set :refer [map-invert intersection]]
[clojure.string :as s]
@@ -20,7 +19,7 @@
#{`= `not= `seq? `first `and `let `pos? `> `>= `< `<= `coll? `set `quote
`count 'aops `- `not-empty-diff? `not-empty-inter? `walk `munification-map
`substitute `sets `some `deref `do `vreset! `volatile! `fn `mapv `if
`sort-commutative `n/reduce-ext-inter `n/reduce-symilarity `complement
`sort-commutative `n/reduce-ext-inter `n/reduce-similarity `complement
`n/reduce-int-dif `n/reduce-and `n/reduce-ext-dif `n/reduce-image
`n/reduce-int-inter `n/reduce-neg `n/reduce-or `nil? `not `or `abs
`implications-and-equivalences `get-terms `empty? `intersection
@@ -68,19 +67,24 @@
(defn traverse-node
"Generates code for precondition node."
[vars result {:keys [conclusions children condition]}]
`(when ~(quote-operators condition)
~(when-not (zero? (count conclusions))
`(vswap! ~result concat
~@(set (map #(mapv (partial form-conclusion vars) %)
(quote-operators conclusions)))))
~@(map (fn [n] (traverse-node vars result n)) children)))
(let [conclusions (remove
nil?
[(when-not (zero? (count conclusions))
`(vswap! ~result concat
~@(set (map #(mapv (partial form-conclusion vars) %)
(quote-operators conclusions)))))])
children (mapcat (fn [n] (traverse-node vars result n)) children)]
(if (true? condition)
(concat conclusions children)
[`(when ~(quote-operators condition)
~@(concat conclusions children))])))
(defn traversal
"Walk through preconditions tree and generates code for matcher."
[vars tree]
(let [results (gensym)]
`(let [~results (volatile! [])]
~(traverse-node vars results tree)
~@(traverse-node vars results tree)
@~results)))
(defn replace-occurrences
@@ -341,6 +345,5 @@
match-fn-code (-> main-pattern
(gen-rules rules)
(match-rules main-pattern task-type))]
[k (assoc v :matcher (eval match-fn-code)
:matcher-code match-fn-code)])))
[k (eval match-fn-code)])))
(into {})))
+3 -3
View File
@@ -111,7 +111,7 @@
[_ ['ext-set & l1] ['ext-set & l2]] (diff 'ext-set l1 l2)
:else st))
(defn reduce-symilarity
(defn reduce-similarity
[st]
(m/match st
['<-> ['ext-set s] ['ext-set p]] ['<-> s p]
@@ -169,7 +169,7 @@
'| `reduce-int-inter
'- `reduce-ext-dif
'int-dif `reduce-int-dif
'<-> `reduce-symilarity
'<-> `reduce-similarity
'* `reduce-production
'int-image `reduce-image
'ext-image `reduce-image
@@ -185,7 +185,7 @@
| (reduce-int-inter st)
- (reduce-ext-dif st)
int-dif (reduce-int-dif st)
<-> (reduce-symilarity st)
<-> (reduce-similarity st)
* (reduce-production st)
int-image (reduce-image st)
ext-image (reduce-image st)
+25 -16
View File
@@ -57,6 +57,12 @@
[{:keys [pre]}]
(some #{:question?} pre))
(defn quest?
"Return true if rule allows only quest as task."
[{:keys [pre] [{post :post}] :conclusions}]
(and (some #{:question?} pre)
(every? #(not (#{:p/judgement} %)) post)))
(defn goal?
"Return true if rule allows only goal as task."
[{pre :pre [{post :post}] :conclusions}]
@@ -118,26 +124,29 @@
pairs)))
(defmacro defrules [name & rules]
"Define rules. Rules must be #R statements."
;TODO exception on duplication of the rule
`(def ~name (quote ~rules)))
(defn compile-rules
"Define rules. Rules must be #R statements."
;TODO exception on duplication of the rule
[& 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#))
(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))
quest-rules# (check-duplication (filter quest? rules))]
(println "Beliefs rules:" (count judgement-rules#))
(println "Questions rules:" (count question-rules#))
(println "Goal rules:" (count goal-rules#))
(println "Quests rules:" (count quest-rules#))
{:judgement (rules-map judgement-rules# :judgement)
:question (rules-map question-rules# :question)
:goal (rules-map goal-rules# :goal)})))
:goal (rules-map goal-rules# :goal)
:quest (rules-map quest-rules# :quest)})))
+3 -1
View File
@@ -108,6 +108,8 @@
(defn t-identity [p1 _] p1)
(defn d-identity [p1 _] p1)
(defn belief-identity [p1 p2] (when p2 p1))
(defn belief-structural-deduction [_ p2]
@@ -166,6 +168,6 @@
:d/deduction intersection
:d/weak desire-weak
:d/induction desire-induction
:d/identity identity
:d/identity d-identity
:d/negation negation
:d/structural-strong desire-structural-strong})
+23 -7
View File
@@ -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,4 +448,20 @@
#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)])
#R[(|| B :list/A) B |- (|| B :list/A) :pre (:question?) :post (:t/belief-structural-deduction :p/judgement)]
)
(def rules (compile-rules all-rules))
(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))))
-19
View File
@@ -1,19 +0,0 @@
(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
@@ -1,20 +0,0 @@
(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
@@ -1,30 +0,0 @@
(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}))
@@ -1,25 +0,0 @@
(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
@@ -1,13 +0,0 @@
(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
@@ -1,148 +0,0 @@
(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
@@ -1,64 +0,0 @@
(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
@@ -1,75 +0,0 @@
(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
@@ -1,26 +0,0 @@
(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))
+46 -52
View File
@@ -1,15 +1,9 @@
(ns nal.test.core
(:require [clojure.test :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))
[nal.core :refer :all]))
(deftest test-inference
(are [a1 a2] (= (set a1) (set (apply inference rules a2)))
(are [a1 a2] (= (set a1) (set (apply inference a2)))
'({:statement [==>
[&| [--> [ext-set tim] [int-set driving]]]
@@ -33,26 +27,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
@@ -91,24 +85,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
@@ -148,12 +142,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
+105 -10
View File
@@ -1,21 +1,116 @@
(ns nal.test.deriver
(:require [clojure.test :refer :all]
[nal.deriver :refer :all]
[nal.deriver.rules :refer [compile-rules]]
[nal.rules :as r]))
(def rules
(compile-rules '([(P --> M) (S --> M) |- (S <-> P)
:post (:t/comparison :d/weak :allow-backward)
:pre ((:!= S P))])))
(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]}))
(deftest test-generate-conclusions
(is (= (set [{:occurrence 1000
:statement '[<-> sport chess]
:task-type :judgement
:truth [1.0 0.44751381215469616]}])
(is (= (set result)
(set (generate-conclusions
(rules :judgement)
(r/rules :judgement)
'{:statement [--> sport competition]
:truth [1 0.9]
:task-type :judgement