use of ai.grakn.concept.Entity in project grakn by graknlabs.
the class AttributeTest method whenLinkingResourcesToThings_EnsureTheRelationIsAnEdge.
@Test
public void whenLinkingResourcesToThings_EnsureTheRelationIsAnEdge() {
AttributeType<String> attributeType = tx.putAttributeType("My attribute type", AttributeType.DataType.STRING);
Attribute<String> attribute = attributeType.putAttribute("A String");
EntityType entityType = tx.putEntityType("My entity type").attribute(attributeType);
Entity entity = entityType.addEntity();
entity.attribute(attribute);
RelationshipStructure relationshipStructure = RelationshipImpl.from(Iterables.getOnlyElement(entity.relationships().collect(toSet()))).structure();
assertThat(relationshipStructure, instanceOf(RelationshipEdge.class));
assertTrue("Edge Relationship id not starting with [" + Schema.PREFIX_EDGE + "]", relationshipStructure.getId().getValue().startsWith(Schema.PREFIX_EDGE));
assertEquals(entity, attribute.owner());
assertThat(entity.attributes().collect(toSet()), containsInAnyOrder(attribute));
}
use of ai.grakn.concept.Entity in project grakn by graknlabs.
the class AttributeTest method whenInsertingAThingWithTwoKeys_Throw.
@Test
public void whenInsertingAThingWithTwoKeys_Throw() {
AttributeType<String> attributeType = tx.putAttributeType("Key Thingy", AttributeType.DataType.STRING);
EntityType entityType = tx.putEntityType("Entity Type Thingy").key(attributeType);
Entity entity = entityType.addEntity();
Attribute<String> key1 = attributeType.putAttribute("key 1");
Attribute<String> key2 = attributeType.putAttribute("key 2");
entity.attribute(key1);
entity.attribute(key2);
expectedException.expect(InvalidKBException.class);
tx.commit();
}
use of ai.grakn.concept.Entity in project grakn by graknlabs.
the class AttributeTest method whenAddingRolePlayerToRelationEdge_RelationAutomaticallyReifies.
@Test
public void whenAddingRolePlayerToRelationEdge_RelationAutomaticallyReifies() {
// Create boring attribute which creates a relation edge
AttributeType<String> attributeType = tx.putAttributeType("My attribute type", AttributeType.DataType.STRING);
Attribute<String> attribute = attributeType.putAttribute("A String");
EntityType entityType = tx.putEntityType("My entity type").attribute(attributeType);
Entity entity = entityType.addEntity();
entity.attribute(attribute);
RelationshipImpl relation = RelationshipImpl.from(entity.relationships().iterator().next());
// Check it's a relation edge.
RelationshipStructure relationshipStructureBefore = relation.structure();
assertThat(relationshipStructureBefore, instanceOf(RelationshipEdge.class));
// Get the roles and role players via the relation edge:
Map<Role, Set<Thing>> allRolePlayerBefore = relationshipStructureBefore.allRolePlayers();
// Expand Schema to allow new role
Role newRole = tx.putRole("My New Role");
entityType.plays(newRole);
relation.type().relates(newRole);
Entity newEntity = entityType.addEntity();
// Now actually add the new role player
relation.addRolePlayer(newRole, newEntity);
// Check it's a relation reified now.
RelationshipStructure relationshipStructureAfter = relation.structure();
assertThat(relationshipStructureAfter, instanceOf(RelationshipReified.class));
// Check IDs are equal
assertEquals(relationshipStructureBefore.getId(), relation.getId());
assertEquals(relationshipStructureBefore.getId(), relationshipStructureAfter.getId());
// Check Role Players have been transferred
allRolePlayerBefore.forEach((role, player) -> assertEquals(player, relationshipStructureAfter.rolePlayers(role).collect(toSet())));
// Check Type Has Been Transferred
assertEquals(relationshipStructureBefore.type(), relationshipStructureAfter.type());
// Check new role player has been added as well
assertEquals(newEntity, Iterables.getOnlyElement(relationshipStructureAfter.rolePlayers(newRole).collect(toSet())));
}
use of ai.grakn.concept.Entity in project grakn by graknlabs.
the class EntityTypePropertyTest method whenAddingAnEntity_TheEntityHasNoResources.
@Property
public void whenAddingAnEntity_TheEntityHasNoResources(@NonMeta @NonAbstract EntityType type) {
Entity entity = type.addEntity();
assertThat(entity.attributes().collect(toSet()), empty());
}
use of ai.grakn.concept.Entity in project grakn by graknlabs.
the class EntityTypePropertyTest method whenAddingAnEntity_TheEntityIsInNoRelations.
@Property
public void whenAddingAnEntity_TheEntityIsInNoRelations(@NonMeta @NonAbstract EntityType type) {
Entity entity = type.addEntity();
assertThat(entity.relationships().collect(toSet()), empty());
}
Aggregations