use of nars.Op.IMPL in project narchy by automenta.
the class TimeGraph method onAdd.
@Override
protected void onAdd(Node<nars.derive.time.TimeGraph.Event, nars.derive.time.TimeGraph.TimeSpan> x) {
Event event = x.id;
Term eventTerm = event.id;
if (byTerm.put(eventTerm, event)) {
if (autoNeg.test(eventTerm)) {
// link(event, 0, know(eventTerm.neg())); //WEAK
// WEAK
link(know(eventTerm), 0, know(eventTerm.neg()));
}
}
// Term tRoot = eventTerm.root();
// if (!tRoot.equals(eventTerm))
// byTerm.put(tRoot, event);
int edt = eventTerm.dt(), eventDT;
if (edt == DTERNAL && dternalAsZero)
eventDT = 0;
else
eventDT = edt;
switch(eventTerm.op()) {
// break;
case IMPL:
Term subj = eventTerm.sub(0);
Event se = know(subj);
Term pred = eventTerm.sub(1);
Event pe = know(pred);
if (eventDT == DTERNAL) {
link(se, ETERNAL, pe);
subj.eventsWhile((w, y) -> {
link(know(y), ETERNAL, pe);
return true;
}, 0, true, true, false, 0);
pred.eventsWhile((w, y) -> {
link(se, ETERNAL, know(y));
return true;
}, 0, true, true, false, 0);
} else if (eventDT != XTERNAL) {
int st = subj.dtRange();
link(se, (eventDT + st), pe);
subj.eventsWhile((w, y) -> {
link(know(y), eventDT + st - w, pe);
return true;
}, 0, true, true, false, 0);
pred.eventsWhile((w, y) -> {
link(se, eventDT + st + w, know(y));
return true;
}, 0, true, true, false, 0);
}
break;
case CONJ:
// Subterms tt = eventTerm.subterms();
// int s = tt.subs();
// if (et == TIMELESS) {
// //chain the sibling subevents
// if (s == 2) {
// Term se0 = tt.sub(0);
// Event e0 = know(se0);
// Term se1 = tt.sub(1);
// Event e1 = know(se1);
// int dt;
// Event earliest;
// if (eventDT == DTERNAL) {
// dt = DTERNAL;
// earliest = e0; //just use the first by default
// } else {
// long t0 = eventTerm.subTime(se0);
// long t1 = eventTerm.subTime(se1);
// long ddt = (int) (t1 - t0);
// assert (ddt < Integer.MAX_VALUE);
// dt = (int) ddt;
// earliest = t0 < t1 ? e0 : e1;
// }
// link(e0, dt, e1);
// link(earliest, 0, event);
//
// } else {
// throw new TODO();
// }
//
// } else
// locate the events and sub-events absolutely
long et = event.when();
switch(eventDT) {
case XTERNAL:
break;
case DTERNAL:
Subterms es = eventTerm.subterms();
int esn = es.subs();
Term prev = es.sub(0);
for (int i = 1; i < esn; i++) {
// dternal chain
Term next = es.sub(i);
link(knowComponent(et, 0, prev), ETERNAL, knowComponent(et, 0, next));
prev = next;
}
break;
case 0:
// eventTerm.subterms().forEach(this::know); //TODO can these be absolute if the event is?
boolean timed = et != ETERNAL;
for (Term s : eventTerm.subterms()) {
Event t = eventDT == 0 ? // 0
knowComponent(et, 0, s) : (// DTERNAL and TIMED
timed ? // DTERNAL and TIMED
know(s, et) : know(s));
if (t != null) {
link(event, (eventDT == 0 || timed) ? 0 : ETERNAL, // DTERNAL and TIMELESS
t);
} else {
// WHY?
}
}
break;
default:
eventTerm.eventsWhile((w, y) -> {
link(event, w, knowComponent(et, w, y));
return true;
}, 0, false, false, false, 0);
break;
}
break;
}
}
Aggregations