Search in sources :

Example 41 with RelationshipType

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

the class ValidateGlobalRulesTest method testValidatePlaysStructureUnique.

@Test
public void testValidatePlaysStructureUnique() {
    Role role1 = tx.putRole("role1");
    Role role2 = tx.putRole("role2");
    RelationshipType relationshipType = tx.putRelationshipType("rt").relates(role1).relates(role2);
    EntityType entityType = tx.putEntityType("et");
    ((EntityTypeImpl) entityType).plays(role1, true);
    ((EntityTypeImpl) entityType).plays(role2, false);
    Entity other1 = entityType.addEntity();
    Entity other2 = entityType.addEntity();
    EntityImpl entity = (EntityImpl) entityType.addEntity();
    RelationshipImpl relation1 = (RelationshipImpl) relationshipType.addRelationship().addRolePlayer(role2, other1).addRolePlayer(role1, entity);
    // Valid with only a single relation
    relation1.reified().get().castingsRelation().forEach(rolePlayer -> assertTrue(ValidateGlobalRules.validatePlaysAndRelatesStructure(rolePlayer).isEmpty()));
    RelationshipImpl relation2 = (RelationshipImpl) relationshipType.addRelationship().addRolePlayer(role2, other2).addRolePlayer(role1, entity);
    // Invalid with multiple relations
    relation1.reified().get().castingsRelation().forEach(rolePlayer -> {
        if (rolePlayer.getRole().equals(role1)) {
            assertFalse(ValidateGlobalRules.validatePlaysAndRelatesStructure(rolePlayer).isEmpty());
        }
    });
    relation2.reified().get().castingsRelation().forEach(rolePlayer -> {
        if (rolePlayer.getRole().equals(role1)) {
            assertFalse(ValidateGlobalRules.validatePlaysAndRelatesStructure(rolePlayer).isEmpty());
        }
    });
}
Also used : Role(ai.grakn.concept.Role) EntityType(ai.grakn.concept.EntityType) Entity(ai.grakn.concept.Entity) EntityImpl(ai.grakn.kb.internal.concept.EntityImpl) RelationshipType(ai.grakn.concept.RelationshipType) EntityTypeImpl(ai.grakn.kb.internal.concept.EntityTypeImpl) RelationshipImpl(ai.grakn.kb.internal.concept.RelationshipImpl) Test(org.junit.Test)

Example 42 with RelationshipType

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

the class ValidateGlobalRulesTest method testValidatePlaysStructure.

@Test
public void testValidatePlaysStructure() throws Exception {
    EntityTypeImpl wolf = (EntityTypeImpl) tx.putEntityType("wolf");
    EntityTypeImpl creature = (EntityTypeImpl) tx.putEntityType("creature");
    EntityTypeImpl hunter = (EntityTypeImpl) tx.putEntityType("hunter");
    RelationshipType hunts = tx.putRelationshipType("hunts");
    RoleImpl witcher = (RoleImpl) tx.putRole("witcher");
    RoleImpl monster = (RoleImpl) tx.putRole("monster");
    Thing geralt = hunter.addEntity();
    ThingImpl werewolf = (ThingImpl) wolf.addEntity();
    RelationshipImpl assertion = (RelationshipImpl) hunts.addRelationship().addRolePlayer(witcher, geralt).addRolePlayer(monster, werewolf);
    assertion.reified().get().castingsRelation().forEach(rolePlayer -> assertFalse(ValidateGlobalRules.validatePlaysAndRelatesStructure(rolePlayer).isEmpty()));
    hunter.plays(witcher);
    boolean[] flags = { false, false };
    int count = 0;
    for (Casting casting : assertion.reified().get().castingsRelation().collect(Collectors.toSet())) {
        flags[count] = !ValidateGlobalRules.validatePlaysAndRelatesStructure(casting).isEmpty();
        count++;
    }
    assertTrue(flags[0] && flags[1]);
    wolf.sup(creature);
    creature.plays(monster);
    for (Casting casting : assertion.reified().get().castingsRelation().collect(Collectors.toSet())) {
        assertFalse(ValidateGlobalRules.validatePlaysAndRelatesStructure(casting).isEmpty());
    }
}
Also used : Casting(ai.grakn.kb.internal.structure.Casting) RoleImpl(ai.grakn.kb.internal.concept.RoleImpl) EntityTypeImpl(ai.grakn.kb.internal.concept.EntityTypeImpl) RelationshipType(ai.grakn.concept.RelationshipType) RelationshipImpl(ai.grakn.kb.internal.concept.RelationshipImpl) Thing(ai.grakn.concept.Thing) ThingImpl(ai.grakn.kb.internal.concept.ThingImpl) Test(org.junit.Test)

Example 43 with RelationshipType

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

the class ValidateGlobalRulesTest method testAbstractConceptValidation.

@Test
public void testAbstractConceptValidation() {
    Role role = tx.putRole("relates");
    RelationshipType relationshipType = tx.putRelationshipType("relationTypes");
    assertTrue(ValidateGlobalRules.validateHasSingleIncomingRelatesEdge(role).isPresent());
    assertTrue(ValidateGlobalRules.validateHasMinimumRoles(relationshipType).isPresent());
    relationshipType.setAbstract(true);
    assertTrue(ValidateGlobalRules.validateHasSingleIncomingRelatesEdge(role).isPresent());
    assertFalse(ValidateGlobalRules.validateHasMinimumRoles(relationshipType).isPresent());
}
Also used : Role(ai.grakn.concept.Role) RelationshipType(ai.grakn.concept.RelationshipType) Test(org.junit.Test)

Example 44 with RelationshipType

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

the class ValidateGlobalRulesTest method testValidateRelationTypeRelates.

@Test
public void testValidateRelationTypeRelates() throws Exception {
    Role hunter = tx.putRole("hunter");
    RelationshipType kills = tx.putRelationshipType("kills");
    assertTrue(ValidateGlobalRules.validateHasMinimumRoles(kills).isPresent());
    kills.relates(hunter);
    assertFalse(ValidateGlobalRules.validateHasMinimumRoles(kills).isPresent());
}
Also used : Role(ai.grakn.concept.Role) RelationshipType(ai.grakn.concept.RelationshipType) Test(org.junit.Test)

Example 45 with RelationshipType

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

the class GraknTxTest method whenGettingSubTypesFromRootMeta_IncludeAllTypes.

@Test
public void whenGettingSubTypesFromRootMeta_IncludeAllTypes() {
    EntityType sampleEntityType = tx.putEntityType("Sample Entity Type");
    RelationshipType sampleRelationshipType = tx.putRelationshipType("Sample Relationship Type");
    assertThat(tx.getMetaConcept().subs().collect(toSet()), containsInAnyOrder(tx.getMetaConcept(), tx.getMetaRelationType(), tx.getMetaEntityType(), tx.getMetaAttributeType(), sampleEntityType, sampleRelationshipType));
}
Also used : EntityType(ai.grakn.concept.EntityType) RelationshipType(ai.grakn.concept.RelationshipType) Test(org.junit.Test)

Aggregations

RelationshipType (ai.grakn.concept.RelationshipType)127 Role (ai.grakn.concept.Role)105 Test (org.junit.Test)91 EntityType (ai.grakn.concept.EntityType)80 Entity (ai.grakn.concept.Entity)52 GraknTx (ai.grakn.GraknTx)39 Relationship (ai.grakn.concept.Relationship)25 ConceptId (ai.grakn.concept.ConceptId)23 Label (ai.grakn.concept.Label)21 HashSet (java.util.HashSet)20 Set (java.util.Set)20 AttributeType (ai.grakn.concept.AttributeType)17 Thing (ai.grakn.concept.Thing)17 Attribute (ai.grakn.concept.Attribute)16 Schema (ai.grakn.util.Schema)12 Collectors (java.util.stream.Collectors)12 List (java.util.List)11 GraknSession (ai.grakn.GraknSession)10 GraknTxType (ai.grakn.GraknTxType)10 Concept (ai.grakn.concept.Concept)10