use of nars.concept.dynamic.DynamicTruthModel in project narchy by automenta.
the class DefaultConceptBuilder method unroll.
@Nullable
static DynamicTruthModel unroll(Term t) {
DynamicTruthModel dmt = null;
final Subterms ts = t.subterms();
switch(t.op()) {
case INH:
Term subj = ts.sub(0);
Term pred = ts.sub(1);
Op so = subj.op();
Op po = pred.op();
if (dmt == null) /*&& (so.atomic || so == PROD || so.isSet())*/
{
if ((po == Op.SECTi) || (po == Op.SECTe) || (po == DIFFi)) {
// (M --> P), (M --> S), notSet(S), notSet(P), neqCom(S,P) |- (M --> (P & S)), (Belief:Intersection)
// (M --> P), (M --> S), notSet(S), notSet(P), neqCom(S,P) |- (M --> (P | S)), (Belief:Union)
// (M --> P), (M --> S), notSet(S), notSet(P), neqCom(S,P) |- (M --> (P - S)), (Belief:Difference) //intensional
Compound cpred = (Compound) pred;
int s = cpred.subs();
Term[] x = new Term[s];
for (int i = 0; i < s; i++) {
Term y;
if (!validDynamicSubterm.test(y = INH.the(subj, cpred.sub(i))))
return null;
x[i] = y;
}
switch(po) {
case SECTi:
dmt = new DynamicTruthModel.Union(x);
break;
case SECTe:
dmt = new DynamicTruthModel.SectIntersection(x);
break;
case DIFFi:
dmt = new DynamicTruthModel.Difference(x[0], x[1]);
break;
}
}
/*else if (so.image) {
Compound img = (Compound) subj;
Term[] ee = new Term[img.size()];
int relation = img.dt();
int s = ee.length;
for (int j = 1, i = 0; i < s; ) {
if (j == relation)
ee[i++] = pred;
if (i < s)
ee[i++] = img.sub(j++);
}
Compound b = compoundOrNull(INH.the(DTERNAL, img.sub(0), $.p(ee)));
if (b != null)
dmt = new DynamicTruthModel.Identity(t, b);
}*/
}
if (dmt == null) /* && (po.atomic || po == PROD || po.isSet()) */
{
if ((so == Op.SECTi) || (so == Op.SECTe) || (so == Op.DIFFe)) // || (subj instanceof Int.IntRange) || (so == PROD && subj.OR(Int.IntRange.class::isInstance))
{
// (P --> M), (S --> M), notSet(S), notSet(P), neqCom(S,P) |- ((S | P) --> M), (Belief:Intersection)
// (P --> M), (S --> M), notSet(S), notSet(P), neqCom(S,P) |- ((S & P) --> M), (Belief:Union)
// (P --> M), (S --> M), notSet(S), notSet(P), neqCom(S,P) |- ((P ~ S) --> M), (Belief:Difference) //extensional
Subterms subjsubs = subj.subterms();
int s = subjsubs.subs();
Term[] x = new Term[s];
for (int i = 0; i < s; i++) {
Term y;
//
if (!validDynamicSubterm.test(y = INH.the(subjsubs.sub(i), pred)))
return null;
x[i] = y;
}
switch(so) {
// case PROD:
case SECTi:
dmt = new DynamicTruthModel.SectIntersection(x);
break;
case SECTe:
dmt = new DynamicTruthModel.Union(x);
break;
case DIFFe:
dmt = new DynamicTruthModel.Difference(x[0], x[1]);
break;
}
}
}
break;
case CONJ:
// allow variables onlyif they are not themselves direct subterms of this
if (validDynamicSubterms(ts)) {
dmt = DynamicTruthModel.Intersection.ConjIntersection.the;
}
break;
case DIFFe:
// root DIFFe (not subj or pred of an inh)
if (validDynamicSubterms(ts))
dmt = new DynamicTruthModel.Difference(ts.arrayShared());
break;
case NEG:
throw new RuntimeException("negation terms can not be conceptualized as something separate from that which they negate");
}
return dmt;
}