Search in sources :

Example 36 with TruthValue

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

the class FunctionOperator method execute.

// abstract protected int getMinArity();
// abstract protected int getMaxArity();
@Override
protected ArrayList<Task> execute(Operation operation, Term[] args, Memory m) {
    // TODO make memory access optional by constructor argument
    // TODO allow access to NAR instance?
    int numArgs = args.length - 1;
    if (numArgs < 1) {
        throw new RuntimeException("Requires at least 1 arguments");
    }
    if (numArgs < 2) /*&& !(this instanceof Javascript)*/
    {
        throw new RuntimeException("Requires at least 2 arguments");
    }
    // last argument a variable?
    Term lastTerm = args[numArgs];
    boolean variable = lastTerm instanceof Variable;
    if (!variable) /*&& !(this instanceof Javascript)*/
    {
        throw new RuntimeException("output can not be specified");
    }
    int numParam = numArgs - 1;
    /*if(this instanceof Javascript && !variable) {
            numParam++;
        }*/
    Term[] x = new Term[numParam];
    System.arraycopy(args, 1, x, 0, numParam);
    Term y;
    // try {
    y = function(m, x);
    if (y == null) {
        return null;
    }
    /*if(!variable && this instanceof Javascript) {
                return null;
            }*/
    // m.emit(SynchronousFunctionOperator.class, Arrays.toString(x) + " | " + y);
    /*}
        catch (Exception e) {
            throw e;
        }*/
    Variable var = new Variable("$1");
    // Term actual_part = Similarity.make(var, y);
    // Variable vardep=new Variable("#1");
    // Term actual_dep_part = Similarity.make(vardep, y);
    operation = (Operation) operation.setComponent(0, ((CompoundTerm) operation.getSubject()).setComponent(numArgs, y, m), m);
    float confidence = Parameters.DEFAULT_JUDGMENT_CONFIDENCE;
    if (variable) {
        Sentence s = new Sentence(operation, Symbols.JUDGMENT_MARK, new TruthValue(1.0f, Parameters.DEFAULT_JUDGMENT_CONFIDENCE), new Stamp(m));
        return Lists.newArrayList(new Task(s, new BudgetValue(Parameters.DEFAULT_JUDGMENT_PRIORITY, Parameters.DEFAULT_FEEDBACK_DURABILITY, truthToQuality(s.getTruth())), true));
    } else {
        return null;
    }
}
Also used : BudgetValue(nars.entity.BudgetValue) Task(nars.entity.Task) Variable(nars.language.Variable) Stamp(nars.entity.Stamp) TruthValue(nars.entity.TruthValue) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) Sentence(nars.entity.Sentence)

Example 37 with TruthValue

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

the class Operator method call.

/**
 * The standard way to carry out an operation, which invokes the execute
 * method defined for the operator, and handles feedback tasks as input
 *
 * @param op The operator to be executed
 * @param args The arguments to be taken by the operator
 * @param memory The memory on which the operation is executed
 * @return true if successful, false if an error occurred
 */
public final boolean call(final Operation operation, final Term[] args, final Memory memory) {
    try {
        List<Task> feedback = execute(operation, args, memory);
        if (feedback == null || feedback.isEmpty()) {
            // null operator case
            memory.executedTask(operation, new TruthValue(1f, executionConfidence));
        }
        reportExecution(operation, args, feedback, memory);
        if (feedback != null) {
            for (final Task t : feedback) {
                memory.inputTask(t);
            }
        }
        return true;
    }// }
     catch (Exception e) {
    // reportExecution(operation, args, e, memory);
    }
    return false;
}
Also used : Task(nars.entity.Task) TruthValue(nars.entity.TruthValue)

Example 38 with TruthValue

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

the class Anticipate method anticipationFeedback.

public void anticipationFeedback(Term content, Task t, Memory memory) {
    if (anticipationOperator) {
        Operation op = (Operation) Operation.make(Product.make(Term.SELF, content), this);
        TruthValue truth = new TruthValue(1.0f, Parameters.DEFAULT_JUDGMENT_CONFIDENCE);
        Stamp st;
        if (t == null) {
            st = new Stamp(memory);
        } else {
            st = t.sentence.stamp.clone();
            st.setOccurrenceTime(memory.time());
        }
        Sentence s = new Sentence(op, Symbols.JUDGMENT_MARK, truth, st);
        Task newTask = new Task(s, new BudgetValue(Parameters.DEFAULT_JUDGMENT_PRIORITY * InternalExperience.INTERNAL_EXPERIENCE_PRIORITY_MUL, Parameters.DEFAULT_JUDGMENT_DURABILITY * InternalExperience.INTERNAL_EXPERIENCE_DURABILITY_MUL, BudgetFunctions.truthToQuality(truth)), true);
        memory.addNewTask(newTask, "Perceived (Internal Experience: Anticipation)");
    }
}
Also used : BudgetValue(nars.entity.BudgetValue) Task(nars.entity.Task) Stamp(nars.entity.Stamp) TruthValue(nars.entity.TruthValue) Operation(nars.operator.Operation) Sentence(nars.entity.Sentence)

Example 39 with TruthValue

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

the class Narsese method parseTask.

/**
 * Enter a new Task in String into the memory, called from InputWindow or
 * locally.
 *
 * @param s the single-line addInput String
 * @param memory Reference to the memory
 * @param time The current time
 * @return An experienced task
 */
public Task parseTask(String s) throws InvalidInputException {
    StringBuilder buffer = new StringBuilder(Texts.escape(s));
    String budgetString = getBudgetString(buffer);
    String truthString = getTruthString(buffer);
    Tense tense = parseTense(buffer);
    String str = buffer.toString().trim();
    int last = str.length() - 1;
    char punc = str.charAt(last);
    Stamp stamp = new Stamp(-1, /* if -1, will be set right before the Task is input */
    tense, memory.newStampSerial(), Parameters.DURATION);
    TruthValue truth = parseTruth(truthString, punc);
    Term content = parseTerm(str.substring(0, last));
    if (content == null)
        throw new InvalidInputException("Content term missing");
    Sentence sentence = new Sentence(content, punc, truth, stamp);
    // if ((content instanceof Conjunction) && Variable.containVarDep(content.getName())) {
    // sentence.setRevisible(false);
    // }
    BudgetValue budget = parseBudget(budgetString, punc, truth);
    Task task = new Task(sentence, budget, true);
    return task;
}
Also used : Tense(nars.language.Tense) BudgetValue(nars.entity.BudgetValue) Task(nars.entity.Task) Stamp(nars.entity.Stamp) TruthValue(nars.entity.TruthValue) Term(nars.language.Term) Sentence(nars.entity.Sentence)

Example 40 with TruthValue

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

the class BudgetFunctions method update.

/**
 * Update a belief
 *
 * @param task The task containing new belief
 * @param bTruth Truth value of the previous belief
 * @return Budget value of the updating task
 */
static BudgetValue update(final Task task, final TruthValue bTruth) {
    final TruthValue tTruth = task.sentence.truth;
    final float dif = tTruth.getExpDifAbs(bTruth);
    final float priority = or(dif, task.getPriority());
    final float durability = aveAri(dif, task.getDurability());
    final float quality = truthToQuality(bTruth);
    return new BudgetValue(priority, durability, quality);
}
Also used : BudgetValue(nars.entity.BudgetValue) TruthValue(nars.entity.TruthValue)

Aggregations

TruthValue (nars.entity.TruthValue)64 BudgetValue (nars.entity.BudgetValue)52 Term (nars.language.Term)46 Sentence (nars.entity.Sentence)39 CompoundTerm (nars.language.CompoundTerm)36 Task (nars.entity.Task)34 Statement (nars.language.Statement)20 Stamp (nars.entity.Stamp)18 Conjunction (nars.language.Conjunction)18 Inheritance (nars.language.Inheritance)12 Interval (nars.language.Interval)10 Implication (nars.language.Implication)9 Product (nars.language.Product)7 Variable (nars.language.Variable)7 Concept (nars.entity.Concept)5 SetExt (nars.language.SetExt)5 SetInt (nars.language.SetInt)5 Operation (nars.operator.Operation)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4