From bd0e74dd7db1d255cb277e48a00b84c40484e724 Mon Sep 17 00:00:00 2001
From: Patrick Hammer <patham9@gmail.com>
Date: Tue, 27 Mar 2018 16:36:07 -0400
Subject: [PATCH] Xiang's work on emotions such as fear, anger, regret etc.

---
 .../nars/plugin/mental/ComplexEmotions.java   | 81 +++++++++++++++++++
 1 file changed, 81 insertions(+)
 create mode 100644 nars_core/nars/plugin/mental/ComplexEmotions.java

diff --git a/nars_core/nars/plugin/mental/ComplexEmotions.java b/nars_core/nars/plugin/mental/ComplexEmotions.java
new file mode 100644
index 0000000000..fa77a75531
--- /dev/null
+++ b/nars_core/nars/plugin/mental/ComplexEmotions.java
@@ -0,0 +1,81 @@
+/*
+ * Here comes the text of your license
+ * Each line should be prefixed with  * 
+ */
+package nars.plugin.mental;
+
+import nars.entity.Concept;
+import nars.entity.Task;
+import nars.io.events.EventEmitter;
+import nars.io.events.EventEmitter.EventObserver;
+import nars.io.events.Events;
+import nars.io.events.Events.Answer;
+import nars.io.events.OutputHandler;
+import nars.main.NAR;
+import nars.plugin.Plugin;
+import nars.storage.Memory;
+
+/**
+ *
+ * @author Patrick
+ */
+public class ComplexEmotions implements Plugin {
+
+    public EventEmitter.EventObserver obs;
+    @Override
+    public boolean setEnabled(NAR n, boolean enabled) {
+        if(enabled) {
+            
+            Memory memory = n.memory;
+        
+            if(obs==null) {
+                obs=new EventObserver() {
+                    @Override
+                    public void event(Class event, Object[] a) {
+                        if (event != Events.TaskDerive.class &&
+                                event != Events.InduceSucceedingEvent.class)
+                            return;
+                        Task future_task = (Task)a[0];
+                        
+                        if(future_task.sentence.getOccurenceTime() > n.time()) {
+                            Concept c = n.memory.concept(future_task.getTerm());
+                            float true_expectation = 0.6f;
+                            float false_expectation = 0.4f;
+                            if(c != null) {
+                                if(c.desires.size() > 0 && c.beliefs.size() > 0) {
+                                    /*
+                                    want: a!
+                                    have a. :|:
+                                    believe it will stay that way: a. :/:
+                                    Happiness about a
+                                    */
+                                    if(c.desires.get(0).sentence.truth.getExpectation() > true_expectation) {
+                                        if(c.beliefs.get(0).sentence.truth.getExpectation() > true_expectation) {
+                                                if(future_task.sentence.truth.getExpectation() > true_expectation) {
+                                                        System.out.println("happy");
+                                                        n.addInput("<(*,{SELF},happy) --> ^feel>. :|:");
+                                                         memory.emit(Answer.class, "happy");
+                                                }
+                                        }
+                                    }
+                                    
+                                    if(c.desires.get(0).sentence.truth.getExpectation() < false_expectation) {
+                                        if(c.beliefs.get(0).sentence.truth.getExpectation() < false_expectation) {
+                                                if(future_task.sentence.truth.getExpectation() > true_expectation) {
+                                                        System.out.println("fear");
+                                                        n.addInput("<(*,{SELF},fear) --> ^feel>. :|:");
+                                                        memory.emit(Answer.class, "fear");
+                                                }
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    }
+                };
+            }
+            memory.event.set(obs, enabled, Events.InduceSucceedingEvent.class, Events.TaskDerive.class);
+        }
+        return true;
+    }
+}
-- 
GitLab