use of nars.entity.Task in project opennars by opennars.
the class OutputContainsCondition method cond.
public boolean cond(Class channel, Object signal) {
if ((channel == OUT.class) || (channel == EXE.class)) {
String o;
if (signal instanceof Task) {
// only compare for Sentence string, faster than TextOutput.getOutputString
// which also does unescaping, etc..
Task t = (Task) signal;
Sentence s = t.sentence;
o = s.toString(nar, false).toString();
if (o.contains(containing)) {
if (saveSimilar) {
exact.add(t);
}
return true;
}
} else {
Task t = null;
if (signal instanceof ExecutionResult)
t = ((ExecutionResult) signal).getTask();
o = TextOutputHandler.getOutputString(channel, signal, false, false, nar).toString();
if (o.contains(containing)) {
if ((saveSimilar) && (t != null)) {
exact.add(t);
}
return true;
}
}
if (saveSimilar) {
int dist = levenshteinDistance(o, containing);
if (almost.size() >= maxSimilars) {
SimilarOutput last = almost.last();
if (dist < last.distance) {
almost.remove(last);
almost.add(new SimilarOutput(o, dist));
}
} else {
almost.add(new SimilarOutput(o, dist));
}
}
}
/*if (channel == ERR.class) {
Assert.assertTrue(signal.toString(), false);
}*/
return false;
}
use of nars.entity.Task 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.entity.Task in project opennars by opennars.
the class Memory method inputTask.
/* There are several types of new tasks, all added into the
newTasks list, to be processed in the next cycleMemory.
Some of them are reported and/or logged. */
/**
* Input task processing. Invoked by the outside or inside environment.
* Outside: StringParser (addInput); Inside: InnateOperator (feedback). Input
* tasks with low priority are ignored, and the others are put into task
* buffer.
*
* @param t The addInput task
*/
public void inputTask(final Task t, boolean emitIn) {
if (!checked) {
checked = true;
isjUnit = isJUnitTest();
}
if (t instanceof Task) {
Task task = (Task) t;
Stamp s = task.sentence.stamp;
if (s.getCreationTime() == -1)
s.setCreationTime(time(), Parameters.DURATION);
if (emitIn) {
emit(IN.class, task);
}
if (task.budget.aboveThreshold()) {
addNewTask(task, "Perceived");
} else {
removeTask(task, "Neglected");
}
}
}
use of nars.entity.Task in project opennars by opennars.
the class Memory method processNewTasks.
/**
* Process the newTasks accumulated in the previous workCycle, accept input
* ones and those that corresponding to existing concepts, plus one from the
* buffer.
*/
public void processNewTasks() {
Task task;
// don't include new tasks produced in the current workCycle
int counter = newTasks.size();
while (counter-- > 0) {
task = newTasks.removeFirst();
boolean enterDirect = true;
if (/*task.isElemOfSequenceBuffer() || task.isObservablePrediction() || */
enterDirect || task.isInput() || task.sentence.isQuest() || task.sentence.isQuestion() || concept(task.sentence.term) != null) {
// new input or existing concept
localInference(task);
} else {
Sentence s = task.sentence;
if (s.isJudgment() || s.isGoal()) {
double d = s.getTruth().getExpectation();
if (s.isJudgment() && d > Parameters.DEFAULT_CREATION_EXPECTATION) {
// new concept formation
novelTasks.putIn(task);
} else if (s.isGoal() && d > Parameters.DEFAULT_CREATION_EXPECTATION_GOAL) {
// new concept formation
novelTasks.putIn(task);
} else {
removeTask(task, "Neglected");
}
}
}
}
}
use of nars.entity.Task in project opennars by opennars.
the class Want method execute.
/**
* To create a goal with a given statement
* @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 content = args[1];
TruthValue truth = new TruthValue(1, Parameters.DEFAULT_JUDGMENT_CONFIDENCE);
Sentence sentence = new Sentence(content, Symbols.GOAL_MARK, truth, new Stamp(memory));
BudgetValue budget = new BudgetValue(Parameters.DEFAULT_GOAL_PRIORITY, Parameters.DEFAULT_GOAL_DURABILITY, truth);
return Lists.newArrayList(new Task(sentence, budget, true));
}
Aggregations