use of ai.grakn.concept.Entity in project grakn by graknlabs.
the class ConceptTest method whenCastingToInCorrectType_Throw.
@Test
public void whenCastingToInCorrectType_Throw() {
EntityType thingType = tx.putEntityType("thing type");
Entity thing = thingType.addEntity();
expectedException.expect(GraknTxOperationException.class);
expectedException.expectMessage(GraknTxOperationException.invalidCasting(thing, Type.class).getMessage());
// noinspection ResultOfMethodCallIgnored
thing.asType();
}
use of ai.grakn.concept.Entity in project grakn by graknlabs.
the class AddBenchmark method addRelation.
@Benchmark
public void addRelation() {
Entity entity1 = entityType.addEntity();
Entity entity2 = entityType.addEntity();
relationshipType.addRelationship().addRolePlayer(role1, entity1).addRolePlayer(role2, entity2);
}
use of ai.grakn.concept.Entity in project grakn by graknlabs.
the class EntityTypeTest method addResourceTypeAsKeyToOneEntityTypeAndAsResourceToAnotherEntityType.
@Test
public void addResourceTypeAsKeyToOneEntityTypeAndAsResourceToAnotherEntityType() {
AttributeType<String> attributeType1 = tx.putAttributeType("Shared Attribute 1", AttributeType.DataType.STRING);
AttributeType<String> attributeType2 = tx.putAttributeType("Shared Attribute 2", AttributeType.DataType.STRING);
EntityType entityType1 = tx.putEntityType("EntityType 1");
EntityType entityType2 = tx.putEntityType("EntityType 2");
assertThat(entityType1.keys().collect(toSet()), is(empty()));
assertThat(entityType1.attributes().collect(toSet()), is(empty()));
assertThat(entityType2.keys().collect(toSet()), is(empty()));
assertThat(entityType2.attributes().collect(toSet()), is(empty()));
// Link the resources
entityType1.attribute(attributeType1);
entityType1.key(attributeType2);
entityType2.key(attributeType1);
entityType2.key(attributeType2);
assertThat(entityType1.attributes().collect(toSet()), containsInAnyOrder(attributeType1, attributeType2));
assertThat(entityType2.attributes().collect(toSet()), containsInAnyOrder(attributeType1, attributeType2));
assertThat(entityType1.keys().collect(toSet()), containsInAnyOrder(attributeType2));
assertThat(entityType2.keys().collect(toSet()), containsInAnyOrder(attributeType1, attributeType2));
// Add resource which is a key for one entity and a resource for another
Entity entity1 = entityType1.addEntity();
Entity entity2 = entityType2.addEntity();
Attribute<String> attribute1 = attributeType1.putAttribute("Test 1");
Attribute<String> attribute2 = attributeType2.putAttribute("Test 2");
Attribute<String> attribute3 = attributeType2.putAttribute("Test 3");
// Attribute 1 is a key to one and a resource to another
entity1.attribute(attribute1);
entity2.attribute(attribute1);
entity1.attribute(attribute2);
entity2.attribute(attribute3);
tx.commit();
}
use of ai.grakn.concept.Entity in project grakn by graknlabs.
the class EntityTypeTest method whenAddingInstanceToType_EnsureIsaEdgeIsPlacedOnShard.
@Test
public void whenAddingInstanceToType_EnsureIsaEdgeIsPlacedOnShard() {
EntityTypeImpl entityType = (EntityTypeImpl) tx.putEntityType("EntityType");
Shard shard = entityType.currentShard();
Entity e1 = entityType.addEntity();
assertFalse("The isa edge was places on the type rather than the shard", entityType.neighbours(Direction.IN, Schema.EdgeLabel.ISA).iterator().hasNext());
assertEquals(e1, shard.links().findAny().get());
}
use of ai.grakn.concept.Entity in project grakn by graknlabs.
the class RelationshipTypeTest method whenCallingInstancesOnImplicitRelationType_RelationEdgesAreReturned.
@Test
public void whenCallingInstancesOnImplicitRelationType_RelationEdgesAreReturned() {
AttributeType<String> attributeType = tx.putAttributeType("My Special Attribute Type", AttributeType.DataType.STRING);
Attribute<String> attribute = attributeType.putAttribute("Ad thing");
EntityType entityType = tx.putEntityType("My Special Entity Type").attribute(attributeType);
Entity entity = entityType.addEntity();
RelationshipType implicitRelationshipType = tx.getRelationshipType(Schema.ImplicitType.HAS.getLabel(attributeType.getLabel()).getValue());
assertNotNull(implicitRelationshipType);
assertThat(implicitRelationshipType.instances().collect(toSet()), empty());
entity.attribute(attribute);
assertEquals(1, implicitRelationshipType.instances().count());
}
Aggregations