use of ai.grakn.graql.admin.VarPatternAdmin in project grakn by graknlabs.
the class AtomicQueryTest method testExactUnification_TernaryRelationWithTypes_AllVarsHaveTypes_UnifierMatchesTypes.
@Test
public void testExactUnification_TernaryRelationWithTypes_AllVarsHaveTypes_UnifierMatchesTypes() {
EmbeddedGraknTx<?> graph = unificationWithTypesSet.tx();
String patternString = "{$x1 isa threeRoleEntity;$x2 isa threeRoleEntity2; $x3 isa threeRoleEntity3;($x1, $x2, $x3) isa ternary;}";
String patternString2 = "{$y3 isa threeRoleEntity3;$y2 isa threeRoleEntity2;$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));
}
use of ai.grakn.graql.admin.VarPatternAdmin in project grakn by graknlabs.
the class AtomicQueryTest method testExactUnification_TernaryRelationWithTypes_AllVarsHaveTypes_UnifierMatchesTypes_TypeHierarchyInvolved.
// subSubThreeRoleEntity sub subThreeRoleEntity sub threeRoleEntity3
@Test
public void testExactUnification_TernaryRelationWithTypes_AllVarsHaveTypes_UnifierMatchesTypes_TypeHierarchyInvolved() {
EmbeddedGraknTx<?> graph = unificationWithTypesSet.tx();
String parentString = "{$x1 isa threeRoleEntity;$x2 isa subThreeRoleEntity; $x3 isa subSubThreeRoleEntity;($x1, $x2, $x3) isa ternary;}";
String childString = "{$y1 isa threeRoleEntity;$y2 isa subThreeRoleEntity;$y3 isa subSubThreeRoleEntity;($y2, $y3, $y1) isa ternary;}";
String childString2 = "{$y1 isa threeRoleEntity;$y2 isa subThreeRoleEntity;$y3 isa subSubThreeRoleEntity;(role2: $y2, role3: $y3, role1: $y1) isa ternary;}";
Conjunction<VarPatternAdmin> pattern = conjunction(parentString, graph);
Conjunction<VarPatternAdmin> pattern2 = conjunction(childString, graph);
Conjunction<VarPatternAdmin> pattern3 = conjunction(childString2, graph);
ReasonerAtomicQuery parentQuery = ReasonerQueries.atomic(pattern, graph);
ReasonerAtomicQuery childQuery = ReasonerQueries.atomic(pattern2, graph);
ReasonerAtomicQuery childQuery2 = ReasonerQueries.atomic(pattern3, graph);
MultiUnifier unifier = childQuery.getMultiUnifier(parentQuery);
MultiUnifier unifier2 = childQuery2.getMultiUnifier(parentQuery);
MultiUnifier correctUnifier = new MultiUnifierImpl(ImmutableMultimap.of(var("y1"), var("x1"), var("y2"), var("x2"), var("y3"), var("x3")), ImmutableMultimap.of(var("y1"), var("x1"), var("y2"), var("x3"), var("y3"), var("x2")), ImmutableMultimap.of(var("y1"), var("x2"), var("y2"), var("x1"), var("y3"), var("x3")), ImmutableMultimap.of(var("y1"), var("x2"), var("y2"), var("x3"), var("y3"), var("x1")), ImmutableMultimap.of(var("y1"), var("x3"), var("y2"), var("x1"), var("y3"), var("x2")), ImmutableMultimap.of(var("y1"), var("x3"), var("y2"), var("x2"), var("y3"), var("x1")));
assertTrue(unifier.containsAll(correctUnifier));
assertTrue(unifier2.containsAll(correctUnifier));
}
use of ai.grakn.graql.admin.VarPatternAdmin in project grakn by graknlabs.
the class AtomicQueryTest method testExactUnification_TernaryRelation_ParentRepeatsRoles.
@Test
public void testExactUnification_TernaryRelation_ParentRepeatsRoles() {
EmbeddedGraknTx<?> graph = unificationWithTypesSet.tx();
String parentString = "{(role1: $x, role1: $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 emptyUnifier = childQuery.getMultiUnifier(parentQuery);
MultiUnifier emptyUnifier2 = childQuery2.getMultiUnifier(parentQuery);
assertTrue(emptyUnifier.isEmpty());
assertTrue(emptyUnifier2.isEmpty());
MultiUnifier unifier = childQuery3.getMultiUnifier(parentQuery);
MultiUnifier correctUnifier = 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(unifier.containsAll(correctUnifier));
assertEquals(unifier.size(), 2);
Unifier unifier2 = childQuery4.getMultiUnifier(parentQuery).getUnifier();
Unifier correctUnifier2 = new UnifierImpl(ImmutableMultimap.of(var("u"), var("x"), var("u"), var("y"), var("q"), var("z")));
assertTrue(unifier2.containsAll(correctUnifier2));
}
use of ai.grakn.graql.admin.VarPatternAdmin in project grakn by graknlabs.
the class AtomicTest method testUnification_IndirectRoles_NoRelationType.
@Test
public void testUnification_IndirectRoles_NoRelationType() {
EmbeddedGraknTx<?> graph = unificationTestSet.tx();
VarPatternAdmin basePattern = var().rel(var("role1").label("subRole1"), var("y1")).rel(var("role2").label("subSubRole2"), var("y2")).admin();
ReasonerAtomicQuery baseQuery = ReasonerQueries.atomic(Patterns.conjunction(Sets.newHashSet(basePattern)), graph);
ReasonerAtomicQuery childQuery = ReasonerQueries.atomic(conjunction("{($r1: $x1, $r2: $x2);" + "$r1 label 'subRole1';" + "$r2 label 'subSubRole2';}", graph), graph);
ReasonerAtomicQuery parentQuery = ReasonerQueries.atomic(conjunction("{($R1: $x, $R2: $y);" + "$R1 label 'subRole1';" + "$R2 label 'subSubRole2';}", graph), graph);
exactUnification(parentQuery, childQuery, true, true);
exactUnification(baseQuery, parentQuery, true, true);
exactUnification(baseQuery, childQuery, true, true);
}
use of ai.grakn.graql.admin.VarPatternAdmin in project grakn by graknlabs.
the class QueryTest method testAlphaEquivalence_RelationsWithSubstitution.
@Test
public void testAlphaEquivalence_RelationsWithSubstitution() {
EmbeddedGraknTx<?> graph = geoKB.tx();
String patternString = "{(role: $x, role: $y);$x id 'V666';}";
String patternString2 = "{(role: $x, role: $y);$y id 'V666';}";
String patternString3 = "{(role: $x, role: $y);$x id 'V666';$y id 'V667';}";
String patternString4 = "{(role: $x, role: $y);$y id 'V666';$x id 'V667';}";
String patternString5 = "{(entity-location: $x, geo-entity: $y);$x id 'V666';$y id 'V667';}";
String patternString6 = "{(entity-location: $x, geo-entity: $y);$y id 'V666';$x id 'V667';}";
String patternString7 = "{(role: $x, role: $y);$x id 'V666';$y id 'V666';}";
Conjunction<VarPatternAdmin> pattern = conjunction(patternString, graph);
Conjunction<VarPatternAdmin> pattern2 = conjunction(patternString2, graph);
Conjunction<VarPatternAdmin> pattern3 = conjunction(patternString3, graph);
Conjunction<VarPatternAdmin> pattern4 = conjunction(patternString4, graph);
Conjunction<VarPatternAdmin> pattern5 = conjunction(patternString5, graph);
Conjunction<VarPatternAdmin> pattern6 = conjunction(patternString6, graph);
Conjunction<VarPatternAdmin> pattern7 = conjunction(patternString7, graph);
ReasonerAtomicQuery query = ReasonerQueries.atomic(pattern, graph);
ReasonerAtomicQuery query2 = ReasonerQueries.atomic(pattern2, graph);
ReasonerAtomicQuery query3 = ReasonerQueries.atomic(pattern3, graph);
ReasonerAtomicQuery query4 = ReasonerQueries.atomic(pattern4, graph);
ReasonerAtomicQuery query5 = ReasonerQueries.atomic(pattern5, graph);
ReasonerAtomicQuery query6 = ReasonerQueries.atomic(pattern6, graph);
ReasonerAtomicQuery query7 = ReasonerQueries.atomic(pattern7, graph);
queryEquivalence(query, query2, true);
queryEquivalence(query, query3, false);
queryEquivalence(query, query4, false);
queryEquivalence(query, query5, false);
queryEquivalence(query, query6, false);
queryEquivalence(query, query7, false);
queryEquivalence(query2, query3, false);
queryEquivalence(query2, query4, false);
queryEquivalence(query2, query5, false);
queryEquivalence(query2, query6, false);
queryEquivalence(query2, query7, false);
queryEquivalence(query3, query4, true);
queryEquivalence(query3, query5, false);
queryEquivalence(query3, query6, false);
queryEquivalence(query3, query7, false);
queryEquivalence(query4, query5, false);
queryEquivalence(query4, query6, false);
queryEquivalence(query4, query7, false);
queryEquivalence(query5, query6, false);
queryEquivalence(query5, query7, false);
queryEquivalence(query6, query7, false);
}
Aggregations