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