Search in sources :

Example 1 with IMPL

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;
    }
}
Also used : Iterables(com.google.common.collect.Iterables) java.util(java.util) Search(jcog.data.graph.search.Search) CONJ(nars.Op.CONJ) Tense(nars.time.Tense) MultimapBuilder(com.google.common.collect.MultimapBuilder) IMPL(nars.Op.IMPL) Multimap(com.google.common.collect.Multimap) Iterators(com.google.common.collect.Iterators) MathArithmeticException(org.apache.commons.math3.exception.MathArithmeticException) Op(nars.Op) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Bool(nars.term.atom.Bool) LongObjectPair(org.eclipse.collections.api.tuple.primitive.LongObjectPair) Term(nars.term.Term) Predicate(java.util.function.Predicate) TS_ZERO(nars.derive.time.TimeGraph.TimeSpan.TS_ZERO) FasterList(jcog.list.FasterList) MapNodeGraph(jcog.data.graph.MapNodeGraph) Util(jcog.Util) BooleanObjectPair(org.eclipse.collections.api.tuple.primitive.BooleanObjectPair) Consumer(java.util.function.Consumer) Nullable(org.jetbrains.annotations.Nullable) TODO(jcog.TODO) ImmutableDirectedEdge(jcog.data.graph.ImmutableDirectedEdge) Subterms(nars.subterm.Subterms) Cons(jcog.list.Cons) NotNull(org.jetbrains.annotations.NotNull) UnifiedSet(org.eclipse.collections.impl.set.mutable.UnifiedSet) Subterms(nars.subterm.Subterms) Term(nars.term.Term)

Aggregations

Iterables (com.google.common.collect.Iterables)1 Iterators (com.google.common.collect.Iterators)1 Multimap (com.google.common.collect.Multimap)1 MultimapBuilder (com.google.common.collect.MultimapBuilder)1 java.util (java.util)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 Consumer (java.util.function.Consumer)1 Predicate (java.util.function.Predicate)1 TODO (jcog.TODO)1 Util (jcog.Util)1 ImmutableDirectedEdge (jcog.data.graph.ImmutableDirectedEdge)1 MapNodeGraph (jcog.data.graph.MapNodeGraph)1 Search (jcog.data.graph.search.Search)1 Cons (jcog.list.Cons)1 FasterList (jcog.list.FasterList)1 Op (nars.Op)1 CONJ (nars.Op.CONJ)1 IMPL (nars.Op.IMPL)1 TS_ZERO (nars.derive.time.TimeGraph.TimeSpan.TS_ZERO)1 Subterms (nars.subterm.Subterms)1