Search in sources :

Example 86 with Role

use of ai.grakn.concept.Role in project grakn by graknlabs.

the class GraqlPrinterTest method whenPrintingRole_ShowLabel.

@Test
public void whenPrintingRole_ShowLabel() {
    Printer printer = Printers.graql(true);
    Role role = rule.tx().admin().getMetaRole();
    String roleString = printer.graqlString(role);
    assertThat(roleString, containsString("role"));
}
Also used : Role(ai.grakn.concept.Role) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Printer(ai.grakn.graql.Printer) Test(org.junit.Test)

Example 87 with Role

use of ai.grakn.concept.Role 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)

Example 88 with Role

use of ai.grakn.concept.Role 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());
}
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 89 with Role

use of ai.grakn.concept.Role 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());
}
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 90 with Role

use of ai.grakn.concept.Role 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()));
}
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

Role (ai.grakn.concept.Role)189 Test (org.junit.Test)124 RelationshipType (ai.grakn.concept.RelationshipType)114 EntityType (ai.grakn.concept.EntityType)92 Entity (ai.grakn.concept.Entity)55 GraknTx (ai.grakn.GraknTx)48 Relationship (ai.grakn.concept.Relationship)37 Set (java.util.Set)36 ConceptId (ai.grakn.concept.ConceptId)33 Label (ai.grakn.concept.Label)33 Thing (ai.grakn.concept.Thing)32 HashSet (java.util.HashSet)31 Var (ai.grakn.graql.Var)25 AttributeType (ai.grakn.concept.AttributeType)21 Concept (ai.grakn.concept.Concept)20 Schema (ai.grakn.util.Schema)17 Collectors (java.util.stream.Collectors)17 Attribute (ai.grakn.concept.Attribute)16 SchemaConcept (ai.grakn.concept.SchemaConcept)16 Type (ai.grakn.concept.Type)16