use of ai.grakn.graql.Var in project grakn by graknlabs.
the class QueryAnswerTest method whenGettingAConceptThatIsNotInTheAnswer_Throw.
@Test
public void whenGettingAConceptThatIsNotInTheAnswer_Throw() {
Var varNotInAnswer = var("y");
exception.expect(GraqlQueryException.class);
exception.expectMessage(GraqlQueryException.varNotInQuery(varNotInAnswer).getMessage());
answer.get(varNotInAnswer);
}
use of ai.grakn.graql.Var in project grakn by graknlabs.
the class AtomicTest method testRoleInference_RoleHierarchyInvolved.
// missing role is ambiguous without cardinality constraints
@Test
public void testRoleInference_RoleHierarchyInvolved() {
EmbeddedGraknTx<?> graph = unificationTestSet.tx();
String relationString = "{($p, subRole2: $gc) isa binary;}";
String relationString2 = "{(subRole1: $gp, $p) isa binary;}";
RelationshipAtom relation = (RelationshipAtom) ReasonerQueries.atomic(conjunction(relationString, graph), graph).getAtom();
RelationshipAtom relation2 = (RelationshipAtom) ReasonerQueries.atomic(conjunction(relationString2, graph), graph).getAtom();
Multimap<Role, Var> roleMap = roleSetMap(relation.getRoleVarMap());
Multimap<Role, Var> roleMap2 = roleSetMap(relation2.getRoleVarMap());
ImmutableSetMultimap<Role, Var> correctRoleMap = ImmutableSetMultimap.of(graph.getRole("role"), var("p"), graph.getRole("subRole2"), var("gc"));
ImmutableSetMultimap<Role, Var> correctRoleMap2 = ImmutableSetMultimap.of(graph.getRole("role"), var("p"), graph.getRole("subRole1"), var("gp"));
assertEquals(correctRoleMap, roleMap);
assertEquals(correctRoleMap2, roleMap2);
}
use of ai.grakn.graql.Var in project grakn by graknlabs.
the class AtomicTest method testRuleApplicability_AmbiguousRoleMapping_RolePlayerTypeMismatch.
@Test
public void testRuleApplicability_AmbiguousRoleMapping_RolePlayerTypeMismatch() {
EmbeddedGraknTx<?> graph = ruleApplicabilitySet.tx();
// although singleRoleEntity plays only one role it can also play an implicit role of the resource so mapping ambiguous
String relationString = "{($x, $y, $z);$x isa singleRoleEntity; $y isa twoRoleEntity; $z isa threeRoleEntity;}";
RelationshipAtom relation = (RelationshipAtom) ReasonerQueries.atomic(conjunction(relationString, graph), graph).getAtom();
ImmutableSetMultimap<Role, Var> roleMap = ImmutableSetMultimap.of(graph.getRole("role"), var("x"), graph.getRole("role"), var("y"), graph.getRole("role"), var("z"));
assertEquals(roleMap, roleSetMap(relation.getRoleVarMap()));
assertEquals(2, relation.getApplicableRules().count());
}
use of ai.grakn.graql.Var in project grakn by graknlabs.
the class AtomicTest method testRuleApplicability_WithWildcard_MissingMappings.
@Test
public void testRuleApplicability_WithWildcard_MissingMappings() {
EmbeddedGraknTx<?> graph = ruleApplicabilitySet.tx();
// although singleRoleEntity plays only one role it can also play an implicit role of the resource so mapping ambiguous
String relationString = "{($x, $y, $z);$y isa singleRoleEntity; $z isa singleRoleEntity;}";
RelationshipAtom relation = (RelationshipAtom) ReasonerQueries.atomic(conjunction(relationString, graph), graph).getAtom();
ImmutableSetMultimap<Role, Var> roleMap = ImmutableSetMultimap.of(graph.getRole("role"), var("x"), graph.getRole("role"), var("y"), graph.getRole("role"), var("z"));
assertEquals(roleMap, roleSetMap(relation.getRoleVarMap()));
assertThat(relation.getApplicableRules().collect(toSet()), empty());
}
use of ai.grakn.graql.Var in project grakn by graknlabs.
the class AtomicTest method testRoleInference_WithMetaType.
// entity1 plays role1 but entity2 plays roles role1, role2 hence ambiguous and metarole has to be assigned, EXPECTED TO CHANGE WITH CARDINALITY CONSTRAINTS
@Test
public void testRoleInference_WithMetaType() {
EmbeddedGraknTx<?> graph = ruleApplicabilitySet.tx();
String relationString = "{($x, $y, $z) isa ternary;$x isa singleRoleEntity; $y isa twoRoleEntity; $z isa entity;}";
RelationshipAtom relation = (RelationshipAtom) ReasonerQueries.atomic(conjunction(relationString, graph), graph).getAtom();
ImmutableSetMultimap<Role, Var> roleMap = ImmutableSetMultimap.of(graph.getRole("role1"), var("x"), graph.getRole("role"), var("y"), graph.getRole("role"), var("z"));
assertEquals(roleMap, roleSetMap(relation.getRoleVarMap()));
}
Aggregations