Search in sources :

Example 1 with Answer

use of nars.io.events.Events.Answer in project opennars by opennars.

the class TextOutputHandler method getOutputString.

/**
 * generates a human-readable string from an output channel and signal
 */
public static CharSequence getOutputString(Class channel, Object signal, final boolean showStamp, final NAR nar, final StringBuilder buffer) {
    buffer.setLength(0);
    if (signal instanceof Exception) {
        Exception e = (Exception) signal;
        buffer.append(e.getClass().getSimpleName()).append(": ").append(e.getMessage());
        /*if (showStackTrace)*/
        {
            buffer.append(" ").append(Arrays.asList(e.getStackTrace()));
        }
    } else if (signal instanceof Task) {
        Task t = (Task) signal;
        Sentence s = t.sentence;
        buffer.append(s.toString(nar, showStamp));
    } else if (signal instanceof Sentence) {
        Sentence s = (Sentence) signal;
        buffer.append(s.toString(nar, showStamp));
    } else if (signal instanceof Object[]) {
        if (channel == Answer.class) {
            Object[] o = (Object[]) signal;
            Task task = (Task) o[0];
            Sentence belief = (Sentence) o[1];
            Sentence question = task.sentence;
            Sentence answer = belief;
            buffer.append(answer.toString(nar, showStamp));
        } else
            buffer.append(Arrays.toString((Object[]) signal));
    } else {
        buffer.append(signal.toString());
    }
    return Texts.unescape(buffer);
}
Also used : Answer(nars.io.events.Events.Answer) Task(nars.entity.Task) Sentence(nars.entity.Sentence) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 Sentence (nars.entity.Sentence)1 Task (nars.entity.Task)1 Answer (nars.io.events.Events.Answer)1