Search in sources :

Example 1 with Variable

use of nars.term.var.Variable in project narchy by automenta.

the class NoCommonSubtermConstraint method isSubtermOfTheOther.

static boolean isSubtermOfTheOther(Term a, Term b, boolean recurse, boolean excludeVariables) {
    if ((excludeVariables) && (a instanceof Variable || b instanceof Variable))
        return false;
    int av = a.volume();
    int bv = b.volume();
    if (av == bv) {
        // impossible for either to contain the other
        return false;
    } else {
        if (av < bv) {
            // swap
            Term c = a;
            a = b;
            b = c;
        }
        return recurse ? a.containsRecursively(b, true, limit) : a.containsRoot(b);
    }
}
Also used : Variable(nars.term.var.Variable) Term(nars.term.Term)

Example 2 with Variable

use of nars.term.var.Variable in project narchy by automenta.

the class TermIOTest method testTermSerialization3_2.

@Test
public void testTermSerialization3_2() throws Narsese.NarseseException {
    // multiple variables
    Variable q = $.varQuery(1);
    Compound twoB = $.inh($.varDep(2), Atomic.the("b"));
    assertNotEquals(q.compareTo(twoB), twoB.compareTo(q));
    assertTermEqualSerialize("((#a --> b) <-> ?c)");
    Term a = $("(#2-->b)");
    Term b = $("?1");
    int x = a.compareTo(b);
    int y = b.compareTo(a);
    assertNotEquals((int) Math.signum(x), (int) Math.signum(y));
}
Also used : Variable(nars.term.var.Variable) Compound(nars.term.Compound) Term(nars.term.Term) Test(org.junit.jupiter.api.Test)

Example 3 with Variable

use of nars.term.var.Variable in project narchy by automenta.

the class LinkageTest method links.

public boolean links(@NotNull String premise1, String premise2, @NotNull TestNAR tester) throws Narsese.NarseseException {
    Concept ret = tester.nar.conceptualize(premise1);
    boolean passed = false;
    if (ret != null) {
        for (PriReference<Term> entry : ret.termlinks()) {
            Term et1 = entry.get().term();
            if (et1.toString().equals(premise2)) {
                passed = true;
                break;
            }
            if (!(et1 instanceof Variable)) {
                Concept Wc = tester.nar.concept(et1);
                if (Wc != null) {
                    for (PriReference<Term> entry2 : Wc.termlinks()) {
                        Term et2 = entry2.get().term();
                        if (et2.toString().equals(premise2)) {
                            passed = true;
                            break;
                        }
                        Concept Wc2 = tester.nar.concept(et2);
                        if (Wc2 != null) {
                            for (PriReference<Term> entry3 : Wc2.termlinks()) {
                                Term et3 = entry3.get().term();
                                if (et3.toString().equals(premise2)) {
                                    passed = true;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        /*if (w.toString().equals(premise2)) {
                    passed = true;
                }*/
        }
    }
    return passed;
}
Also used : Concept(nars.concept.Concept) Variable(nars.term.var.Variable) Term(nars.term.Term)

Example 4 with Variable

use of nars.term.var.Variable in project narchy by automenta.

the class NarseseBaseTest method testVariables.

@Test
public void testVariables() throws Narsese.NarseseException {
    Variable v;
    v = testVar(Op.VAR_DEP.ch);
    assertTrue(v.hasVarDep());
    v = testVar(Op.VAR_INDEP.ch);
    assertTrue(v.hasVarIndep());
    v = testVar(Op.VAR_QUERY.ch);
    assertTrue(v.hasVarQuery());
}
Also used : Variable(nars.term.var.Variable) Test(org.junit.jupiter.api.Test)

Example 5 with Variable

use of nars.term.var.Variable in project narchy by automenta.

the class CommonVariableTest method testInvalid.

@Test
public void testInvalid() {
    assertThrows(RuntimeException.class, () -> {
        Variable p1p1 = CommonVariable.common(p1, p1);
        assertEquals("#x1y1", p1p1.toString());
    });
}
Also used : Variable(nars.term.var.Variable) CommonVariable(nars.term.var.CommonVariable) Test(org.junit.jupiter.api.Test)

Aggregations

Variable (nars.term.var.Variable)17 Term (nars.term.Term)12 Test (org.junit.jupiter.api.Test)6 CommonVariable (nars.term.var.CommonVariable)4 Op (nars.Op)3 FileNotFoundException (java.io.FileNotFoundException)2 TODO (jcog.TODO)2 FasterList (jcog.list.FasterList)2 Concept (nars.concept.Concept)2 Subterms (nars.subterm.Subterms)2 Compound (nars.term.Compound)2 Bool (nars.term.atom.Bool)2 Int (nars.term.atom.Int)2 MutableSet (org.eclipse.collections.api.set.MutableSet)2 UnifiedMap (org.eclipse.collections.impl.map.mutable.UnifiedMap)2 IntObjectHashMap (org.eclipse.collections.impl.map.mutable.primitive.IntObjectHashMap)2 NotNull (org.jetbrains.annotations.NotNull)2 NumberTerm (alice.tuprolog.NumberTerm)1 Struct (alice.tuprolog.Struct)1 Theory (alice.tuprolog.Theory)1