Search in sources :

Example 6 with Entity

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());
}
Also used : EntityType(ai.grakn.concept.EntityType) Entity(ai.grakn.concept.Entity) Test(org.junit.Test)

Example 7 with Entity

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();
}
Also used : EntityType(ai.grakn.concept.EntityType) Entity(ai.grakn.concept.Entity) Attribute(ai.grakn.concept.Attribute) Test(org.junit.Test)

Example 8 with Entity

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));
}
Also used : EntityType(ai.grakn.concept.EntityType) Entity(ai.grakn.concept.Entity) Test(org.junit.Test)

Example 9 with Entity

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);
}
Also used : EntityType(ai.grakn.concept.EntityType) Entity(ai.grakn.concept.Entity) Attribute(ai.grakn.concept.Attribute) Relationship(ai.grakn.concept.Relationship) Label(ai.grakn.concept.Label) Test(org.junit.Test)

Example 10 with Entity

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());
            }
        });
    });
}
Also used : EntityType(ai.grakn.concept.EntityType) Entity(ai.grakn.concept.Entity) Test(org.junit.Test)

Aggregations

Entity (ai.grakn.concept.Entity)99 Test (org.junit.Test)81 EntityType (ai.grakn.concept.EntityType)74 Role (ai.grakn.concept.Role)53 RelationshipType (ai.grakn.concept.RelationshipType)50 GraknTx (ai.grakn.GraknTx)44 Attribute (ai.grakn.concept.Attribute)18 Set (java.util.Set)16 Relationship (ai.grakn.concept.Relationship)14 Label (ai.grakn.concept.Label)11 ConceptId (ai.grakn.concept.ConceptId)10 HashSet (java.util.HashSet)10 ArrayList (java.util.ArrayList)8 AttributeType (ai.grakn.concept.AttributeType)7 List (java.util.List)7 GraknSession (ai.grakn.GraknSession)6 Before (org.junit.Before)6 GraknTxType (ai.grakn.GraknTxType)5 Concept (ai.grakn.concept.Concept)5 GraqlQueryException (ai.grakn.exception.GraqlQueryException)5