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);
}
}
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();
}
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;
}
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);
}
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();
}
Aggregations