Search in sources :

Example 1 with DerivationContext

use of nars.control.DerivationContext in project opennars by opennars.

the class GlobalAnticipation method event.

@Override
public void event(Class event, Object[] args) {
    if (event == Events.TaskDerive.class) {
        Task derivedTask = (Task) args[0];
        if (derivedTask.sentence.term instanceof Implication && (((Implication) derivedTask.sentence.term).getTemporalOrder() == TemporalRules.ORDER_FORWARD || ((Implication) derivedTask.sentence.term).getTemporalOrder() == TemporalRules.ORDER_CONCURRENT)) {
            if (!current_tasks.contains(derivedTask)) {
                current_tasks.add(derivedTask);
            }
        }
    } else if (event == Events.ConceptBeliefRemove.class) {
        // task is 3nd
        Task removedTask = (Task) args[2];
        if (current_tasks.contains(removedTask)) {
            current_tasks.remove(removedTask);
        }
    } else if (event == Events.InduceSucceedingEvent.class) {
        Task newEvent = (Task) args[0];
        DerivationContext nal = (DerivationContext) args[1];
        if (newEvent.sentence.truth != null) {
            stm.add(newEvent);
            while (stm.size() > MatchUpTo) {
                stm.removeFirst();
            }
        }
        temporalPredictionsAdapt(nal);
    }
}
Also used : Task(nars.entity.Task) DerivationContext(nars.control.DerivationContext) Events(nars.io.events.Events) Implication(nars.language.Implication)

Example 2 with DerivationContext

use of nars.control.DerivationContext in project opennars by opennars.

the class ConcatVisionChannel method step_start.

@Override
public void step_start() {
    Position samplePos = sampling.get(0);
    Task current = inputs[samplePos.Y][samplePos.X];
    int k = 0;
    for (int i = 1; i < sampling.size(); i++) {
        Position samplePos2 = sampling.get(i);
        Task prem2 = inputs[samplePos2.Y][samplePos2.X];
        List<Task> seq = proceedWithTemporalInduction(current.sentence, prem2.sentence, prem2, new DerivationContext(nar.memory), true, false, true);
        if (seq != null) {
            for (Task t : seq) {
                if (!t.sentence.isEternal()) {
                    // TODO improve API, this check should not be necessary
                    current = t;
                    break;
                }
            }
        }
        k++;
    }
    System.out.println(k);
    System.out.println(current);
    // feeds results into "upper" sensory channels:
    this.results.add(current);
    this.step_finished();
}
Also used : Task(nars.entity.Task) DerivationContext(nars.control.DerivationContext)

Example 3 with DerivationContext

use of nars.control.DerivationContext in project opennars by opennars.

the class Consider method execute.

/**
 * To activate a concept as if a question has been asked about it
 *
 * @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 term = args[1];
    Concept concept = memory.conceptualize(Consider.budgetMentalConcept(operation), term);
    DerivationContext cont = new DerivationContext(memory);
    cont.setCurrentConcept(concept);
    GeneralInferenceControl.fireConcept(cont, 1);
    return null;
}
Also used : Concept(nars.entity.Concept) DerivationContext(nars.control.DerivationContext) Term(nars.language.Term)

Example 4 with DerivationContext

use of nars.control.DerivationContext in project opennars by opennars.

the class Memory method localInference.

public void localInference(Task task) {
    DerivationContext cont = new DerivationContext(this);
    cont.setCurrentTask(task);
    cont.setCurrentTerm(task.getTerm());
    cont.setCurrentConcept(conceptualize(task.budget, cont.getCurrentTerm()));
    if (cont.getCurrentConcept() != null) {
        boolean processed = ConceptProcessing.processTask(cont.getCurrentConcept(), cont, task);
        if (processed) {
            event.emit(Events.ConceptDirectProcessedTask.class, task);
        }
    }
    if (!task.sentence.isEternal() && !(task.sentence.term instanceof Operation)) {
        TemporalInferenceControl.eventInference(task, cont);
    }
    // memory.logic.TASK_IMMEDIATE_PROCESS.commit();
    emit(Events.TaskImmediateProcess.class, task, cont);
}
Also used : DerivationContext(nars.control.DerivationContext) Events(nars.io.events.Events) Operation(nars.operator.Operation)

Example 5 with DerivationContext

use of nars.control.DerivationContext in project opennars by opennars.

the class SpatialSamplingVisionChannel method step_start.

@Override
public void step_start() {
    int ind = nar.memory.randomNumber.nextInt(sampling.size());
    Position samplePos = sampling.get(ind);
    Task sampled = spatialbag[samplePos.Y][samplePos.X].takeNext();
    // Todo improve API, channel should not need to know where in the array x and y size is
    // spatial biased random sampling:
    int ind2 = nar.memory.randomNumber.nextInt(sampling.size());
    int s2posY = sampling.get(ind2).Y;
    int s2posX = sampling.get(ind2).X;
    if (spatialbag[s2posY][s2posX] != null) {
        Task sampled2 = spatialbag[s2posY][s2posX].takeNext();
        if (sampled2 != null) {
            // improve API, carrying out temporal inference should be easier..
            List<Task> seq = proceedWithTemporalInduction(sampled.sentence, sampled2.sentence, sampled2, new DerivationContext(nar.memory), true, false, true);
            if (seq != null) {
                for (Task t : seq) {
                    if (!t.sentence.isEternal()) {
                        // TODO improve API, this check should not be necessary
                        AddToSpatialBag(t);
                        this.results.add(t);
                    }
                }
            }
            // todo improve API, putting an element bag should be easy
            spatialbag[s2posY][s2posX].putBack(sampled2, nar.memory.cycles(nar.memory.param.conceptForgetDurations), nar.memory);
        }
    }
    spatialbag[samplePos.Y][samplePos.X].putBack(sampled, nar.memory.cycles(nar.memory.param.conceptForgetDurations), nar.memory);
    // feeds results into "upper" sensory channels:
    this.step_finished();
}
Also used : Task(nars.entity.Task) DerivationContext(nars.control.DerivationContext)

Aggregations

DerivationContext (nars.control.DerivationContext)7 Task (nars.entity.Task)5 Events (nars.io.events.Events)3 Concept (nars.entity.Concept)2 Term (nars.language.Term)2 TreeMLData (automenta.vivisect.TreeMLData)1 NWindow (automenta.vivisect.swing.NWindow)1 PCanvas (automenta.vivisect.swing.PCanvas)1 LineChart (automenta.vivisect.timeline.LineChart)1 TimelineVis (automenta.vivisect.timeline.TimelineVis)1 HashSet (java.util.HashSet)1 Random (java.util.Random)1 Sentence (nars.entity.Sentence)1 NARSwing (nars.gui.NARSwing)1 Narsese (nars.io.Narsese)1 AnswerHandler (nars.io.events.AnswerHandler)1 TaskImmediateProcess (nars.io.events.Events.TaskImmediateProcess)1 ChangedTextInput (nars.lab.ioutils.ChangedTextInput)1 Implication (nars.language.Implication)1 NAR (nars.main.NAR)1