Search in sources :

Example 1 with RelationshipAtom

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()));
}
Also used : Role(ai.grakn.concept.Role) Var(ai.grakn.graql.Var) RelationshipAtom(ai.grakn.graql.internal.reasoner.atom.binary.RelationshipAtom) Test(org.junit.Test)

Example 2 with RelationshipAtom

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());
}
Also used : RelationshipAtom(ai.grakn.graql.internal.reasoner.atom.binary.RelationshipAtom) Test(org.junit.Test)

Example 3 with RelationshipAtom

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());
}
Also used : Role(ai.grakn.concept.Role) Var(ai.grakn.graql.Var) RelationshipAtom(ai.grakn.graql.internal.reasoner.atom.binary.RelationshipAtom) Test(org.junit.Test)

Example 4 with RelationshipAtom

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())));
}
Also used : RelationshipAtom(ai.grakn.graql.internal.reasoner.atom.binary.RelationshipAtom) Test(org.junit.Test)

Example 5 with RelationshipAtom

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);
}
Also used : Role(ai.grakn.concept.Role) Var(ai.grakn.graql.Var) RelationshipAtom(ai.grakn.graql.internal.reasoner.atom.binary.RelationshipAtom) Test(org.junit.Test)

Aggregations

RelationshipAtom (ai.grakn.graql.internal.reasoner.atom.binary.RelationshipAtom)15 Test (org.junit.Test)13 Role (ai.grakn.concept.Role)10 Var (ai.grakn.graql.Var)10 RelationshipType (ai.grakn.concept.RelationshipType)1 Type (ai.grakn.concept.Type)1 MultiUnifier (ai.grakn.graql.admin.MultiUnifier)1 Unifier (ai.grakn.graql.admin.Unifier)1 QueryAnswer (ai.grakn.graql.internal.query.QueryAnswer)1 Atom (ai.grakn.graql.internal.reasoner.atom.Atom)1 ResourceAtom (ai.grakn.graql.internal.reasoner.atom.binary.ResourceAtom)1 ReasonerAtomicQuery (ai.grakn.graql.internal.reasoner.query.ReasonerAtomicQuery)1 InferenceRule (ai.grakn.graql.internal.reasoner.rule.InferenceRule)1