Search in sources :

Example 16 with MultiUnifier

use of ai.grakn.graql.admin.MultiUnifier in project grakn by graknlabs.

the class AtomicQueryTest method testExactUnification_TernaryRelation_ParentRepeatsMetaRoles.

@Test
public void testExactUnification_TernaryRelation_ParentRepeatsMetaRoles() {
    EmbeddedGraknTx<?> graph = unificationWithTypesSet.tx();
    String parentString = "{(role: $x, role: $y, role2: $z) isa ternary;}";
    String childString = "{(role1: $u, role2: $v, role3: $q) isa ternary;}";
    String childString2 = "{(role1: $u, role2: $v, role2: $q) isa ternary;}";
    String childString3 = "{(role1: $u, role1: $v, role2: $q) isa ternary;}";
    String childString4 = "{(role1: $u, role1: $u, role2: $q) isa ternary;}";
    Conjunction<VarPatternAdmin> parentPattern = conjunction(parentString, graph);
    Conjunction<VarPatternAdmin> childPattern = conjunction(childString, graph);
    Conjunction<VarPatternAdmin> childPattern2 = conjunction(childString2, graph);
    Conjunction<VarPatternAdmin> childPattern3 = conjunction(childString3, graph);
    Conjunction<VarPatternAdmin> childPattern4 = conjunction(childString4, graph);
    ReasonerAtomicQuery parentQuery = ReasonerQueries.atomic(parentPattern, graph);
    ReasonerAtomicQuery childQuery = ReasonerQueries.atomic(childPattern, graph);
    ReasonerAtomicQuery childQuery2 = ReasonerQueries.atomic(childPattern2, graph);
    ReasonerAtomicQuery childQuery3 = ReasonerQueries.atomic(childPattern3, graph);
    ReasonerAtomicQuery childQuery4 = ReasonerQueries.atomic(childPattern4, graph);
    MultiUnifier unifier = childQuery.getMultiUnifier(parentQuery);
    MultiUnifier correctUnifier = new MultiUnifierImpl(ImmutableMultimap.of(var("u"), var("x"), var("v"), var("z"), var("q"), var("y")), ImmutableMultimap.of(var("u"), var("y"), var("v"), var("z"), var("q"), var("x")));
    assertTrue(unifier.containsAll(correctUnifier));
    assertEquals(unifier.size(), 2);
    MultiUnifier unifier2 = childQuery2.getMultiUnifier(parentQuery);
    MultiUnifier correctUnifier2 = new MultiUnifierImpl(ImmutableMultimap.of(var("u"), var("x"), var("v"), var("y"), var("q"), var("z")), ImmutableMultimap.of(var("u"), var("x"), var("v"), var("z"), var("q"), var("y")), ImmutableMultimap.of(var("u"), var("y"), var("v"), var("z"), var("q"), var("x")), ImmutableMultimap.of(var("u"), var("y"), var("v"), var("x"), var("q"), var("z")));
    assertTrue(unifier2.containsAll(correctUnifier2));
    assertEquals(unifier2.size(), 4);
    MultiUnifier unifier3 = childQuery3.getMultiUnifier(parentQuery);
    MultiUnifier correctUnifier3 = new MultiUnifierImpl(ImmutableMultimap.of(var("u"), var("x"), var("v"), var("y"), var("q"), var("z")), ImmutableMultimap.of(var("u"), var("y"), var("v"), var("x"), var("q"), var("z")));
    assertTrue(unifier3.containsAll(correctUnifier3));
    assertEquals(unifier3.size(), 2);
    Unifier unifier4 = childQuery4.getMultiUnifier(parentQuery).getUnifier();
    Unifier correctUnifier4 = new UnifierImpl(ImmutableMultimap.of(var("u"), var("x"), var("u"), var("y"), var("q"), var("z")));
    assertTrue(unifier4.containsAll(correctUnifier4));
}
Also used : VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) MultiUnifier(ai.grakn.graql.admin.MultiUnifier) ReasonerAtomicQuery(ai.grakn.graql.internal.reasoner.query.ReasonerAtomicQuery) MultiUnifier(ai.grakn.graql.admin.MultiUnifier) Unifier(ai.grakn.graql.admin.Unifier) Test(org.junit.Test)

Example 17 with MultiUnifier

use of ai.grakn.graql.admin.MultiUnifier in project grakn by graknlabs.

the class AtomicQueryTest method testExactUnification_TernaryRelation_ParentRepeatsRoles_ParentRepeatsRPs.

@Test
public void testExactUnification_TernaryRelation_ParentRepeatsRoles_ParentRepeatsRPs() {
    EmbeddedGraknTx<?> graph = unificationWithTypesSet.tx();
    String parentString = "{(role1: $x, role1: $x, role2: $y) isa ternary;}";
    String childString = "{(role1: $u, role2: $v, role3: $q) isa ternary;}";
    String childString2 = "{(role1: $u, role2: $v, role2: $q) isa ternary;}";
    String childString3 = "{(role1: $u, role1: $v, role2: $q) isa ternary;}";
    String childString4 = "{(role1: $u, role1: $u, role2: $q) isa ternary;}";
    Conjunction<VarPatternAdmin> parentPattern = conjunction(parentString, graph);
    Conjunction<VarPatternAdmin> childPattern = conjunction(childString, graph);
    Conjunction<VarPatternAdmin> childPattern2 = conjunction(childString2, graph);
    Conjunction<VarPatternAdmin> childPattern3 = conjunction(childString3, graph);
    Conjunction<VarPatternAdmin> childPattern4 = conjunction(childString4, graph);
    ReasonerAtomicQuery parentQuery = ReasonerQueries.atomic(parentPattern, graph);
    ReasonerAtomicQuery childQuery = ReasonerQueries.atomic(childPattern, graph);
    ReasonerAtomicQuery childQuery2 = ReasonerQueries.atomic(childPattern2, graph);
    ReasonerAtomicQuery childQuery3 = ReasonerQueries.atomic(childPattern3, graph);
    ReasonerAtomicQuery childQuery4 = ReasonerQueries.atomic(childPattern4, graph);
    MultiUnifier emptyUnifier = childQuery.getMultiUnifier(parentQuery);
    MultiUnifier emptyUnifier2 = childQuery2.getMultiUnifier(parentQuery);
    assertTrue(emptyUnifier.isEmpty());
    assertTrue(emptyUnifier2.isEmpty());
    Unifier unifier = childQuery3.getMultiUnifier(parentQuery).getUnifier();
    Unifier correctUnifier = new UnifierImpl(ImmutableMultimap.of(var("u"), var("x"), var("v"), var("x"), var("q"), var("y")));
    assertTrue(unifier.containsAll(correctUnifier));
    Unifier unifier2 = childQuery4.getMultiUnifier(parentQuery).getUnifier();
    Unifier correctUnifier2 = new UnifierImpl(ImmutableMultimap.of(var("u"), var("x"), var("q"), var("y")));
    assertTrue(unifier2.containsAll(correctUnifier2));
}
Also used : VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) MultiUnifier(ai.grakn.graql.admin.MultiUnifier) ReasonerAtomicQuery(ai.grakn.graql.internal.reasoner.query.ReasonerAtomicQuery) MultiUnifier(ai.grakn.graql.admin.MultiUnifier) Unifier(ai.grakn.graql.admin.Unifier) Test(org.junit.Test)

Aggregations

MultiUnifier (ai.grakn.graql.admin.MultiUnifier)17 Unifier (ai.grakn.graql.admin.Unifier)10 VarPatternAdmin (ai.grakn.graql.admin.VarPatternAdmin)9 Answer (ai.grakn.graql.admin.Answer)8 MultiUnifierImpl (ai.grakn.graql.internal.reasoner.MultiUnifierImpl)8 Pair (ai.grakn.graql.internal.reasoner.utils.Pair)7 Set (java.util.Set)7 Collectors (java.util.stream.Collectors)7 Test (org.junit.Test)7 ReasonerAtomicQuery (ai.grakn.graql.internal.reasoner.query.ReasonerAtomicQuery)6 Stream (java.util.stream.Stream)6 Var (ai.grakn.graql.Var)5 QueryAnswer (ai.grakn.graql.internal.query.QueryAnswer)5 Atom (ai.grakn.graql.internal.reasoner.atom.Atom)5 HashSet (java.util.HashSet)5 Map (java.util.Map)5 Concept (ai.grakn.concept.Concept)4 GraqlQueryException (ai.grakn.exception.GraqlQueryException)4 Atomic (ai.grakn.graql.admin.Atomic)4 Conjunction (ai.grakn.graql.admin.Conjunction)4