Search in sources :

Example 6 with EntityType

use of ai.grakn.concept.EntityType 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 EntityType

use of ai.grakn.concept.EntityType 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 EntityType

use of ai.grakn.concept.EntityType 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 EntityType

use of ai.grakn.concept.EntityType 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 EntityType

use of ai.grakn.concept.EntityType 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

EntityType (ai.grakn.concept.EntityType)168 Test (org.junit.Test)141 Role (ai.grakn.concept.Role)83 RelationshipType (ai.grakn.concept.RelationshipType)82 Entity (ai.grakn.concept.Entity)74 GraknTx (ai.grakn.GraknTx)45 Relationship (ai.grakn.concept.Relationship)21 Attribute (ai.grakn.concept.Attribute)19 AttributeType (ai.grakn.concept.AttributeType)17 ConceptId (ai.grakn.concept.ConceptId)17 Label (ai.grakn.concept.Label)17 Set (java.util.Set)16 HashSet (java.util.HashSet)15 Thing (ai.grakn.concept.Thing)14 GraknTxType (ai.grakn.GraknTxType)8 ArrayList (java.util.ArrayList)8 GraknSession (ai.grakn.GraknSession)7 Concept (ai.grakn.concept.Concept)7 HashMap (java.util.HashMap)7 Before (org.junit.Before)7