Search in sources :

Example 56 with EntityType

use of ai.grakn.concept.EntityType in project grakn by graknlabs.

the class GraknTxTest method whenGettingSubTypesFromRootMeta_IncludeAllTypes.

@Test
public void whenGettingSubTypesFromRootMeta_IncludeAllTypes() {
    EntityType sampleEntityType = tx.putEntityType("Sample Entity Type");
    RelationshipType sampleRelationshipType = tx.putRelationshipType("Sample Relationship Type");
    assertThat(tx.getMetaConcept().subs().collect(toSet()), containsInAnyOrder(tx.getMetaConcept(), tx.getMetaRelationType(), tx.getMetaEntityType(), tx.getMetaAttributeType(), sampleEntityType, sampleRelationshipType));
}
Also used : EntityType(ai.grakn.concept.EntityType) RelationshipType(ai.grakn.concept.RelationshipType) Test(org.junit.Test)

Example 57 with EntityType

use of ai.grakn.concept.EntityType in project grakn by graknlabs.

the class GraknTxTest method whenAttemptingToMutateReadOnlyGraph_Throw.

@Test
public void whenAttemptingToMutateReadOnlyGraph_Throw() {
    Keyspace keyspace = Keyspace.of("myreadonlygraph");
    String entityType = "My Entity Type";
    String roleType1 = "My Role Type 1";
    String roleType2 = "My Role Type 2";
    String relationType1 = "My Relationship Type 1";
    String relationType2 = "My Relationship Type 2";
    String resourceType = "My Attribute Type";
    // Fail Some Mutations
    tx = EmbeddedGraknSession.create(keyspace, Grakn.IN_MEMORY).open(GraknTxType.READ);
    failMutation(tx, () -> tx.putEntityType(entityType));
    failMutation(tx, () -> tx.putRole(roleType1));
    failMutation(tx, () -> tx.putRelationshipType(relationType1));
    // Pass some mutations
    tx.close();
    tx = EmbeddedGraknSession.create(keyspace, Grakn.IN_MEMORY).open(GraknTxType.WRITE);
    EntityType entityT = tx.putEntityType(entityType);
    entityT.addEntity();
    Role roleT1 = tx.putRole(roleType1);
    Role roleT2 = tx.putRole(roleType2);
    RelationshipType relationT1 = tx.putRelationshipType(relationType1).relates(roleT1);
    RelationshipType relationT2 = tx.putRelationshipType(relationType2).relates(roleT2);
    AttributeType<String> resourceT = tx.putAttributeType(resourceType, AttributeType.DataType.STRING);
    tx.commit();
    // Fail some mutations again
    tx = EmbeddedGraknSession.create(keyspace, Grakn.IN_MEMORY).open(GraknTxType.READ);
    failMutation(tx, entityT::addEntity);
    failMutation(tx, () -> resourceT.putAttribute("A resource"));
    failMutation(tx, () -> tx.putEntityType(entityType));
    failMutation(tx, () -> entityT.plays(roleT1));
    failMutation(tx, () -> relationT1.relates(roleT2));
    failMutation(tx, () -> relationT2.relates(roleT1));
}
Also used : EntityType(ai.grakn.concept.EntityType) Role(ai.grakn.concept.Role) Keyspace(ai.grakn.Keyspace) RelationshipType(ai.grakn.concept.RelationshipType) Test(org.junit.Test)

Example 58 with EntityType

use of ai.grakn.concept.EntityType in project grakn by graknlabs.

the class GraknTxTest method whenShardingConcepts_EnsureCountsAreUpdated.

@Test
public void whenShardingConcepts_EnsureCountsAreUpdated() {
    EntityType entity = tx.putEntityType("my amazing entity type");
    assertEquals(1L, tx.getShardCount(entity));
    tx.shard(entity.getId());
    assertEquals(2L, tx.getShardCount(entity));
}
Also used : EntityType(ai.grakn.concept.EntityType) Test(org.junit.Test)

Example 59 with EntityType

use of ai.grakn.concept.EntityType in project grakn by graknlabs.

the class GrpcServerIT method whenDefiningASchema_TheSchemaIsDefined.

@Test
public void whenDefiningASchema_TheSchemaIsDefined() {
    try (GraknTx tx = remoteSession.open(GraknTxType.WRITE)) {
        EntityType animal = tx.putEntityType("animal");
        EntityType dog = tx.putEntityType("dog").sup(animal);
        EntityType cat = tx.putEntityType("cat");
        animal.sub(cat);
        cat.setLabel(Label.of("feline"));
        dog.setAbstract(true).setAbstract(false);
        cat.setAbstract(true);
        RelationshipType chases = tx.putRelationshipType("chases");
        Role chased = tx.putRole("chased");
        Role chaser = tx.putRole("chaser");
        chases.relates(chased).relates(chaser);
        Role pointlessRole = tx.putRole("pointless-role");
        tx.putRelationshipType("pointless").relates(pointlessRole);
        chases.relates(pointlessRole).deleteRelates(pointlessRole);
        dog.plays(chaser);
        cat.plays(chased);
        AttributeType<String> name = tx.putAttributeType("name", DataType.STRING);
        AttributeType<String> id = tx.putAttributeType("id", DataType.STRING).setRegex("(good|bad)-dog");
        AttributeType<Long> age = tx.putAttributeType("age", DataType.LONG);
        animal.attribute(name);
        animal.key(id);
        dog.attribute(age).deleteAttribute(age);
        cat.key(age).deleteKey(age);
        cat.plays(chaser).deletePlays(chaser);
        Entity dunstan = dog.addEntity();
        Attribute<String> dunstanId = id.putAttribute("good-dog");
        assertNotNull(dunstan.attributeRelationship(dunstanId));
        Attribute<String> dunstanName = name.putAttribute("Dunstan");
        dunstan.attribute(dunstanName).deleteAttribute(dunstanName);
        chases.addRelationship().addRolePlayer(chaser, dunstan);
        tx.commit();
    }
    try (GraknTx tx = localSession.open(GraknTxType.READ)) {
        EntityType animal = tx.getEntityType("animal");
        EntityType dog = tx.getEntityType("dog");
        EntityType cat = tx.getEntityType("feline");
        RelationshipType chases = tx.getRelationshipType("chases");
        Role chased = tx.getRole("chased");
        Role chaser = tx.getRole("chaser");
        AttributeType<String> name = tx.getAttributeType("name");
        AttributeType<String> id = tx.getAttributeType("id");
        Entity dunstan = Iterators.getOnlyElement(dog.instances().iterator());
        Relationship aChase = Iterators.getOnlyElement(chases.instances().iterator());
        assertEquals(animal, dog.sup());
        assertEquals(animal, cat.sup());
        assertEquals(ImmutableSet.of(chased, chaser), chases.relates().collect(toSet()));
        assertEquals(ImmutableSet.of(chaser), dog.plays().filter(role -> !role.isImplicit()).collect(toSet()));
        assertEquals(ImmutableSet.of(chased), cat.plays().filter(role -> !role.isImplicit()).collect(toSet()));
        assertEquals(ImmutableSet.of(name, id), animal.attributes().collect(toSet()));
        assertEquals(ImmutableSet.of(id), animal.keys().collect(toSet()));
        assertEquals(ImmutableSet.of(name, id), dog.attributes().collect(toSet()));
        assertEquals(ImmutableSet.of(id), dog.keys().collect(toSet()));
        assertEquals(ImmutableSet.of(name, id), cat.attributes().collect(toSet()));
        assertEquals(ImmutableSet.of(id), cat.keys().collect(toSet()));
        assertEquals("good-dog", Iterables.getOnlyElement(dunstan.keys(id).collect(toSet())).getValue());
        ImmutableMap<Role, ImmutableSet<?>> expectedRolePlayers = ImmutableMap.of(chaser, ImmutableSet.of(dunstan), chased, ImmutableSet.of());
        assertEquals(expectedRolePlayers, aChase.allRolePlayers());
        assertEquals("(good|bad)-dog", id.getRegex());
        assertFalse(dog.isAbstract());
        assertTrue(cat.isAbstract());
    }
}
Also used : Entity(ai.grakn.concept.Entity) RelationshipType(ai.grakn.concept.RelationshipType) EntityType(ai.grakn.concept.EntityType) Role(ai.grakn.concept.Role) GraknTx(ai.grakn.GraknTx) ImmutableSet(com.google.common.collect.ImmutableSet) Relationship(ai.grakn.concept.Relationship) Test(org.junit.Test)

Example 60 with EntityType

use of ai.grakn.concept.EntityType in project grakn by graknlabs.

the class BatchExecutorClientIT method loader.

private BatchExecutorClient loader(int maxDelay) {
    // load schema
    try (EmbeddedGraknTx<?> graph = session.open(GraknTxType.WRITE)) {
        Role role = graph.putRole("some-role");
        graph.putRelationshipType("some-relationship").relates(role);
        EntityType nameTag = graph.putEntityType("name_tag");
        AttributeType<String> nameTagString = graph.putAttributeType("name_tag_string", AttributeType.DataType.STRING);
        AttributeType<String> nameTagId = graph.putAttributeType("name_tag_id", AttributeType.DataType.STRING);
        nameTag.attribute(nameTagString);
        nameTag.attribute(nameTagId);
        graph.commitSubmitNoLogs();
        GraknClient graknClient = GraknClient.of(engine.uri());
        return spy(BatchExecutorClient.newBuilder().taskClient(graknClient).maxDelay(maxDelay).requestLogEnabled(true).build());
    }
}
Also used : Role(ai.grakn.concept.Role) EntityType(ai.grakn.concept.EntityType) GraknClient(ai.grakn.client.GraknClient)

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