Details about the way Qwiery processes emotions can be found here.

The emotions engine is a dynamical system (a neural network actually) which can quickly give you a world of variations with little efforts. The input for the engine can be diverse:

  • inspecting the smileys as a way to update the social emotions
  • inspecting the topics discussed and relate them to a predefined goal
  • use the internal emotional state to output smileys
  • use the internal emotional dynamics as a way to render colors or images related to the state

How to use the engine can be seen from the following basic example (you can find diverse examples in the unit tests):

   var engine = new emo.Engine();
   var qwiery = engine.createAgent("Qwiery");
   var user = engine.createAgent("User");
   // Qwiery just wants to have fun, but it's a lasting search hence the isUnstable=true
   engine.createGoalForAgent('Qwiery', "Fun", 1, true);
   // having fun means talking about jokes and movies
   var jokes = new emo.Belief(1, "User", ["Fun"], [0.7], true);
   var movies = new emo.Belief(1, "User", ["Fun"], [0.5], true);
   // talking about books is no fun
   var books = new emo.Belief(1, "User", ["Fun"], [-0.8], true);
   qwiery.appraise(jokes);
   qwiery.appraise(jokes);
   qwiery.appraise(jokes);
   var joyHistory = qwiery.getEmotionalHistory("joy");
   console.log(joyHistory);
   qwiery.appraise(books);
   qwiery.appraise(books);
   qwiery.appraise(books);
   qwiery.appraise(books);
   var angerHistory = qwiery.getEmotionalHistory("anger");
   // talking about books wasnt so much fun
   console.log(angerHistory);
   qwiery.printEmotionalState(false);

After the engine has been instantiated:

  • two agents are created: Qwiery and a generic User
  • Qwiery wants to have fun and the utility set equal to one means this is essentially all it wants. You can add as many goals as you like. Goals on their own are not very meaningful unless they are connected to events and how intense these events relate to the goals. If your goal in life is to live in the Andromeda galaxy you will hardly ever be triggered by events related to that and, at least as far a the cognitive model is concerned, never have any emotional dynamics.
  • jokes and movies relate in a positive way to having fun. Qwiery believes that talking about books has a strong negative influence on fun.
  • after hitting a few time the ‘jokes’ trigger there will be joy
  • talking a bit about books will make Qwiery somewhat angry. The full emotional state (in plain English) can be fetched from the printEmotionalState method

In the processing pipeline the emotional engine is hooked up if the config has emotions set to true:

if(config.emotions && stack[0].Topics) {
        _.forEach(stack[0].Topics, function(topicName) {
            emotionalModule.appraise(topicName);
            emotionalModule.printEmotionalState();
         });
}

This means that Qwiery’s emotional dynamics will change in function of the topics discussed and the topics defined in the oracle stack of templates. Out of the box Qwiery will not do anything in particular with these emotions but it would take only few lines to, for example, add a smiley if the ‘joy’ is above a threshold:

 if(emotionalModule.qwiery.getCurrentEmotion('joy')>0.7){
   if(_.isString(envelope.Output.Answer){
           envelope.Output.Answer += ":)";
 }
}