use of nars.operator.Operator.ExecutionResult 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;
}
Aggregations