Search in sources :

Example 16 with Term

use of nars.language.Term in project opennars by opennars.

the class MathExpression method getTerms.

public static Term getTerms(ExpressionValue[] data) {
    if (data.length == 1)
        return getTerm(data[0]);
    Term[] c = new Term[data.length];
    int j = 0;
    for (ExpressionValue t : data) {
        c[j++] = getTerm(t);
    }
    return new Product(c);
}
Also used : ExpressionValue(org.encog.ml.prg.expvalue.ExpressionValue) Product(nars.language.Product) Term(nars.language.Term)

Example 17 with Term

use of nars.language.Term in project opennars by opennars.

the class Reflect method sop.

public static Term sop(String operatorName, Term... t) {
    Term[] m = new Term[t.length];
    int i = 0;
    for (Term x : t) m[i++] = getMetaTerm(x);
    return Inheritance.make(Product.make(m), Term.get(operatorName));
}
Also used : CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term)

Example 18 with Term

use of nars.language.Term 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 19 with Term

use of nars.language.Term 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)

Example 20 with Term

use of nars.language.Term in project opennars by opennars.

the class InternalExperience method toTerm.

public static Term toTerm(final Sentence s, final Memory mem) {
    String opName;
    switch(s.punctuation) {
        case Symbols.JUDGMENT_MARK:
            opName = "^believe";
            if (!AllowWantBelieve) {
                return null;
            }
            break;
        case Symbols.GOAL_MARK:
            opName = "^want";
            if (!AllowWantBelieve) {
                return null;
            }
            break;
        case Symbols.QUESTION_MARK:
            opName = "^wonder";
            break;
        case Symbols.QUEST_MARK:
            opName = "^evaluate";
            break;
        default:
            return null;
    }
    Term opTerm = mem.getOperator(opName);
    Term[] arg = new Term[s.truth == null ? 2 : 3];
    arg[0] = Term.SELF;
    arg[1] = s.getTerm();
    if (s.truth != null) {
        arg[2] = s.projection(mem.time(), mem.time()).truth.toWordTerm();
    }
    // Operation.make ?
    Term operation = Inheritance.make(new Product(arg), opTerm);
    if (operation == null) {
        throw new RuntimeException("Unable to create Inheritance: " + opTerm + ", " + Arrays.toString(arg));
    }
    return operation;
}
Also used : Product(nars.language.Product) Term(nars.language.Term)

Aggregations

Term (nars.language.Term)109 CompoundTerm (nars.language.CompoundTerm)66 BudgetValue (nars.entity.BudgetValue)48 TruthValue (nars.entity.TruthValue)46 Sentence (nars.entity.Sentence)40 Task (nars.entity.Task)37 Statement (nars.language.Statement)28 Conjunction (nars.language.Conjunction)20 Inheritance (nars.language.Inheritance)19 Stamp (nars.entity.Stamp)17 Concept (nars.entity.Concept)14 Implication (nars.language.Implication)13 Product (nars.language.Product)11 NAR (nars.main.NAR)9 Interval (nars.language.Interval)8 Test (org.junit.Test)8 HashMap (java.util.HashMap)7 SetExt (nars.language.SetExt)7 SetInt (nars.language.SetInt)7 Variable (nars.language.Variable)7