Search in sources :

Example 11 with Task

use of nars.entity.Task in project opennars by opennars.

the class Wonder method execute.

/**
 * To create a question with a given statement
 * @param args Arguments, a Statement followed by an optional tense
 * @param memory The memory in which the operation is executed
 * @return Immediate results as Tasks
 */
@Override
protected ArrayList<Task> execute(Operation operation, Term[] args, Memory memory) {
    Term content = args[1];
    Sentence sentence = new Sentence(content, Symbols.QUESTION_MARK, null, new Stamp(memory));
    BudgetValue budget = new BudgetValue(Parameters.DEFAULT_QUESTION_PRIORITY, Parameters.DEFAULT_QUESTION_DURABILITY, 1);
    return Lists.newArrayList(new Task(sentence, budget, true));
}
Also used : BudgetValue(nars.entity.BudgetValue) Task(nars.entity.Task) Stamp(nars.entity.Stamp) Term(nars.language.Term) Sentence(nars.entity.Sentence)

Example 12 with Task

use of nars.entity.Task in project opennars by opennars.

the class Abbreviation method setEnabled.

@Override
public boolean setEnabled(final NAR n, final boolean enabled) {
    final Memory memory = n.memory;
    Operator _abbreviate = memory.getOperator("^abbreviate");
    if (_abbreviate == null) {
        _abbreviate = memory.addOperator(new Abbreviate());
    }
    final Operator abbreviate = _abbreviate;
    if (obs == null) {
        obs = new EventObserver() {

            @Override
            public void event(Class event, Object[] a) {
                if (event != TaskDerive.class)
                    return;
                if ((abbreviationProbability < 1.0) && (Memory.randomNumber.nextDouble() > abbreviationProbability))
                    return;
                Task task = (Task) a[0];
                // is it complex and also important? then give it a name:
                if (canAbbreviate(task)) {
                    Operation operation = Operation.make(abbreviate, termArray(task.sentence.term), false);
                    operation.setTask(task);
                    abbreviate.call(operation, memory);
                }
            }
        };
    }
    memory.event.set(obs, enabled, TaskDerive.class);
    return true;
}
Also used : Operator(nars.operator.Operator) EventObserver(nars.io.events.EventEmitter.EventObserver) Task(nars.entity.Task) Memory(nars.storage.Memory) TaskDerive(nars.io.events.Events.TaskDerive) Operation(nars.operator.Operation)

Example 13 with Task

use of nars.entity.Task in project opennars by opennars.

the class ComplexEmotions method setEnabled.

@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.5f;
                        float false_expectation = 0.5f;
                        if (c != null) {
                            if (c.desires.size() > 0 && c.beliefs.size() > 0) {
                                // Fear:
                                if (future_task.sentence.truth.getExpectation() > true_expectation && c.desires.get(0).sentence.truth.getExpectation() < false_expectation) {
                                    // n.addInput("<(*,{SELF},fear) --> ^feel>. :|:");
                                    float weight = future_task.getPriority();
                                    float fear = solutionQuality(true, c.desires.get(0), future_task.sentence, memory);
                                    float newValue = fear * weight;
                                    fear += newValue * weight;
                                    fear /= 1.0f + weight;
                                    // incrase concept priority by fear value:
                                    Concept C1 = memory.concept(future_task.getTerm());
                                    if (C1 != null) {
                                        C1.incPriority(fear);
                                    }
                                    memory.emit(Answer.class, "Fear value=" + fear);
                                    System.out.println("Fear value=" + fear);
                                }
                            }
                        }
                    }
                }
            };
        }
        memory.event.set(obs, enabled, Events.InduceSucceedingEvent.class, Events.TaskDerive.class);
    }
    return true;
}
Also used : EventObserver(nars.io.events.EventEmitter.EventObserver) Concept(nars.entity.Concept) Answer(nars.io.events.Events.Answer) Task(nars.entity.Task) Events(nars.io.events.Events) Memory(nars.storage.Memory)

Example 14 with Task

use of nars.entity.Task in project opennars by opennars.

the class Emotions method adjustBusy.

public void adjustBusy(float newValue, float weight, DerivationContext nal) {
    busy += newValue * weight;
    busy /= (1.0f + weight);
    if (!enabled) {
        return;
    }
    float frequency = -1;
    if (Math.abs(busy - lastbusy) > CHANGE_THRESHOLD && nal.memory.time() - last_busy_time > change_steps_demanded) {
        if (busy > Parameters.BUSY_EVENT_HIGHER_THRESHOLD && lastbusy <= Parameters.BUSY_EVENT_HIGHER_THRESHOLD) {
            frequency = 1.0f;
        }
        if (busy < Parameters.BUSY_EVENT_LOWER_THRESHOLD && lastbusy >= Parameters.BUSY_EVENT_LOWER_THRESHOLD) {
            frequency = 0.0f;
        }
        lastbusy = busy;
        last_busy_time = nal.memory.time();
    }
    if (frequency != -1) {
        // ok lets add an event now
        Term predicate = SetInt.make(new Term("busy"));
        Term subject = new Term("SELF");
        Inheritance inh = Inheritance.make(subject, predicate);
        TruthValue truth = new TruthValue(busy, Parameters.DEFAULT_JUDGMENT_CONFIDENCE);
        Sentence s = new Sentence(inh, Symbols.JUDGMENT_MARK, truth, new Stamp(nal.memory));
        s.stamp.setOccurrenceTime(nal.memory.time());
        Task t = new Task(s, new BudgetValue(Parameters.DEFAULT_JUDGMENT_PRIORITY, Parameters.DEFAULT_JUDGMENT_DURABILITY, BudgetFunctions.truthToQuality(truth)), true);
        nal.addTask(t, "emotion");
    }
}
Also used : BudgetValue(nars.entity.BudgetValue) Task(nars.entity.Task) Stamp(nars.entity.Stamp) TruthValue(nars.entity.TruthValue) Inheritance(nars.language.Inheritance) Term(nars.language.Term) Sentence(nars.entity.Sentence)

Example 15 with Task

use of nars.entity.Task in project opennars by opennars.

the class Emotions method adjustSatisfaction.

public void adjustSatisfaction(float newValue, float weight, DerivationContext nal) {
    // float oldV = happyValue;
    happy += newValue * weight;
    happy /= 1.0f + weight;
    if (!enabled) {
        return;
    }
    float frequency = -1;
    if (Math.abs(happy - lasthappy) > CHANGE_THRESHOLD && nal.memory.time() - last_happy_time > change_steps_demanded) {
        if (happy > Parameters.HAPPY_EVENT_HIGHER_THRESHOLD && lasthappy <= Parameters.HAPPY_EVENT_HIGHER_THRESHOLD) {
            frequency = 1.0f;
        }
        if (happy < Parameters.HAPPY_EVENT_LOWER_THRESHOLD && lasthappy >= Parameters.HAPPY_EVENT_LOWER_THRESHOLD) {
            frequency = 0.0f;
        }
        lasthappy = happy;
        last_happy_time = nal.memory.time();
    }
    if (frequency != -1) {
        // ok lets add an event now
        Term predicate = SetInt.make(new Term("satisfied"));
        Term subject = Term.SELF;
        Inheritance inh = Inheritance.make(subject, predicate);
        TruthValue truth = new TruthValue(happy, Parameters.DEFAULT_JUDGMENT_CONFIDENCE);
        Sentence s = new Sentence(inh, Symbols.JUDGMENT_MARK, truth, new Stamp(nal.memory));
        s.stamp.setOccurrenceTime(nal.memory.time());
        Task t = new Task(s, new BudgetValue(Parameters.DEFAULT_JUDGMENT_PRIORITY, Parameters.DEFAULT_JUDGMENT_DURABILITY, BudgetFunctions.truthToQuality(truth)), true);
        nal.addTask(t, "emotion");
    /*if(Parameters.REFLECT_META_HAPPY_GOAL) { //remind on the goal whenever happyness changes, should suffice for now
                TruthValue truth2=new TruthValue(1.0f,Parameters.DEFAULT_GOAL_CONFIDENCE);
                Sentence s2=new Sentence(inh,Symbols.GOAL_MARK,truth2,new Stamp(nal.memory));
                s2.stamp.setOccurrenceTime(nal.memory.time());
                Task t2=new Task(s2,new BudgetValue(Parameters.DEFAULT_GOAL_PRIORITY,Parameters.DEFAULT_GOAL_DURABILITY,BudgetFunctions.truthToQuality(truth2)));
                nal.addTask(t2, "metagoal");
                //this is a good candidate for innate belief for consider and remind:
                Operator consider=nal.memory.getOperator("^consider");
                Operator remind=nal.memory.getOperator("^remind");
                Term[] arg=new Term[1];
                arg[0]=inh;
                if(InternalExperience.enabled && Parameters.CONSIDER_REMIND) {
                    Operation op_consider=Operation.make(consider, arg, true);
                    Operation op_remind=Operation.make(remind, arg, true);
                    Operation[] op=new Operation[2];
                    op[0]=op_remind; //order important because usually reminding something
                    op[1]=op_consider; //means it has good chance to be considered after
                    for(Operation o : op) {
                        TruthValue truth3=new TruthValue(1.0f,Parameters.DEFAULT_JUDGMENT_CONFIDENCE);
                        Sentence s3=new Sentence(o,Symbols.JUDGMENT_MARK,truth3,new Stamp(nal.memory));
                        s3.stamp.setOccurrenceTime(nal.memory.time());

                        //INTERNAL_EXPERIENCE_DURABILITY_MUL
                        BudgetValue budget=new BudgetValue(Parameters.DEFAULT_JUDGMENT_PRIORITY,Parameters.DEFAULT_JUDGMENT_DURABILITY,BudgetFunctions.truthToQuality(truth3));
                        budget.setPriority(budget.getPriority()*InternalExperience.INTERNAL_EXPERIENCE_PRIORITY_MUL);
                        budget.setDurability(budget.getPriority()*InternalExperience.INTERNAL_EXPERIENCE_DURABILITY_MUL);
                        Task t3=new Task(s3,budget);
                        nal.addTask(t3, "internal experience for consider and remind");
                    }
                }
            }*/
    }
// if (Math.abs(oldV - happyValue) > 0.1) {
// Record.append("HAPPY: " + (int) (oldV*10.0) + " to " + (int) (happyValue*10.0) + "\n");
}
Also used : BudgetValue(nars.entity.BudgetValue) Task(nars.entity.Task) Stamp(nars.entity.Stamp) TruthValue(nars.entity.TruthValue) Inheritance(nars.language.Inheritance) Term(nars.language.Term) Sentence(nars.entity.Sentence)

Aggregations

Task (nars.entity.Task)78 Sentence (nars.entity.Sentence)54 Term (nars.language.Term)37 BudgetValue (nars.entity.BudgetValue)36 TruthValue (nars.entity.TruthValue)34 Stamp (nars.entity.Stamp)25 CompoundTerm (nars.language.CompoundTerm)21 Concept (nars.entity.Concept)18 Conjunction (nars.language.Conjunction)11 Statement (nars.language.Statement)10 Events (nars.io.events.Events)8 Inheritance (nars.language.Inheritance)8 Interval (nars.language.Interval)8 Narsese (nars.io.Narsese)6 SetExt (nars.language.SetExt)6 SetInt (nars.language.SetInt)6 ArrayList (java.util.ArrayList)5 DerivationContext (nars.control.DerivationContext)5 Implication (nars.language.Implication)5 Memory (nars.storage.Memory)5