use of ai.grakn.concept.Entity in project grakn by graknlabs.
the class EntityTest method whenGettingEntityKeys_EnsureKeysAreReturned.
@Test
public void whenGettingEntityKeys_EnsureKeysAreReturned() {
AttributeType<String> attributeType = tx.putAttributeType("An Attribute", AttributeType.DataType.STRING);
AttributeType<String> keyType = tx.putAttributeType("A Key", AttributeType.DataType.STRING);
EntityType entityType = tx.putEntityType("A Thing").attribute(attributeType).key(keyType);
Attribute<String> a1 = attributeType.putAttribute("a1");
Attribute<String> a2 = attributeType.putAttribute("a2");
Attribute<String> k1 = keyType.putAttribute("k1");
Entity entity = entityType.addEntity().attribute(a1).attribute(a2).attribute(k1);
assertThat(entity.keys().collect(Collectors.toSet()), containsInAnyOrder(k1));
assertThat(entity.keys(attributeType, keyType).collect(Collectors.toSet()), containsInAnyOrder(k1));
assertThat(entity.keys(attributeType).collect(Collectors.toSet()), empty());
}
use of ai.grakn.concept.Entity in project grakn by graknlabs.
the class EntityTest method whenAddingMultipleResourcesToEntity_EnsureDifferentRelationsAreBuilt.
@Test
public void whenAddingMultipleResourcesToEntity_EnsureDifferentRelationsAreBuilt() throws InvalidKBException {
String resourceTypeId = "A Attribute Thing";
EntityType entityType = tx.putEntityType("A Thing");
AttributeType<String> attributeType = tx.putAttributeType(resourceTypeId, AttributeType.DataType.STRING);
entityType.attribute(attributeType);
Entity entity = entityType.addEntity();
Attribute attribute1 = attributeType.putAttribute("A resource thing");
Attribute attribute2 = attributeType.putAttribute("Another resource thing");
assertEquals(0, entity.relationships().count());
entity.attribute(attribute1);
assertEquals(1, entity.relationships().count());
entity.attribute(attribute2);
assertEquals(2, entity.relationships().count());
tx.commit();
}
use of ai.grakn.concept.Entity in project grakn by graknlabs.
the class EntityTest method whenRemovingAnAttributedFromAnEntity_EnsureTheAttributeIsNoLongerReturned.
@Test
public void whenRemovingAnAttributedFromAnEntity_EnsureTheAttributeIsNoLongerReturned() {
AttributeType<String> name = tx.putAttributeType("name", AttributeType.DataType.STRING);
Attribute<String> fim = name.putAttribute("Fim");
Attribute<String> tim = name.putAttribute("Tim");
Attribute<String> pim = name.putAttribute("Pim");
EntityType person = tx.putEntityType("person").attribute(name);
Entity aPerson = person.addEntity().attribute(fim).attribute(tim).attribute(pim);
assertThat(aPerson.attributes().collect(toSet()), containsInAnyOrder(fim, tim, pim));
aPerson.deleteAttribute(tim);
assertThat(aPerson.attributes().collect(toSet()), containsInAnyOrder(fim, pim));
}
use of ai.grakn.concept.Entity in project grakn by graknlabs.
the class EntityTest method whenAddingResourceToAnEntity_EnsureTheImplicitStructureIsCreated.
@Test
public void whenAddingResourceToAnEntity_EnsureTheImplicitStructureIsCreated() {
Label resourceLabel = Label.of("A Attribute Thing");
EntityType entityType = tx.putEntityType("A Thing");
AttributeType<String> attributeType = tx.putAttributeType(resourceLabel, AttributeType.DataType.STRING);
entityType.attribute(attributeType);
Entity entity = entityType.addEntity();
Attribute attribute = attributeType.putAttribute("A attribute thing");
entity.attribute(attribute);
Relationship relationship = entity.relationships().iterator().next();
checkImplicitStructure(attributeType, relationship, entity, Schema.ImplicitType.HAS, Schema.ImplicitType.HAS_OWNER, Schema.ImplicitType.HAS_VALUE);
}
use of ai.grakn.concept.Entity in project grakn by graknlabs.
the class EntityTest method whenCreatingInferredAttributeLink_EnsureMarkedAsInferred.
@Test
public void whenCreatingInferredAttributeLink_EnsureMarkedAsInferred() {
AttributeType<String> name = tx.putAttributeType("name", AttributeType.DataType.STRING);
Attribute<String> attribute1 = name.putAttribute("An attribute 1");
Attribute<String> attribute2 = name.putAttribute("An attribute 2");
EntityType et = tx.putEntityType("et").attribute(name);
Entity e = et.addEntity();
// Link Attributes
e.attribute(attribute1);
EntityImpl.from(e).attributeInferred(attribute2);
e.relationships().forEach(relationship -> {
relationship.rolePlayers().forEach(roleplayer -> {
if (roleplayer.equals(attribute1)) {
assertFalse(relationship.isInferred());
} else if (roleplayer.equals(attribute2)) {
assertTrue(relationship.isInferred());
}
});
});
}
Aggregations