Search in sources :

Example 1 with ExecutionResult

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;
}
Also used : Task(nars.entity.Task) ExecutionResult(nars.operator.Operator.ExecutionResult) Sentence(nars.entity.Sentence)

Aggregations

Sentence (nars.entity.Sentence)1 Task (nars.entity.Task)1 ExecutionResult (nars.operator.Operator.ExecutionResult)1