use of nars.task.util.InvalidTaskException in project narchy by automenta.
the class TaskBuilder method apply.
@Override
public Task apply(NAR n) throws Concept.InvalidConceptException, InvalidTaskException {
if (isDeleted())
throw new InvalidTaskException(this, "Deleted");
Term t = term;
byte punc = punc();
if (punc == 0)
throw new InvalidTaskException(this, "Unspecified punctuation");
Term cntt = t.normalize().the();
if (cntt == null)
throw new InvalidTaskException(t, "Failed normalization");
if (!Task.validTaskTerm(cntt, punc, !isInput() && !Param.DEBUG))
throw new InvalidTaskException(cntt, "Invalid content");
if (cntt != t) {
this.term = cntt;
}
// noinspection IfStatementWithTooManyBranches
switch(punc()) {
case BELIEF:
case GOAL:
if (truth == null) {
// apply the default truth value for specified punctuation
setTruth(t(1, n.confDefault(punc)));
} else {
float confLimit = 1f - Param.TRUTH_EPSILON;
if (!isInput() && conf() > confLimit) {
// clip maximum confidence in case a derivation of an axiomatic belief reaches conf=~1.0 also
setTruth(t(freq(), confLimit));
}
}
break;
case QUEST:
case QUESTION:
if (truth != null)
throw new RuntimeException("quests and questions must have null truth");
break;
case COMMAND:
break;
default:
throw new UnsupportedOperationException("invalid punctuation: " + punc);
}
// assign a unique stamp if none specified (input)
if (evidence.length == 0)
setEvidence(n.time.nextStamp());
if (creation() == ETERNAL) {
long now = n.time();
long oc = start();
if (oc != ETERNAL)
oc += now;
this.creation = now;
setStart(oc);
setEnd(oc);
}
// if quality is not specified (NaN), then this means to assign the default budgeting according to the task's punctuation
float pp = priElseNeg1();
if (pp < 0) {
priSet(n.priDefault(punc));
}
// if (dur!=dur) {
// //assign default duration from NAR
// dur = n.dur();
// }
// shift the occurrence time if input and dt < 0 and non-eternal HACK dont use log it may be removed without warning
// if (isInput()) {
// long exOcc = occurrence();
// if (exOcc != ETERNAL) {
// int termDur = ntt.dt();
// if (termDur != DTERNAL && termDur < 0) {
// setOccurrence(exOcctermDur);
// }
// }
// }
Truth tFinal;
if (truth != null) {
tFinal = Truth.theDithered(truth.freq(), truth.evi(), n);
} else {
tFinal = null;
}
NALTask i = new NALTask(term, punc, tFinal, creation, start, end, evidence);
i.priSet(this);
// return this;
return i;
}
use of nars.task.util.InvalidTaskException in project narchy by automenta.
the class Narsese method decodeTask.
/**
* returns null if the Task is invalid (ex: invalid term)
*/
static Task decodeTask(NAR m, Object[] x) {
if (x.length == 1 && x[0] instanceof Task) {
return (Task) x[0];
}
Term content = ((Term) x[1]).normalize();
/*if (!(content instanceof Compound)) {
throw new NarseseException("Task term unnormalizable: " + contentRaw);
//return Command.task($.func("log", content));
} else */
Object px = x[2];
byte punct = px instanceof Byte ? (Byte) x[2] : (byte) (((Character) x[2]).charValue());
Truth t = (Truth) x[3];
if (t != null && !Float.isFinite(t.conf()))
t = $.t(t.freq(), m.confDefault(punct));
if (t == null && (punct == BELIEF || punct == GOAL)) {
t = $.t(1, m.confDefault(punct));
}
Task y = Task.tryTask(content, punct, t, (C, tr) -> {
// TODO construct directly and remove TaskBuilder
TaskBuilder ttt = new TaskBuilder(C, punct, tr).time(// creation time
m.time(), Tense.getRelativeOccurrence((Tense) x[4], m));
if (x[0] == null)
/* do not set, Memory will apply defaults */
ttt.priSet(m.priDefault(punct));
else
ttt.priSet((Float) x[0]);
return ttt.apply(m).log(NARSESE_TASK_TAG);
});
if (y == null) {
throw new InvalidTaskException(content, "input: " + Arrays.toString(x));
}
return y;
}
Aggregations