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;
}
}
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());
}
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");
}
}
Aggregations