use of ai.grakn.concept.Relationship in project grakn by graknlabs.
the class RelationshipTest method whenRemovingRolePlayerFromRelationship_EnsureRolePlayerIsRemoved.
@Test
public void whenRemovingRolePlayerFromRelationship_EnsureRolePlayerIsRemoved() {
Role role1 = tx.putRole("dark");
Role role2 = tx.putRole("souls");
RelationshipType relationshipType = tx.putRelationshipType("Dark Souls").relates(role1).relates(role2);
EntityType entityType = tx.putEntityType("Dead Guys").plays(role1).plays(role2);
Entity e1 = entityType.addEntity();
Entity e2 = entityType.addEntity();
Entity e3 = entityType.addEntity();
Entity e4 = entityType.addEntity();
Entity e5 = entityType.addEntity();
Entity e6 = entityType.addEntity();
Relationship relationship = relationshipType.addRelationship().addRolePlayer(role1, e1).addRolePlayer(role1, e2).addRolePlayer(role1, e3).addRolePlayer(role2, e4).addRolePlayer(role2, e5).addRolePlayer(role2, e6);
assertThat(relationship.rolePlayers().collect(Collectors.toSet()), containsInAnyOrder(e1, e2, e3, e4, e5, e6));
relationship.removeRolePlayer(role1, e2);
relationship.removeRolePlayer(role2, e1);
assertThat(relationship.rolePlayers().collect(Collectors.toSet()), containsInAnyOrder(e1, e3, e4, e5, e6));
relationship.removeRolePlayer(role2, e6);
assertThat(relationship.rolePlayers().collect(Collectors.toSet()), containsInAnyOrder(e1, e3, e4, e5));
}
use of ai.grakn.concept.Relationship in project grakn by graknlabs.
the class RelationshipTest method whenDeletingRelations_EnsureCastingsRemain.
@Test
public void whenDeletingRelations_EnsureCastingsRemain() {
Role entityRole = tx.putRole("Entity Role");
Role degreeRole = tx.putRole("Degree Role");
EntityType entityType = tx.putEntityType("Entity Type").plays(entityRole);
AttributeType<Long> degreeType = tx.putAttributeType("Attribute Type", AttributeType.DataType.LONG).plays(degreeRole);
RelationshipType hasDegree = tx.putRelationshipType("Has Degree").relates(entityRole).relates(degreeRole);
Entity entity = entityType.addEntity();
Attribute<Long> degree1 = degreeType.putAttribute(100L);
Attribute<Long> degree2 = degreeType.putAttribute(101L);
Relationship relationship1 = hasDegree.addRelationship().addRolePlayer(entityRole, entity).addRolePlayer(degreeRole, degree1);
hasDegree.addRelationship().addRolePlayer(entityRole, entity).addRolePlayer(degreeRole, degree2);
assertEquals(2, entity.relationships().count());
relationship1.delete();
assertEquals(1, entity.relationships().count());
}
use of ai.grakn.concept.Relationship in project grakn by graknlabs.
the class RelationshipTest method ensureRelationToStringContainsRolePlayerInformation.
@Test
public void ensureRelationToStringContainsRolePlayerInformation() {
Role role1 = tx.putRole("role type 1");
Role role2 = tx.putRole("role type 2");
RelationshipType relationshipType = tx.putRelationshipType("A relationship Type").relates(role1).relates(role2);
EntityType type = tx.putEntityType("concept type").plays(role1).plays(role2);
Thing thing1 = type.addEntity();
Thing thing2 = type.addEntity();
Relationship relationship = relationshipType.addRelationship().addRolePlayer(role1, thing1).addRolePlayer(role2, thing2);
String mainDescription = "ID [" + relationship.getId() + "] Type [" + relationship.type().getLabel() + "] Roles and Role Players:";
String rolerp1 = " Role [" + role1.getLabel() + "] played by [" + thing1.getId() + ",]";
String rolerp2 = " Role [" + role2.getLabel() + "] played by [" + thing2.getId() + ",]";
assertTrue("Relationship toString missing main description", relationship.toString().contains(mainDescription));
assertTrue("Relationship toString missing role and role player definition", relationship.toString().contains(rolerp1));
assertTrue("Relationship toString missing role and role player definition", relationship.toString().contains(rolerp2));
}
use of ai.grakn.concept.Relationship in project grakn by graknlabs.
the class RelationshipTest method whenAttributeLinkedToRelationshipIsInferred_EnsureItIsMarkedAsInferred.
@Test
public void whenAttributeLinkedToRelationshipIsInferred_EnsureItIsMarkedAsInferred() {
AttributeType attributeType = tx.putAttributeType("Another thing of sorts", AttributeType.DataType.STRING);
RelationshipType relationshipType = tx.putRelationshipType("A thing of sorts").attribute(attributeType);
Attribute attribute = attributeType.putAttribute("Things");
Relationship relationship = relationshipType.addRelationship();
RelationshipImpl.from(relationship).attributeInferred(attribute);
assertTrue(relationship.relationships().findAny().get().isInferred());
}
use of ai.grakn.concept.Relationship in project grakn by graknlabs.
the class RelationshipTest method whenAttemptingToLinkTheInstanceOfAResourceRelationToTheResourceWhichCreatedIt_ThrowIfTheRelationTypeDoesNotHavePermissionToPlayTheNecessaryRole.
@Test
public void whenAttemptingToLinkTheInstanceOfAResourceRelationToTheResourceWhichCreatedIt_ThrowIfTheRelationTypeDoesNotHavePermissionToPlayTheNecessaryRole() {
AttributeType<String> attributeType = tx.putAttributeType("what a pain", AttributeType.DataType.STRING);
Attribute<String> attribute = attributeType.putAttribute("a real pain");
EntityType entityType = tx.putEntityType("yay").attribute(attributeType);
Relationship implicitRelationship = Iterables.getOnlyElement(entityType.addEntity().attribute(attribute).relationships().collect(Collectors.toSet()));
expectedException.expect(GraknTxOperationException.class);
expectedException.expectMessage(GraknTxOperationException.hasNotAllowed(implicitRelationship, attribute).getMessage());
implicitRelationship.attribute(attribute);
}
Aggregations