use of ai.grakn.graql.internal.reasoner.atom.binary.RelationshipAtom in project grakn by graknlabs.
the class AtomicTest method testRoleInference_RelationHasVerticalRoleHierarchy.
// relation relates a single role so instead of assigning metarole this role should be assigned
@Test
public void testRoleInference_RelationHasVerticalRoleHierarchy() {
EmbeddedGraknTx<?> graph = ruleApplicabilitySet.tx();
String relationString = "{($x, $y) isa reifying-relation;}";
RelationshipAtom relation = (RelationshipAtom) ReasonerQueries.atomic(conjunction(relationString, graph), graph).getAtom();
ImmutableSetMultimap<Role, Var> roleMap = ImmutableSetMultimap.of(graph.getRole("role1"), var("x"), graph.getRole("role1"), var("y"));
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_AmbiguousRoleMapping_TypeHierarchyEnablesExtraRule.
// threeRoleEntity subs twoRoleEntity -> (role, role, role)
@Test
public void testRuleApplicability_AmbiguousRoleMapping_TypeHierarchyEnablesExtraRule() {
EmbeddedGraknTx<?> graph = ruleApplicabilitySet.tx();
String relationString = "{($x, $y, $z);$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())));
assertEquals(2, relation.getApplicableRules().count());
}
use of ai.grakn.graql.internal.reasoner.atom.binary.RelationshipAtom in project grakn by graknlabs.
the class AtomicTest method testRuleApplicability_AmbiguousRoleMapping.
@Test
public void testRuleApplicability_AmbiguousRoleMapping() {
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 anotherTwoRoleEntity; $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_MetaRelationType.
// for each role player role mapping is ambiguous so metarole has to be assigned
@Test
public void testRoleInference_MetaRelationType() {
EmbeddedGraknTx<?> graph = roleInferenceSet.tx();
String relationString = "{($x, $y) isa relationship;}";
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_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);
}
Aggregations