Search in sources :

Example 96 with RelationshipType

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

the class MigratorTestUtils method assertRelationBetweenInstancesExists.

public static void assertRelationBetweenInstancesExists(GraknTx graph, Thing thing1, Thing thing2, Label relation) {
    RelationshipType relationshipType = graph.getSchemaConcept(relation);
    Role role1 = thing1.plays().filter(r -> r.relationshipTypes().anyMatch(rel -> rel.equals(relationshipType))).findFirst().get();
    assertTrue(thing1.relationships(role1).anyMatch(rel -> rel.rolePlayers().anyMatch(r -> r.equals(thing2))));
}
Also used : Role(ai.grakn.concept.Role) InvalidKBException(ai.grakn.exception.InvalidKBException) Role(ai.grakn.concept.Role) Concept(ai.grakn.concept.Concept) Entity(ai.grakn.concept.Entity) Attribute(ai.grakn.concept.Attribute) HashSet(java.util.HashSet) Label(ai.grakn.concept.Label) AttributeType(ai.grakn.concept.AttributeType) RelationshipType(ai.grakn.concept.RelationshipType) Files(com.google.common.io.Files) GraknTx(ai.grakn.GraknTx) Relationship(ai.grakn.concept.Relationship) GraknTxType(ai.grakn.GraknTxType) Assert.assertNotNull(org.junit.Assert.assertNotNull) Collection(java.util.Collection) GraknSession(ai.grakn.GraknSession) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) Collectors.joining(java.util.stream.Collectors.joining) Stream(java.util.stream.Stream) Thing(ai.grakn.concept.Thing) Schema(ai.grakn.util.Schema) TestCase.assertEquals(junit.framework.TestCase.assertEquals) RelationshipType(ai.grakn.concept.RelationshipType)

Example 97 with RelationshipType

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

the class GraknTxPutPropertyTest method whenCallingPutRelationType_CreateATypeThatOwnsNoRoles.

@Property
public void whenCallingPutRelationType_CreateATypeThatOwnsNoRoles(@Open GraknTx graph, @Unused Label label) {
    RelationshipType relationshipType = graph.putRelationshipType(label);
    assertThat(relationshipType.relates().collect(toSet()), empty());
}
Also used : RelationshipType(ai.grakn.concept.RelationshipType) Property(com.pholser.junit.quickcheck.Property)

Example 98 with RelationshipType

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

the class GraknTxPutPropertyTest method whenCallingPutRelationType_CreateATypeWithSuperTypeRelation.

@Property
public void whenCallingPutRelationType_CreateATypeWithSuperTypeRelation(@Open GraknTx tx, @Unused Label label) {
    RelationshipType relationshipType = tx.putRelationshipType(label);
    assertEquals(tx.admin().getMetaRelationType(), relationshipType.sup());
}
Also used : RelationshipType(ai.grakn.concept.RelationshipType) Property(com.pholser.junit.quickcheck.Property)

Example 99 with RelationshipType

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

the class GraknTxPutPropertyTest method whenCallingPutRelationTypeWithAnExistingRelationTypeLabel_ItReturnsThatType.

@Property
public void whenCallingPutRelationTypeWithAnExistingRelationTypeLabel_ItReturnsThatType(@Open GraknTx graph, @FromTx RelationshipType relationshipType) {
    RelationshipType newType = graph.putRelationshipType(relationshipType.getLabel());
    assertEquals(relationshipType, newType);
}
Also used : RelationshipType(ai.grakn.concept.RelationshipType) Property(com.pholser.junit.quickcheck.Property)

Example 100 with RelationshipType

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

the class ValidatorTest method whenCommittingWithRoleTypeHierarchyAndInstancesCannotPlayRolesExplicitly_Throw2.

@Test
public void whenCommittingWithRoleTypeHierarchyAndInstancesCannotPlayRolesExplicitly_Throw2() throws InvalidKBException {
    Role parent = tx.putRole("parent");
    Role child = tx.putRole("child");
    EntityType person = tx.putEntityType("person").plays(child);
    RelationshipType parenthood = tx.putRelationshipType("parenthood").relates(parent).relates(child);
    Entity x = person.addEntity();
    Entity y = person.addEntity();
    parenthood.addRelationship().addRolePlayer(parent, x).addRolePlayer(child, y);
    expectedException.expect(InvalidKBException.class);
    expectedException.expectMessage(ErrorMessage.VALIDATION_CASTING.getMessage(person.getLabel(), x.getId(), parent.getLabel()));
    tx.commit();
}
Also used : Role(ai.grakn.concept.Role) EntityType(ai.grakn.concept.EntityType) Entity(ai.grakn.concept.Entity) 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