Search in sources :

Example 11 with RelationshipAtom

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

Example 12 with RelationshipAtom

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

Example 13 with RelationshipAtom

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()));
}
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 14 with RelationshipAtom

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());
}
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 15 with RelationshipAtom

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())));
}
Also used : 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