Search in sources :

Example 1 with RoleImpl

use of ai.grakn.kb.internal.concept.RoleImpl 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)

Aggregations

RelationshipType (ai.grakn.concept.RelationshipType)1 Thing (ai.grakn.concept.Thing)1 EntityTypeImpl (ai.grakn.kb.internal.concept.EntityTypeImpl)1 RelationshipImpl (ai.grakn.kb.internal.concept.RelationshipImpl)1 RoleImpl (ai.grakn.kb.internal.concept.RoleImpl)1 ThingImpl (ai.grakn.kb.internal.concept.ThingImpl)1 Casting (ai.grakn.kb.internal.structure.Casting)1 Test (org.junit.Test)1