Compare commits
6
Commits
rule-names
...
grammar
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
17e5249d31 | ||
|
|
7dbcf24e7b | ||
|
|
9ff12f3f98 | ||
|
|
05d6953e76 | ||
|
|
54c88af81e | ||
|
|
9324907f24 |
+11
-7
@@ -5,7 +5,7 @@
|
||||
sentence ::= statement"." [tense] [truth] (* judgement to be remembered *)
|
||||
| statement"?" [tense] [truth] (* question to be answered, tense added in OpenNARS 1.7 *)
|
||||
| statement"@" [tense] [truth] (* question on desire value to be answered, tense added in OpenNARS 1.7 *)
|
||||
| statement"!" [tense] [truth] (* goal to be realized, tense added in OpenNARS 1.7 *)
|
||||
| statement"!" [tense] [desire] (* goal to be realized, tense added in OpenNARS 1.7 *)
|
||||
|
||||
statement ::= <"<">term copula term<">"> (* two terms related to each other *)
|
||||
| <"(">term copula term<")"> (* two terms related to each other, new notation *)
|
||||
@@ -15,15 +15,15 @@
|
||||
|
||||
copula ::= "-->" (* inheritance *)
|
||||
| "<->" (* similarity *)
|
||||
| "{--" (* instance *)
|
||||
| "--]" (* property *)
|
||||
| "{-]" (* instance-property *)
|
||||
| "{--" (* o-- instance *)
|
||||
| "--]" (* --o property *)
|
||||
| "{-]" (* o-o instance-property *)
|
||||
| "==>" (* implication *)
|
||||
| "=/>" (* predictive implication *)
|
||||
| "=/>" (* =+> predictive implication *)
|
||||
| "=|>" (* concurrent implication *)
|
||||
| "=\\>" (* =\> retrospective implication *)
|
||||
| "=\\>" (* =-> retrospective implication *)
|
||||
| "<=>" (* equivalence *)
|
||||
| "</>" (* predictive equivalence *)
|
||||
| "</>" (* <+> predictive equivalence *)
|
||||
| "<|>" (* concurrent equivalence *)
|
||||
|
||||
term ::= word (* an atomic constant term *)
|
||||
@@ -72,6 +72,7 @@
|
||||
interval ::= <"/">#"\d+" (* integer *)
|
||||
|
||||
truth ::= <"%">frequency[<";">confidence]<"%"> (* two numbers in [0,1]x(0,1) *)
|
||||
desire ::= <"%">plausibility[<";">desirability]<"%"> (* two numbers in [0,1]x(0,1) *)
|
||||
budget ::= <"$">priority[<";">durability][<";">quality]<"$"> (* three numbers in [0,1]x(0,1)x[0,1] *)
|
||||
|
||||
word : #"\w+" (* unicode string *)
|
||||
@@ -80,3 +81,6 @@
|
||||
quality : #"([0]?\.[0-9]+|1\.[0]*|1|0)" (* 0 <= x <= 1 *)
|
||||
frequency : #"([0]?\.[0-9]+|1\.[0]*|1|0)" (* 0 <= x <= 1 *)
|
||||
confidence : #"[0]?\.[0]*[1-9]{1}[0-9]*" (* 0 < x < 1 *)
|
||||
plausibility : #"([0]?\.[0-9]+|1\.[0]*|1|0)" (* 0 <= x <= 1 *)
|
||||
desirability : #"[0]?\.[0]*[1-9]{1}[0-9]*" (* 0 < x < 1 *)
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@
|
||||
(update-in c [:answers q] choice-with-nil belief))
|
||||
concept questions))
|
||||
|
||||
(defmulti task->concept (fn [& args] (:action (first args))))
|
||||
(defmulti task->concept (fn [& args] (:task-type (first args))))
|
||||
|
||||
(defmethod task->concept :question
|
||||
[{:keys [statement] :as task} {:keys [concepts] :as m} term]
|
||||
|
||||
+33
-14
@@ -40,16 +40,23 @@
|
||||
"&/" 'sequential-events
|
||||
"&|" 'parallel-events})
|
||||
|
||||
(def tenses
|
||||
{":|:" :present
|
||||
":/:" :future
|
||||
":\\:" :past})
|
||||
|
||||
(defn get-compound-term [[_ operator-srt]]
|
||||
(compound-terms operator-srt))
|
||||
|
||||
(def actions {"." :judgement
|
||||
"?" :question})
|
||||
(def task-types {"." :judgement
|
||||
"?" :question})
|
||||
|
||||
(def ^:dynamic *action* (atom nil))
|
||||
(def ^:dynamic *task-type* (atom nil))
|
||||
(def ^:dynamic *lvars* (atom []))
|
||||
(def ^:dynamic *truth* (atom []))
|
||||
(def ^:dynamic *budget* (atom []))
|
||||
(def ^:dynamic *tense* (atom :present))
|
||||
(def ^:dynamic *syntactic-complexity* nil)
|
||||
|
||||
(defn keep-cat [fun col]
|
||||
(into [] (comp (mapcat fun) (filter (complement nil?))) col))
|
||||
@@ -64,16 +71,20 @@
|
||||
|
||||
(defmethod element :sentence [[_ & data]]
|
||||
(let [filtered (group-by string? data)]
|
||||
(reset! *action* (actions (first (filtered true))))
|
||||
(reset! *task-type* (task-types (first (filtered true))))
|
||||
(let [cols (filtered false)
|
||||
last-el (last cols)]
|
||||
(when (= :truth (first last-el))
|
||||
(element last-el))
|
||||
(when-let [tense (some #(when (= :tense (first %)) %) data)]
|
||||
(element tense))
|
||||
(element (first cols)))))
|
||||
|
||||
(defmethod element :statement [[_ & data]]
|
||||
(if-let [copula (get-copula data)]
|
||||
`[~copula ~@(keep-cat element data)]
|
||||
(do
|
||||
(swap! *syntactic-complexity* inc)
|
||||
`[~copula ~@(keep-cat element data)])
|
||||
(keep-cat element data)))
|
||||
|
||||
(defmethod element :task [[_ & data]]
|
||||
@@ -125,9 +136,13 @@
|
||||
(element (last data)))
|
||||
|
||||
(defmethod element :term [[_ & data]]
|
||||
(swap! *syntactic-complexity* inc)
|
||||
(when (seq? data)
|
||||
(keep element data)))
|
||||
|
||||
(defmethod element :tense [[_ key]]
|
||||
(reset! *tense* (tenses key)))
|
||||
|
||||
(defmethod element :default [_])
|
||||
|
||||
;TODO check for variables in statemnts, ignore subterm if it contains variable
|
||||
@@ -148,16 +163,20 @@
|
||||
[narsese-str]
|
||||
(let [data (parser narsese-str)]
|
||||
(if-not (i/failure? data)
|
||||
(binding [*action* (atom nil)
|
||||
(binding [*task-type* (atom nil)
|
||||
*lvars* (atom [])
|
||||
*truth* (atom [])
|
||||
*budget* (atom [])]
|
||||
*budget* (atom [])
|
||||
*tense* (atom :present)
|
||||
*syntactic-complexity* (atom 0)]
|
||||
(let [statement (element data)
|
||||
act @*action*]
|
||||
{:action act
|
||||
:lvars @*lvars*
|
||||
:truth (check-truth-value @*truth*)
|
||||
:budget (check-budget @*budget* act)
|
||||
:statement statement
|
||||
:terms (terms statement)}))
|
||||
act @*task-type*]
|
||||
{:task-type act
|
||||
:lvars @*lvars*
|
||||
:truth (check-truth-value @*truth*)
|
||||
:budget (check-budget @*budget* act)
|
||||
:statement statement
|
||||
:tense @*tense*
|
||||
:syntactic-complexity @*syntactic-complexity*
|
||||
:terms (terms statement)}))
|
||||
data)))
|
||||
|
||||
Reference in New Issue
Block a user