use of ai.grakn.graql.internal.reasoner.atom.binary.RelationshipAtom in project grakn by graknlabs.
the class AtomicTest method roleInference.
private void roleInference(String patternString, ImmutableSetMultimap<Role, Var> expectedRoleMAp, EmbeddedGraknTx<?> graph) {
RelationshipAtom atom = (RelationshipAtom) ReasonerQueries.atomic(conjunction(patternString, graph), graph).getAtom();
Multimap<Role, Var> roleMap = roleSetMap(atom.getRoleVarMap());
assertEquals(expectedRoleMAp, roleMap);
}
use of ai.grakn.graql.internal.reasoner.atom.binary.RelationshipAtom in project grakn by graknlabs.
the class AtomicTest method testRoleInference_AllRolePlayersHaveAmbiguousRoles.
// for each role player role mapping is ambiguous so metarole has to be assigned
@Test
public void testRoleInference_AllRolePlayersHaveAmbiguousRoles() {
EmbeddedGraknTx<?> graph = ruleApplicabilitySet.tx();
String relationString = "{($x, $y, $z) isa ternary;$x isa twoRoleEntity; $y isa threeRoleEntity; $z isa anotherTwoRoleEntity;}";
RelationshipAtom relation = (RelationshipAtom) ReasonerQueries.atomic(conjunction(relationString, graph), graph).getAtom();
relation.getRoleVarMap().entries().forEach(e -> assertTrue(Schema.MetaSchema.isMetaLabel(e.getKey().getLabel())));
}
use of ai.grakn.graql.internal.reasoner.atom.binary.RelationshipAtom in project grakn by graknlabs.
the class AtomicTest method testRoleInference_RoleMappingUnambiguous.
// entity1 plays role1, entity2 plays 2 roles, entity3 plays 3 roles hence ambiguous and metarole has to be assigned, EXPECTED TO CHANGE WITH CARDINALITY CONSTRAINTS
@Test
public void testRoleInference_RoleMappingUnambiguous() {
EmbeddedGraknTx<?> graph = ruleApplicabilitySet.tx();
String relationString = "{($x, $y, $z) isa ternary;$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("role1"), var("x"), graph.getRole("role"), var("y"), graph.getRole("role"), var("z"));
assertEquals(roleMap, roleSetMap(relation.getRoleVarMap()));
}
use of ai.grakn.graql.internal.reasoner.atom.binary.RelationshipAtom in project grakn by graknlabs.
the class AtomicTest method testRuleApplicability_WithWildcard.
// should assign (role : $x, role1: $y, role: $z) which is compatible with 3 ternary rules
@Test
public void testRuleApplicability_WithWildcard() {
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 twoRoleEntity;}";
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(3, relation.getApplicableRules().count());
}
use of ai.grakn.graql.internal.reasoner.atom.binary.RelationshipAtom in project grakn by graknlabs.
the class AtomicTest method testRoleInference_NoInformationPresent.
// for each role player role mapping is ambiguous so metarole has to be assigned
@Test
public void testRoleInference_NoInformationPresent() {
EmbeddedGraknTx<?> graph = roleInferenceSet.tx();
String relationString = "{($x, $y);}";
RelationshipAtom relation = (RelationshipAtom) ReasonerQueries.atomic(conjunction(relationString, graph), graph).getAtom();
relation.getRoleVarMap().entries().forEach(e -> assertTrue(Schema.MetaSchema.isMetaLabel(e.getKey().getLabel())));
}
Aggregations