use of nars.term.atom.Bool in project narchy by automenta.
the class IO method readTermContainer.
@NotNull
public static Term[] readTermContainer(DataInput in) throws IOException {
int siz = in.readByte();
assert (siz < Param.COMPOUND_SUBTERMS_MAX);
Term[] s = new Term[siz];
for (int i = 0; i < siz; i++) {
Term read = (s[i] = readTerm(in));
if (read == null || read instanceof Bool)
throw new Term.InvalidTermException(Op.PROD, /* consider the termvector as a product */
s, "invalid");
}
return s;
}
use of nars.term.atom.Bool in project narchy by automenta.
the class DeriveTime method ifDynamic.
Term ifDynamic(Termed xt) {
Term x = xt.term();
Term y = x.eval(d);
if (y != null && !(y instanceof Bool) && !y.equals(x)) {
Collection<Event> existing = byTerm.get(y);
for (Event ee : existing) if (ee instanceof Absolute)
// transformed but already known (maybe only return 'x' if absolute times are known here)
return null;
return y;
} else {
return null;
}
}
use of nars.term.atom.Bool in project narchy by automenta.
the class TaskRule method accept.
@Override
protected void accept(Task X, Map<Term, Term> xy) {
Term y = output.replace(xy);
if (y instanceof Variable || y instanceof Bool)
return;
// if (r == null)
// return null;
//
// //unnegate and check for an apparent atomic term which may need decompressed in order to be the task's content
// boolean negated;
// Term s = r;
// if (r.op() == NEG) {
// s = r.unneg();
// if (s instanceof Variable)
// return null; //throw new InvalidTaskException(r, "unwrapped variable"); //should have been prevented earlier
//
// negated = true;
// if (s instanceof Compound) {
// return (Compound) r; //its normal compound inside the negation, handle it in Task constructor
// }
// } else if (r instanceof Compound) {
// return (Compound) r; //do not uncompress any further
// } else if (r instanceof Variable) {
// return null;
// } else {
// negated = false;
// }
//
// if (!(s instanceof Compound)) {
// Compound t = compoundOrNull(nar.post(s));
// if (t == null)
// return null; //throw new InvalidTaskException(r, "undecompressible");
// else
// return (Compound) $.negIf(t, negated); //done
// // else
// // else if (s.op()==NEG)
// // return (Compound) $.negIf(post(s.unneg(), nar));
// // else
// // return (Compound) $.negIf(s, negated);
// }
// //its a normal negated compound, which will be unnegated in task constructor
// return (Compound) s;
y = compoundOrNull(y);
if (y == null)
return;
y = y.normalize();
if (y == null)
return;
if (!Task.validTaskTerm(y, X.punc(), false))
return;
Task Y = Task.clone(X, y);
if (Y != null) {
logger.info("{}\t{}", X, Y);
nar.input(Y);
}
}
use of nars.term.atom.Bool in project narchy by automenta.
the class Conj method term.
// private byte id(long w) {
//
// int i = times.indexOf(w);
// if (i!=-1) {
// return (byte) i;
// } else {
// int s = times.size();
// assert(s < Byte.MAX_VALUE);
// times.add(w);
// return (byte)s;
// }
// }
//
// short id(Term t, long w) {
// byte tb = id(t);
// byte wb = id(w);
// return (short) ((tb << 8) | wb);
// }
//
// byte termIndex(short s) {
// return (byte) ((s >> 8) & 0xff);
// }
// byte timeIndex(short s) {
// return (byte) (s & 0xff);
// }
public Term term() {
if (term != null)
return term;
int numTimes = event.size();
switch(numTimes) {
case 0:
return Null;
case 1:
break;
default:
break;
}
event.compact();
IntPredicate validator = null;
Object eternalWhat = event.get(ETERNAL);
Term eternal = term(ETERNAL, eternalWhat);
if (eternal != null) {
if (eternal instanceof Bool)
// override and terminates
return this.term = eternal;
if (numTimes > 1) {
if (eternal.op() == CONJ) {
// Subterms eteSub = eternal.subterms();
if (eternalWhat instanceof byte[]) {
byte[] b = (byte[]) eternalWhat;
validator = (i) -> indexOfZeroTerminated(b, (byte) -i) == -1;
} else {
RoaringBitmap b = (RoaringBitmap) eternalWhat;
validator = (i) -> !b.contains(-i);
}
} else {
Term finalEternal = eternal;
validator = (t) -> !finalEternal.equalsNeg(termsIndex.get(Math.abs(t - 1)).negIf(t < 0));
}
}
}
if (eternal != null && numTimes == 1)
// done
return eternal;
FasterList<LongObjectPair<Term>> e = new FasterList(numTimes - (eternal != null ? 1 : 0));
Iterator<LongObjectPair> ii = event.keyValuesView().iterator();
while (ii.hasNext()) {
LongObjectPair next = ii.next();
long when = next.getOne();
if (when == ETERNAL)
// already handled above
continue;
Term wt = term(when, next.getTwo(), validator);
if (wt == True) {
// canceled out
continue;
} else if (wt == False) {
// short-circuit false
return this.term = False;
} else if (wt == Null) {
// short-circuit null
return this.term = Null;
}
e.add(pair(when, wt));
}
assert (!e.isEmpty());
Term temporal;
if (e.size() > 1) {
e.sortThisBy(LongObjectPair::getOne);
temporal = conjSeq(e);
if (temporal instanceof Bool)
return temporal;
} else {
temporal = e.get(0).getTwo();
}
return eternal != null ? // Op.instance(CONJ, DTERNAL, sorted(eternal, temporal))
CONJ.the(DTERNAL, sorted(eternal, temporal)) : temporal;
}
use of nars.term.atom.Bool in project narchy by automenta.
the class Anon method put.
public Task put(Task t, int dur) {
Term x = t.term();
// assert (x.isNormalized()) : t + " has non-normalized Term content";
Term y = put(x);
if (y == null || y instanceof Bool) {
throw new RuntimeException("Anon fail for term: " + t);
}
return (t.isBeliefOrGoal() && !t.isEternal()) ? new TaskProxy.WithTermCachedTruth(y, t, dur) : new TaskProxy.WithTerm(y, t);
}
Aggregations