Search in sources :

Example 1 with VarPatternAdmin

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

the class AtomicQueryTest method testExactUnification_TernaryRelationWithTypes_RepeatingRelationPlayers_withMetaRoles.

@Test
public void testExactUnification_TernaryRelationWithTypes_RepeatingRelationPlayers_withMetaRoles() {
    EmbeddedGraknTx<?> graph = unificationWithTypesSet.tx();
    String patternString = "{$x1 isa threeRoleEntity;$x3 isa threeRoleEntity3;($x1, $x2, $x3) isa ternary;}";
    String patternString2 = "{$y3 isa threeRoleEntity3;$y1 isa threeRoleEntity;($y2, $y3, $y1) isa ternary;}";
    String patternString3 = "{$y3 isa threeRoleEntity3;$y2 isa threeRoleEntity2;$y1 isa threeRoleEntity;(role2: $y2, role3: $y3, role1: $y1) isa ternary;}";
    Conjunction<VarPatternAdmin> pattern = conjunction(patternString, graph);
    Conjunction<VarPatternAdmin> pattern2 = conjunction(patternString2, graph);
    Conjunction<VarPatternAdmin> pattern3 = conjunction(patternString3, graph);
    ReasonerAtomicQuery parentQuery = ReasonerQueries.atomic(pattern, graph);
    ReasonerAtomicQuery childQuery = ReasonerQueries.atomic(pattern2, graph);
    ReasonerAtomicQuery childQuery2 = ReasonerQueries.atomic(pattern3, graph);
    Unifier unifier = childQuery.getMultiUnifier(parentQuery).getUnifier();
    Unifier unifier2 = childQuery2.getMultiUnifier(parentQuery).getUnifier();
    Unifier correctUnifier = new UnifierImpl(ImmutableMultimap.of(var("y1"), var("x1"), var("y2"), var("x2"), var("y3"), var("x3")));
    assertTrue(unifier.containsAll(correctUnifier));
    assertTrue(unifier2.containsAll(correctUnifier));
}
Also used : VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) 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 2 with VarPatternAdmin

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

the class AtomicQueryTest method testWhenConstructingNonAtomicQuery_ExceptionIsThrown.

@Test
public void testWhenConstructingNonAtomicQuery_ExceptionIsThrown() {
    EmbeddedGraknTx<?> graph = geoKB.tx();
    String patternString = "{$x isa university;$y isa country;($x, $y) isa is-located-in;($y, $z) isa is-located-in;}";
    Conjunction<VarPatternAdmin> pattern = conjunction(patternString, graph);
    exception.expect(GraqlQueryException.class);
    ReasonerAtomicQuery atomicQuery = ReasonerQueries.atomic(pattern, graph);
}
Also used : VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) ReasonerAtomicQuery(ai.grakn.graql.internal.reasoner.query.ReasonerAtomicQuery) Test(org.junit.Test)

Example 3 with VarPatternAdmin

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

the class AtomicQueryTest method testWhenUnifiyingAtomWithItself_UnifierIsIdentity.

@Test
public void testWhenUnifiyingAtomWithItself_UnifierIsIdentity() {
    EmbeddedGraknTx<?> graph = unificationWithTypesSet.tx();
    String patternString = "{$x1 isa twoRoleEntity;$x2 isa twoRoleEntity2;($x1, $x2) isa binary;}";
    Conjunction<VarPatternAdmin> pattern = conjunction(patternString, graph);
    ReasonerAtomicQuery parentQuery = ReasonerQueries.atomic(pattern, graph);
    ReasonerAtomicQuery childQuery = ReasonerQueries.atomic(pattern, graph);
    Unifier unifier = childQuery.getMultiUnifier(parentQuery).getUnifier();
    Unifier unifier2 = parentQuery.getMultiUnifier(parentQuery).getUnifier();
    Unifier unifier3 = childQuery.getMultiUnifier(childQuery).getUnifier();
    assertTrue(Sets.intersection(unifier.keySet(), Sets.newHashSet(var("x"), var("y"))).isEmpty());
    assertTrue(unifier2.isEmpty());
    assertTrue(unifier3.isEmpty());
}
Also used : VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) 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 4 with VarPatternAdmin

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

the class AtomicQueryTest method testExactUnification_TernaryRelationWithTypes_SomeVarsHaveTypes_UnifierMatchesTypes.

@Test
public void testExactUnification_TernaryRelationWithTypes_SomeVarsHaveTypes_UnifierMatchesTypes() {
    EmbeddedGraknTx<?> graph = unificationWithTypesSet.tx();
    String patternString = "{$x1 isa threeRoleEntity;$x3 isa threeRoleEntity3;($x1, $x2, $x3) isa ternary;}";
    String patternString2 = "{$y3 isa threeRoleEntity3;$y1 isa threeRoleEntity;($y2, $y3, $y1) isa ternary;}";
    String patternString3 = "{$y3 isa threeRoleEntity3;$y2 isa threeRoleEntity2;$y1 isa threeRoleEntity;(role2: $y2, role3: $y3, role1: $y1) isa ternary;}";
    Conjunction<VarPatternAdmin> pattern = conjunction(patternString, graph);
    Conjunction<VarPatternAdmin> pattern2 = conjunction(patternString2, graph);
    Conjunction<VarPatternAdmin> pattern3 = conjunction(patternString3, graph);
    ReasonerAtomicQuery parentQuery = ReasonerQueries.atomic(pattern, graph);
    ReasonerAtomicQuery childQuery = ReasonerQueries.atomic(pattern2, graph);
    ReasonerAtomicQuery childQuery2 = ReasonerQueries.atomic(pattern3, graph);
    Unifier unifier = childQuery.getMultiUnifier(parentQuery).getUnifier();
    Unifier unifier2 = childQuery2.getMultiUnifier(parentQuery).getUnifier();
    Unifier correctUnifier = new UnifierImpl(ImmutableMultimap.of(var("y1"), var("x1"), var("y2"), var("x2"), var("y3"), var("x3")));
    assertTrue(unifier.containsAll(correctUnifier));
    assertTrue(unifier2.containsAll(correctUnifier));
}
Also used : VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) 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 5 with VarPatternAdmin

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

the class AtomicQueryTest method testExactUnification_BinaryRelationWithTypes_AllVarsHaveTypes_UnifierMatchesTypes.

// only a single unifier exists
@Test
public void testExactUnification_BinaryRelationWithTypes_AllVarsHaveTypes_UnifierMatchesTypes() {
    EmbeddedGraknTx<?> graph = unificationWithTypesSet.tx();
    String patternString = "{$x1 isa twoRoleEntity;$x2 isa twoRoleEntity2;($x1, $x2) isa binary;}";
    String patternString2 = "{$y1 isa twoRoleEntity;$y2 isa twoRoleEntity2;($y1, $y2) isa binary;}";
    Conjunction<VarPatternAdmin> pattern = conjunction(patternString, graph);
    Conjunction<VarPatternAdmin> pattern2 = conjunction(patternString2, graph);
    ReasonerAtomicQuery parentQuery = ReasonerQueries.atomic(pattern, graph);
    ReasonerAtomicQuery childQuery = ReasonerQueries.atomic(pattern2, graph);
    Unifier unifier = childQuery.getMultiUnifier(parentQuery).getUnifier();
    Unifier correctUnifier = new UnifierImpl(ImmutableMultimap.of(var("y1"), var("x1"), var("y2"), var("x2")));
    assertTrue(unifier.containsAll(correctUnifier));
}
Also used : VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) 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

VarPatternAdmin (ai.grakn.graql.admin.VarPatternAdmin)55 Test (org.junit.Test)20 Var (ai.grakn.graql.Var)17 ReasonerAtomicQuery (ai.grakn.graql.internal.reasoner.query.ReasonerAtomicQuery)17 MultiUnifier (ai.grakn.graql.admin.MultiUnifier)16 Unifier (ai.grakn.graql.admin.Unifier)15 ConceptId (ai.grakn.concept.ConceptId)13 Label (ai.grakn.concept.Label)13 IdPredicate (ai.grakn.graql.internal.reasoner.atom.predicate.IdPredicate)13 Role (ai.grakn.concept.Role)11 GraknTx (ai.grakn.GraknTx)10 VarProperty (ai.grakn.graql.admin.VarProperty)10 Collection (java.util.Collection)10 Set (java.util.Set)10 Stream (java.util.stream.Stream)10 SchemaConcept (ai.grakn.concept.SchemaConcept)9 GraqlQueryException (ai.grakn.exception.GraqlQueryException)9 VarPattern (ai.grakn.graql.VarPattern)9 ReasonerQuery (ai.grakn.graql.admin.ReasonerQuery)9 RelationPlayer (ai.grakn.graql.admin.RelationPlayer)9