Search in sources :

Example 66 with Task

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

the class StructuralRules method structuralDecompose2.

/**
 * {<(S*T) --> (P*T)>, S@(S*T)} |- <S --> P>
 *
 * @param statement The premise
 * @param nal Reference to the memory
 */
static void structuralDecompose2(Statement statement, int index, DerivationContext nal) {
    Term subj = statement.getSubject();
    Term pred = statement.getPredicate();
    if (subj.getClass() != pred.getClass()) {
        return;
    }
    if (!(subj instanceof Product) && !(subj instanceof SetExt) && !(subj instanceof SetInt)) {
        // no abduction on other compounds for now, but may change in the future
        return;
    }
    CompoundTerm sub = (CompoundTerm) subj;
    CompoundTerm pre = (CompoundTerm) pred;
    if (sub.size() != pre.size() || sub.size() <= index) {
        return;
    }
    Term t1 = sub.term[index];
    Term t2 = pre.term[index];
    Statement content;
    int order = statement.getTemporalOrder();
    if (switchOrder(sub, (short) index)) {
        content = Statement.make(statement, t2, t1, TemporalRules.reverseOrder(order));
    } else {
        content = Statement.make(statement, t1, t2, order);
    }
    if (content == null) {
        return;
    }
    Task task = nal.getCurrentTask();
    Sentence sentence = task.sentence;
    TruthValue truth = sentence.truth;
    BudgetValue budget;
    if (sentence.isQuestion() || sentence.isQuest()) {
        budget = BudgetFunctions.compoundBackward(content, nal);
    } else {
        budget = BudgetFunctions.compoundForward(truth, content, nal);
    }
    nal.singlePremiseTask(content, truth, budget);
}
Also used : CompoundTerm(nars.language.CompoundTerm) BudgetValue(nars.entity.BudgetValue) Task(nars.entity.Task) Statement(nars.language.Statement) TruthValue(nars.entity.TruthValue) SetExt(nars.language.SetExt) Product(nars.language.Product) SetInt(nars.language.SetInt) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) Sentence(nars.entity.Sentence)

Example 67 with Task

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

the class SyllogisticRules method elimiVarDep.

/**
 * {(&&, <#x() --> S>, <#x() --> P>>, <M --> P>} |- <M --> S>
 *
 * @param compound The compound term to be decomposed
 * @param component The part of the compound to be removed
 * @param compoundTask Whether the compound comes from the task
 * @param nal Reference to the memory
 */
static void elimiVarDep(CompoundTerm compound, Term component, boolean compoundTask, DerivationContext nal) {
    Term comp = null;
    for (Term t : compound) {
        Term[] unify = new Term[] { t, component };
        if (Variables.unify(Symbols.VAR_DEPENDENT, unify)) {
            comp = t;
            break;
        }
        if (Variables.unify(Symbols.VAR_QUERY, unify)) {
            comp = t;
            break;
        }
    }
    if (comp == null) {
        return;
    }
    Term content = reduceComponents(compound, comp, nal.mem());
    if ((content == null) || ((content instanceof Statement) && ((Statement) content).invalid())) {
        return;
    }
    Task task = nal.getCurrentTask();
    Sentence sentence = task.sentence;
    Sentence belief = nal.getCurrentBelief();
    TruthValue v1 = sentence.truth;
    TruthValue v2 = belief.truth;
    TruthValue truth = null;
    BudgetValue budget;
    if (sentence.isQuestion() || sentence.isQuest()) {
        budget = (compoundTask ? BudgetFunctions.backward(v2, nal) : BudgetFunctions.backwardWeak(v2, nal));
    } else {
        if (sentence.isGoal()) {
            // to check
            truth = (compoundTask ? TruthFunctions.desireDed(v1, v2) : TruthFunctions.desireInd(v1, v2));
        } else {
            truth = (compoundTask ? TruthFunctions.anonymousAnalogy(v1, v2) : TruthFunctions.anonymousAnalogy(v2, v1));
        }
        budget = BudgetFunctions.compoundForward(truth, content, nal);
    }
    nal.doublePremiseTask(content, truth, budget, false, false);
}
Also used : BudgetValue(nars.entity.BudgetValue) Task(nars.entity.Task) Statement(nars.language.Statement) TruthValue(nars.entity.TruthValue) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) Sentence(nars.entity.Sentence)

Example 68 with Task

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

the class Anticipate method event.

@Override
public void event(Class event, Object[] args) {
    if (event == Events.InduceSucceedingEvent.class || event == Events.TaskDerive.class) {
        Task newEvent = (Task) args[0];
        this.nal = (DerivationContext) args[1];
        if (newEvent.sentence.truth != null && newEvent.sentence.isJudgment() && newEvent.sentence.truth.getExpectation() > Parameters.DEFAULT_CONFIRMATION_EXPECTATION && !newEvent.sentence.isEternal()) {
            // new: always add but keep truth value in mind
            newTasks.add(newEvent.getTerm());
        }
    }
    if (nal != null && event == CycleEnd.class) {
        updateAnticipations();
    }
}
Also used : Task(nars.entity.Task) CycleEnd(nars.io.events.Events.CycleEnd)

Example 69 with Task

use of nars.entity.Task 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 70 with Task

use of nars.entity.Task 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

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