Search in sources :

Example 11 with ThingVariable

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

the class AlphaEquivalenceTest method test_isa_equivalent.

@Test
public void test_isa_equivalent() {
    ThingVariable a = parseVariable("a", "$a isa age").asThing();
    ThingVariable b = parseVariable("b", "$b isa age").asThing();
    AlphaEquivalence alphaEq = a.alphaEquals(b);
    assertEquals(map(new Pair<>("$a", "$b"), new Pair<>("$_age", "$_age")), alphaMapToStringMap(alphaEq.asValid()));
    testAlphaEquivalenceSymmetricReflexive(a, b, true);
}
Also used : ThingVariable(com.vaticle.typedb.core.pattern.variable.ThingVariable) Pair(com.vaticle.typedb.common.collection.Pair) Test(org.junit.Test)

Example 12 with ThingVariable

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

the class RelationConstraint method addTo.

@Override
public void addTo(GraphTraversal.Thing traversal) {
    for (RolePlayer rolePlayer : rolePlayers) {
        assert !rolePlayer.inferredRoleTypes.isEmpty();
        ThingVariable player = rolePlayer.player();
        int rep = rolePlayer.repetition();
        if (rolePlayer.roleType().isPresent() && rolePlayer.roleType().get().id().isName()) {
            Identifier.Scoped role = Identifier.Scoped.of(owner.id(), rolePlayer.roleType().get().id(), player.id(), rep);
            traversal.relating(owner.id(), role);
            traversal.playing(player.id(), role);
            traversal.isa(role, rolePlayer.roleType().get().id());
            traversal.types(role, rolePlayer.inferredRoleTypes());
        } else {
            traversal.rolePlayer(owner.id(), player.id(), rolePlayer.inferredRoleTypes(), rep);
        }
    }
}
Also used : Identifier(com.vaticle.typedb.core.traversal.common.Identifier) ThingVariable(com.vaticle.typedb.core.pattern.variable.ThingVariable)

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