use of ai.grakn.concept.EntityType in project grakn by graknlabs.
the class ValidatorTest method whenManuallyCreatingCorrectBinaryRelation_Commit.
@Test
public void whenManuallyCreatingCorrectBinaryRelation_Commit() throws InvalidKBException {
Role characterBeingPlayed = tx.putRole("Character being played");
Role personPlayingCharacter = tx.putRole("Person Playing Char");
RelationshipType playsChar = tx.putRelationshipType("Plays Char").relates(characterBeingPlayed).relates(personPlayingCharacter);
EntityType person = tx.putEntityType("person").plays(characterBeingPlayed).plays(personPlayingCharacter);
EntityType character = tx.putEntityType("character").plays(characterBeingPlayed);
Entity matt = person.addEntity();
Entity walker = character.addEntity();
playsChar.addRelationship().addRolePlayer(personPlayingCharacter, matt).addRolePlayer(characterBeingPlayed, walker);
tx.commit();
}
use of ai.grakn.concept.EntityType 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.EntityType 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.EntityType 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.EntityType in project grakn by graknlabs.
the class GraknTxPutPropertyTest method whenCallingPutEntityType_CreateATypeWithSuperTypeEntity.
@Property
public void whenCallingPutEntityType_CreateATypeWithSuperTypeEntity(@Open GraknTx graph, @Unused Label label) {
EntityType entityType = graph.putEntityType(label);
assertEquals(graph.admin().getMetaEntityType(), entityType.sup());
}
Aggregations