Search in sources :

Example 1 with ThingVariable

use of com.vaticle.typedb.core.pattern.variable.ThingVariable in project grakn by graknlabs.

the class AlphaEquivalenceTest method test_relation_equivalent_with_overlapping_variables.

@Test
public void test_relation_equivalent_with_overlapping_variables() {
    ThingVariable r = parseVariables("r", "$r(parent: $p, child: $c) isa parentship").asThing();
    ThingVariable q = parseVariables("r", "$r(parent: $s, child: $p) isa parentship").asThing();
    AlphaEquivalence alphaEq = r.alphaEquals(q);
    Map<String, String> varNameMap = alphaMapToStringMap(alphaEq.asValid());
    assertEquals(varNameMap.get("$r"), "$r");
    assertEquals(varNameMap.get("$p"), "$s");
    assertEquals(varNameMap.get("$c"), "$p");
    assertEquals(varNameMap.get("$_parentship:parent"), "$_parentship:parent");
    assertEquals(varNameMap.get("$_parentship:child"), "$_parentship:child");
    assertEquals(varNameMap.get("$_parentship"), "$_parentship");
    testAlphaEquivalenceSymmetricReflexive(r, q, true);
}
Also used : ThingVariable(com.vaticle.typedb.core.pattern.variable.ThingVariable) Test(org.junit.Test)

Example 2 with ThingVariable

use of com.vaticle.typedb.core.pattern.variable.ThingVariable in project grakn by graknlabs.

the class AlphaEquivalenceTest method test_multiple_value_and_has_label_equivalent.

@Test
public void test_multiple_value_and_has_label_equivalent() {
    ThingVariable p = parseVariables("p", "$p has $a", "$a 30 isa age", "$p has $n", "$n \"Alice\" isa name", "$p isa person").asThing();
    ThingVariable q = parseVariables("q", "$q has $b", "$b 30 isa age", "$q has $m", "$m \"Alice\" isa name", "$q isa person").asThing();
    testAlphaEquivalenceSymmetricReflexive(p, q, true);
    AlphaEquivalence alphaEq = p.alphaEquals(q);
    Map<String, String> varNameMap = alphaMapToStringMap(alphaEq.asValid());
    assertEquals(varNameMap.get("$p"), "$q");
    assertEquals(varNameMap.get("$a"), "$b");
    assertEquals(varNameMap.get("$_age"), "$_age");
    assertEquals(varNameMap.get("$n"), "$m");
    assertEquals(varNameMap.get("$_name"), "$_name");
    assertEquals(varNameMap.get("$_person"), "$_person");
}
Also used : ThingVariable(com.vaticle.typedb.core.pattern.variable.ThingVariable) Test(org.junit.Test)

Example 3 with ThingVariable

use of com.vaticle.typedb.core.pattern.variable.ThingVariable in project grakn by graknlabs.

the class AlphaEquivalenceTest method test_relation_equivalent.

@Test
public void test_relation_equivalent() {
    ThingVariable r = parseVariables("r", "$r(parent: $p, child: $c) isa parentship").asThing();
    ThingVariable q = parseVariables("q", "$q(parent: $s, child: $t) isa parentship").asThing();
    AlphaEquivalence alphaEq = r.alphaEquals(q);
    Map<String, String> varNameMap = alphaMapToStringMap(alphaEq.asValid());
    assertEquals(varNameMap.get("$r"), "$q");
    assertEquals(varNameMap.get("$p"), "$s");
    assertEquals(varNameMap.get("$c"), "$t");
    assertEquals(varNameMap.get("$_parentship:parent"), "$_parentship:parent");
    assertEquals(varNameMap.get("$_parentship:child"), "$_parentship:child");
    assertEquals(varNameMap.get("$_parentship"), "$_parentship");
    testAlphaEquivalenceSymmetricReflexive(r, q, true);
}
Also used : ThingVariable(com.vaticle.typedb.core.pattern.variable.ThingVariable) Test(org.junit.Test)

Example 4 with ThingVariable

use of com.vaticle.typedb.core.pattern.variable.ThingVariable in project grakn by graknlabs.

the class AlphaEquivalenceTest method test_relation_equivalent_with_clashing_variables.

@Test
public void test_relation_equivalent_with_clashing_variables() {
    ThingVariable r = parseVariables("r", "$r(parent: $x, child: $y) isa parentship").asThing();
    ThingVariable q = parseVariables("x", "$x(parent: $y, child: $r) isa parentship").asThing();
    AlphaEquivalence alphaEq = r.alphaEquals(q);
    Map<String, String> varNameMap = alphaMapToStringMap(alphaEq.asValid());
    assertEquals(varNameMap.get("$r"), "$x");
    assertEquals(varNameMap.get("$x"), "$y");
    assertEquals(varNameMap.get("$y"), "$r");
    assertEquals(varNameMap.get("$_parentship:parent"), "$_parentship:parent");
    assertEquals(varNameMap.get("$_parentship:child"), "$_parentship:child");
    assertEquals(varNameMap.get("$_parentship"), "$_parentship");
    testAlphaEquivalenceSymmetricReflexive(r, q, true);
}
Also used : ThingVariable(com.vaticle.typedb.core.pattern.variable.ThingVariable) Test(org.junit.Test)

Example 5 with ThingVariable

use of com.vaticle.typedb.core.pattern.variable.ThingVariable in project grakn by graknlabs.

the class AlphaEquivalenceTest method test_value_not_equivalent.

@Test
public void test_value_not_equivalent() {
    ThingVariable p = parseVariables("p", "$p has age 30", "$p isa person").asThing();
    ThingVariable q = parseVariables("q", "$q has age 20", "$q isa person").asThing();
    testAlphaEquivalenceSymmetricReflexive(p, q, false);
}
Also used : ThingVariable(com.vaticle.typedb.core.pattern.variable.ThingVariable) Test(org.junit.Test)

Aggregations

ThingVariable (com.vaticle.typedb.core.pattern.variable.ThingVariable)12 Test (org.junit.Test)11 Pair (com.vaticle.typedb.common.collection.Pair)1 Identifier (com.vaticle.typedb.core.traversal.common.Identifier)1