Search in sources :

Example 1 with Ellipsis

use of nars.derive.match.Ellipsis in project narchy by automenta.

the class Choose2 method mutate.

@Override
public void mutate(Unify versioneds, Termutator[] chain, int current) {
    Combinations ccc = this.comb;
    ccc.reset();
    boolean phase = true;
    int start = f.now();
    ShuffledSubterms yy = this.yy;
    Ellipsis xEllipsis = this.xEllipsis;
    Unify f = this.f;
    Term[] x = this.x;
    int[] c = null;
    while (ccc.hasNext() || !phase) {
        c = phase ? ccc.next() : c;
        phase = !phase;
        byte c0 = (byte) c[0];
        byte c1 = (byte) c[1];
        // swap to try the reverse next iteration
        ArrayUtils.reverse(c);
        Term y1 = yy.sub(c0);
        if (x[0].unify(y1, f)) {
            Term y2 = yy.sub(c1);
            if (x[1].unify(y2, f) && xEllipsis.unify(EllipsisMatch.matchExcept(yy, c0, c1), f)) {
                if (!f.tryMutate(chain, current))
                    break;
            }
        }
        if (!f.revertLive(start))
            break;
    }
}
Also used : Unify(nars.term.subst.Unify) Combinations(jcog.math.Combinations) Ellipsis(nars.derive.match.Ellipsis) Term(nars.term.Term) ShuffledSubterms(nars.subterm.ShuffledSubterms)

Example 2 with Ellipsis

use of nars.derive.match.Ellipsis in project narchy by automenta.

the class PatternIndex method patternify.

/*@NotNull*/
public Term patternify(/*@NotNull*/
Compound x) {
    Subterms s = x.subterms();
    int ss = s.subs();
    Term[] bb = new Term[ss];
    // , temporal = false;
    boolean changed = false;
    for (int i = 0; i < ss; i++) {
        Term a = s.sub(i);
        Termed b = get(a, true);
        if (a != b) {
            changed = true;
        }
        bb[i] = b.term();
    }
    if (!changed && Ellipsis.firstEllipsis(s) == null)
        return x;
    Subterms v = changed ? Subterms.subtermsInterned(bb.length > 1 && x.op().commutative && (concurrent(x.dt())) ? Terms.sorted(bb) : bb) : s;
    Ellipsis e = Ellipsis.firstEllipsis(v);
    return e != null ? ellipsis(x, v, e) : // new PatternCompound.PatternCompoundSimple(x.op(), x.dt(), v);
    x.op().the(x.dt(), v.arrayShared());
}
Also used : Subterms(nars.subterm.Subterms) Termed(nars.term.Termed) Ellipsis(nars.derive.match.Ellipsis) Term(nars.term.Term)

Example 3 with Ellipsis

use of nars.derive.match.Ellipsis in project narchy by automenta.

the class EllipsisTest method testEllipsisInMinArity.

@Test
public void testEllipsisInMinArity() {
    Atomic a = Atomic.the("a");
    Ellipsis b = new EllipsisOneOrMore($.varPattern(1));
    for (Op o : Op.values()) {
        if (o.minSize <= 1)
            continue;
        if (o.statement)
            continue;
        if (o != DIFFe && o != DIFFi) {
            assertEquals(a, o.the(DTERNAL, a), o + " with normal term");
        } else {
            assertEquals(Null, o.the(DTERNAL, a));
        }
        assertEquals(o.statement ? VAR_PATTERN : o, o.the(DTERNAL, b).op(), o + " with ellipsis not reduced");
    }
}
Also used : Op(nars.Op) Ellipsis(nars.derive.match.Ellipsis) Ellipsis.firstEllipsis(nars.derive.match.Ellipsis.firstEllipsis) EllipsisOneOrMore(nars.derive.match.EllipsisOneOrMore) Atomic(nars.term.atom.Atomic) Test(org.junit.jupiter.api.Test)

Aggregations

Ellipsis (nars.derive.match.Ellipsis)3 Term (nars.term.Term)2 Combinations (jcog.math.Combinations)1 Op (nars.Op)1 Ellipsis.firstEllipsis (nars.derive.match.Ellipsis.firstEllipsis)1 EllipsisOneOrMore (nars.derive.match.EllipsisOneOrMore)1 ShuffledSubterms (nars.subterm.ShuffledSubterms)1 Subterms (nars.subterm.Subterms)1 Termed (nars.term.Termed)1 Atomic (nars.term.atom.Atomic)1 Unify (nars.term.subst.Unify)1 Test (org.junit.jupiter.api.Test)1