Search in sources :

Example 21 with Stamp

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

the class InternalExperience method beliefReason.

/**
 * used in full internal experience mode only
 */
protected void beliefReason(Sentence belief, Term beliefTerm, Term taskTerm, DerivationContext nal) {
    Memory memory = nal.memory;
    if (Memory.randomNumber.nextDouble() < INTERNAL_EXPERIENCE_RARE_PROBABILITY) {
        // the operators which dont have a innate belief
        // also get a chance to reveal its effects to the system this way
        Operator op = memory.getOperator(nonInnateBeliefOperators[Memory.randomNumber.nextInt(nonInnateBeliefOperators.length)]);
        Product prod = new Product(new Term[] { belief.term });
        if (op != null && prod != null) {
            Term new_term = Inheritance.make(prod, op);
            Sentence sentence = new Sentence(new_term, Symbols.GOAL_MARK, // a naming convension
            new TruthValue(1, Parameters.DEFAULT_JUDGMENT_CONFIDENCE), new Stamp(memory));
            float quality = BudgetFunctions.truthToQuality(sentence.truth);
            BudgetValue budget = new BudgetValue(Parameters.DEFAULT_GOAL_PRIORITY * INTERNAL_EXPERIENCE_PRIORITY_MUL, Parameters.DEFAULT_GOAL_DURABILITY * INTERNAL_EXPERIENCE_DURABILITY_MUL, quality);
            Task newTask = new Task(sentence, budget, true);
            nal.derivedTask(newTask, false, false, false);
        }
    }
    if (beliefTerm instanceof Implication && Memory.randomNumber.nextDouble() <= INTERNAL_EXPERIENCE_PROBABILITY) {
        Implication imp = (Implication) beliefTerm;
        if (imp.getTemporalOrder() == TemporalRules.ORDER_FORWARD) {
            // 1. check if its (&/,term,+i1,...,+in) =/> anticipateTerm form:
            boolean valid = true;
            if (imp.getSubject() instanceof Conjunction) {
                Conjunction conj = (Conjunction) imp.getSubject();
                if (!conj.term[0].equals(taskTerm)) {
                    // the expected needed term is not included
                    valid = false;
                }
                for (int i = 1; i < conj.term.length; i++) {
                    if (!(conj.term[i] instanceof Interval)) {
                        valid = false;
                        break;
                    }
                }
            } else {
                if (!imp.getSubject().equals(taskTerm)) {
                    valid = false;
                }
            }
            if (valid) {
                Operator op = memory.getOperator("^anticipate");
                if (op == null)
                    throw new RuntimeException(this + " requires ^anticipate operator");
                Product args = new Product(new Term[] { imp.getPredicate() });
                Term new_term = Operation.make(args, op);
                Sentence sentence = new Sentence(new_term, Symbols.GOAL_MARK, // a naming convension
                new TruthValue(1, Parameters.DEFAULT_JUDGMENT_CONFIDENCE), new Stamp(memory));
                float quality = BudgetFunctions.truthToQuality(sentence.truth);
                BudgetValue budget = new BudgetValue(Parameters.DEFAULT_GOAL_PRIORITY * INTERNAL_EXPERIENCE_PRIORITY_MUL, Parameters.DEFAULT_GOAL_DURABILITY * INTERNAL_EXPERIENCE_DURABILITY_MUL, quality);
                Task newTask = new Task(sentence, budget, true);
                nal.derivedTask(newTask, false, false, false);
            }
        }
    }
}
Also used : Operator(nars.operator.Operator) BudgetValue(nars.entity.BudgetValue) Task(nars.entity.Task) Stamp(nars.entity.Stamp) Memory(nars.storage.Memory) Product(nars.language.Product) Term(nars.language.Term) Implication(nars.language.Implication) TruthValue(nars.entity.TruthValue) Conjunction(nars.language.Conjunction) Sentence(nars.entity.Sentence) Interval(nars.language.Interval)

Example 22 with Stamp

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

the class Memory method executedTask.

/**
 * ExecutedTask called in Operator.call
 *
 * @param operation The operation just executed
 */
public void executedTask(final Operation operation, TruthValue truth) {
    Task opTask = operation.getTask();
    // logic.TASK_EXECUTED.commit(opTask.budget.getPriority());
    Stamp stamp = new Stamp(this, Tense.Present);
    Sentence sentence = new Sentence(operation, Symbols.JUDGMENT_MARK, truth, stamp);
    Task task = new Task(sentence, new BudgetValue(Parameters.DEFAULT_FEEDBACK_PRIORITY, Parameters.DEFAULT_FEEDBACK_DURABILITY, truthToQuality(sentence.getTruth())), true);
    task.setElemOfSequenceBuffer(true);
    addNewTask(task, "Executed");
}
Also used : BudgetValue(nars.entity.BudgetValue) Task(nars.entity.Task) Stamp(nars.entity.Stamp) Sentence(nars.entity.Sentence)

Example 23 with Stamp

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

the class RuleTables method goalFromQuestion.

private static void goalFromQuestion(final Task task, final Term taskTerm, final DerivationContext nal) {
    if (task.sentence.punctuation == Symbols.QUESTION_MARK && (taskTerm instanceof Implication || taskTerm instanceof Equivalence)) {
        // <a =/> b>? |- a!
        Term goalterm = null;
        Term goalterm2 = null;
        if (taskTerm instanceof Implication) {
            Implication imp = (Implication) taskTerm;
            if (imp.getTemporalOrder() != TemporalRules.ORDER_BACKWARD || imp.getTemporalOrder() == TemporalRules.ORDER_CONCURRENT) {
                if (!Parameters.CURIOSITY_FOR_OPERATOR_ONLY || imp.getSubject() instanceof Operation) {
                    goalterm = imp.getSubject();
                }
                if (goalterm instanceof Variable && goalterm.hasVarQuery() && (!Parameters.CURIOSITY_FOR_OPERATOR_ONLY || imp.getPredicate() instanceof Operation)) {
                    // overwrite, it is a how question, in case of <?how =/> b> it is b! which is desired
                    goalterm = imp.getPredicate();
                }
            } else if (imp.getTemporalOrder() == TemporalRules.ORDER_BACKWARD) {
                if (!Parameters.CURIOSITY_FOR_OPERATOR_ONLY || imp.getPredicate() instanceof Operation) {
                    goalterm = imp.getPredicate();
                }
                if (goalterm instanceof Variable && goalterm.hasVarQuery() && (!Parameters.CURIOSITY_FOR_OPERATOR_ONLY || imp.getSubject() instanceof Operation)) {
                    // overwrite, it is a how question, in case of <?how =/> b> it is b! which is desired
                    goalterm = imp.getSubject();
                }
            }
        } else if (taskTerm instanceof Equivalence) {
            Equivalence qu = (Equivalence) taskTerm;
            if (qu.getTemporalOrder() == TemporalRules.ORDER_FORWARD || qu.getTemporalOrder() == TemporalRules.ORDER_CONCURRENT) {
                if (!Parameters.CURIOSITY_FOR_OPERATOR_ONLY || qu.getSubject() instanceof Operation) {
                    goalterm = qu.getSubject();
                }
                if (!Parameters.CURIOSITY_FOR_OPERATOR_ONLY || qu.getPredicate() instanceof Operation) {
                    goalterm2 = qu.getPredicate();
                }
            }
        }
        TruthValue truth = new TruthValue(1.0f, Parameters.DEFAULT_GOAL_CONFIDENCE * Parameters.CURIOSITY_DESIRE_CONFIDENCE_MUL);
        if (goalterm != null && !(goalterm instanceof Variable) && goalterm instanceof CompoundTerm) {
            goalterm = ((CompoundTerm) goalterm).transformIndependentVariableToDependentVar((CompoundTerm) goalterm);
            Sentence sent = new Sentence(goalterm, Symbols.GOAL_MARK, truth, new Stamp(task.sentence.stamp, nal.memory.time()));
            nal.singlePremiseTask(sent, new BudgetValue(task.getPriority() * Parameters.CURIOSITY_DESIRE_PRIORITY_MUL, task.getDurability() * Parameters.CURIOSITY_DESIRE_DURABILITY_MUL, BudgetFunctions.truthToQuality(truth)));
        }
        if (goalterm2 != null && !(goalterm2 instanceof Variable) && goalterm2 instanceof CompoundTerm) {
            goalterm2 = ((CompoundTerm) goalterm).transformIndependentVariableToDependentVar((CompoundTerm) goalterm2);
            Sentence sent = new Sentence(goalterm2, Symbols.GOAL_MARK, truth.clone(), new Stamp(task.sentence.stamp, nal.memory.time()));
            nal.singlePremiseTask(sent, new BudgetValue(task.getPriority() * Parameters.CURIOSITY_DESIRE_PRIORITY_MUL, task.getDurability() * Parameters.CURIOSITY_DESIRE_DURABILITY_MUL, BudgetFunctions.truthToQuality(truth)));
        }
    }
}
Also used : CompoundTerm(nars.language.CompoundTerm) BudgetValue(nars.entity.BudgetValue) Variable(nars.language.Variable) Equivalence(nars.language.Equivalence) Stamp(nars.entity.Stamp) TruthValue(nars.entity.TruthValue) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) Operation(nars.operator.Operation) Implication(nars.language.Implication) Sentence(nars.entity.Sentence)

Example 24 with Stamp

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

the class Anticipate method deriveDidntHappen.

protected void deriveDidntHappen(Term aTerm, long expectedOccurenceTime) {
    TruthValue truth = expiredTruth;
    BudgetValue budget = expiredBudget;
    Stamp stamp = new Stamp(nal.memory);
    // stamp.setOccurrenceTime(nal.memory.time());
    // it did not happen, so the time of when it did not
    stamp.setOccurrenceTime(expectedOccurenceTime);
    // happen is exactly the time it was expected
    Sentence S = new Sentence(aTerm, Symbols.JUDGMENT_MARK, truth, stamp);
    Task task = new Task(S, budget, true);
    nal.derivedTask(task, false, true, false);
    task.setElemOfSequenceBuffer(true);
    nal.memory.emit(DISAPPOINT.class, task);
}
Also used : BudgetValue(nars.entity.BudgetValue) Task(nars.entity.Task) Stamp(nars.entity.Stamp) TruthValue(nars.entity.TruthValue) Sentence(nars.entity.Sentence)

Example 25 with Stamp

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

the class NAR method askNow.

public NAR askNow(String termString, AnswerHandler answered) throws InvalidInputException {
    Task t;
    addInput(t = new Task(new Sentence(new Narsese(this).parseTerm(termString), Symbols.QUESTION_MARK, null, new Stamp(memory, Tense.Present)), new BudgetValue(Parameters.DEFAULT_QUESTION_PRIORITY, Parameters.DEFAULT_QUESTION_DURABILITY, 1), true));
    if (answered != null) {
        answered.start(t, this);
    }
    return this;
}
Also used : BudgetValue(nars.entity.BudgetValue) Task(nars.entity.Task) Stamp(nars.entity.Stamp) Narsese(nars.io.Narsese) Sentence(nars.entity.Sentence)

Aggregations

Stamp (nars.entity.Stamp)28 Sentence (nars.entity.Sentence)25 Task (nars.entity.Task)25 BudgetValue (nars.entity.BudgetValue)22 TruthValue (nars.entity.TruthValue)18 Term (nars.language.Term)17 Interval (nars.language.Interval)5 Implication (nars.language.Implication)4 Variable (nars.language.Variable)4 Operation (nars.operator.Operation)4 ArrayList (java.util.ArrayList)3 CompoundTerm (nars.language.CompoundTerm)3 Conjunction (nars.language.Conjunction)3 Inheritance (nars.language.Inheritance)3 Concept (nars.entity.Concept)2 Narsese (nars.io.Narsese)2 Events (nars.io.events.Events)2 Equivalence (nars.language.Equivalence)2 Product (nars.language.Product)2 Memory (nars.storage.Memory)2