Search in sources :

Example 66 with EntityType

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

the class JsonMigratorTest method whenMigratorExecutedOverMissingData_ErrorIsNotThrownAndMissingObjectsAreSkipped.

@Test
public void whenMigratorExecutedOverMissingData_ErrorIsNotThrownAndMissingObjectsAreSkipped() {
    load(factory, getFile("json", "string-or-object/schema.gql"));
    String template = "insert $thing isa the-thing has a-string <the-thing.a-string>;";
    declareAndLoad(template, "string-or-object/data");
    try (GraknTx graph = factory.open(GraknTxType.READ)) {
        EntityType theThing = graph.getEntityType("the-thing");
        assertEquals(1, theThing.instances().count());
    }
}
Also used : EntityType(ai.grakn.concept.EntityType) GraknTx(ai.grakn.GraknTx) Test(org.junit.Test)

Example 67 with EntityType

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

the class GrpcServerIT method whenGettingAnEntityType_TheInformationOnTheEntityTypeIsCorrect.

@Test
public void whenGettingAnEntityType_TheInformationOnTheEntityTypeIsCorrect() {
    try (GraknTx remoteTx = remoteSession.open(GraknTxType.READ);
        GraknTx localTx = localSession.open(GraknTxType.READ)) {
        GetQuery query = remoteTx.graql().match(var("x").label("person")).get();
        EntityType remoteConcept = query.stream().findAny().get().get("x").asEntityType();
        EntityType localConcept = localTx.getConcept(remoteConcept.getId()).asEntityType();
        // There actually aren't any new methods on EntityType, but we should still check we can get them
        assertEquals(localConcept.getId(), remoteConcept.getId());
    }
}
Also used : EntityType(ai.grakn.concept.EntityType) GraknTx(ai.grakn.GraknTx) GetQuery(ai.grakn.graql.GetQuery) Test(org.junit.Test)

Example 68 with EntityType

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

the class DiagonalKB method buildExtensionalDB.

private void buildExtensionalDB(GraknTx tx, int n, int m) {
    Role relFrom = tx.getRole("rel-from");
    Role relTo = tx.getRole("rel-to");
    EntityType entity1 = tx.getEntityType("entity1");
    RelationshipType horizontal = tx.getRelationshipType("horizontal");
    RelationshipType vertical = tx.getRelationshipType("vertical");
    ConceptId[][] instanceIds = new ConceptId[n][m];
    long inserts = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            instanceIds[i][j] = putEntityWithResource(tx, "a" + i + "," + j, entity1, key).getId();
            inserts++;
            if (inserts % 100 == 0)
                System.out.println("inst inserts: " + inserts);
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (i < n - 1) {
                vertical.addRelationship().addRolePlayer(relFrom, tx.getConcept(instanceIds[i][j])).addRolePlayer(relTo, tx.getConcept(instanceIds[i + 1][j]));
                inserts++;
            }
            if (j < m - 1) {
                horizontal.addRelationship().addRolePlayer(relFrom, tx.getConcept(instanceIds[i][j])).addRolePlayer(relTo, tx.getConcept(instanceIds[i][j + 1]));
                inserts++;
            }
            if (inserts % 100 == 0)
                System.out.println("rel inserts: " + inserts);
        }
    }
    System.out.println("Extensional DB loaded.");
}
Also used : Role(ai.grakn.concept.Role) EntityType(ai.grakn.concept.EntityType) RelationshipType(ai.grakn.concept.RelationshipType) ConceptId(ai.grakn.concept.ConceptId)

Example 69 with EntityType

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

the class NguyenKB method buildExtensionalDB.

private void buildExtensionalDB(GraknTx graph, int n) {
    Role Rfrom = graph.getRole("R-rA");
    Role Rto = graph.getRole("R-rB");
    Role qfrom = graph.getRole("Q-rA");
    Role qto = graph.getRole("Q-rB");
    Role Pfrom = graph.getRole("P-rA");
    Role Pto = graph.getRole("P-rB");
    EntityType entity = graph.getEntityType("entity2");
    EntityType aEntity = graph.getEntityType("a-entity");
    EntityType bEntity = graph.getEntityType("b-entity");
    RelationshipType r = graph.getRelationshipType("R");
    RelationshipType p = graph.getRelationshipType("P");
    RelationshipType q = graph.getRelationshipType("Q");
    ConceptId cId = putEntityWithResource(graph, "c", entity, key).getId();
    ConceptId dId = putEntityWithResource(graph, "d", entity, key).getId();
    ConceptId eId = putEntityWithResource(graph, "e", entity, key).getId();
    ConceptId[] aInstancesIds = new ConceptId[n + 2];
    ConceptId[] bInstancesIds = new ConceptId[n + 2];
    aInstancesIds[n + 1] = putEntityWithResource(graph, "a" + (n + 1), aEntity, key).getId();
    for (int i = 0; i <= n; i++) {
        aInstancesIds[i] = putEntityWithResource(graph, "a" + i, aEntity, key).getId();
        bInstancesIds[i] = putEntityWithResource(graph, "b" + i, bEntity, key).getId();
    }
    p.addRelationship().addRolePlayer(Pfrom, graph.getConcept(cId)).addRolePlayer(Pto, graph.getConcept(dId));
    r.addRelationship().addRolePlayer(Rfrom, graph.getConcept(dId)).addRolePlayer(Rto, graph.getConcept(eId));
    q.addRelationship().addRolePlayer(qfrom, graph.getConcept(eId)).addRolePlayer(qto, graph.getConcept(aInstancesIds[0]));
    for (int i = 0; i <= n; i++) {
        p.addRelationship().addRolePlayer(Pfrom, graph.getConcept(bInstancesIds[i])).addRolePlayer(Pto, graph.getConcept(cId));
        p.addRelationship().addRolePlayer(Pfrom, graph.getConcept(cId)).addRolePlayer(Pto, graph.getConcept(bInstancesIds[i]));
        q.addRelationship().addRolePlayer(qfrom, graph.getConcept(aInstancesIds[i])).addRolePlayer(qto, graph.getConcept(bInstancesIds[i]));
        q.addRelationship().addRolePlayer(qfrom, graph.getConcept(bInstancesIds[i])).addRolePlayer(qto, graph.getConcept(aInstancesIds[i + 1]));
    }
}
Also used : Role(ai.grakn.concept.Role) EntityType(ai.grakn.concept.EntityType) RelationshipType(ai.grakn.concept.RelationshipType) ConceptId(ai.grakn.concept.ConceptId)

Example 70 with EntityType

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

the class EntityTypeTest method whenRemovingAttributesFromAType_EnsureTheTypeNoLongerHasThoseAttributes.

@Test
public void whenRemovingAttributesFromAType_EnsureTheTypeNoLongerHasThoseAttributes() {
    AttributeType<String> name = tx.putAttributeType("name", AttributeType.DataType.STRING);
    AttributeType<Integer> age = tx.putAttributeType("age", AttributeType.DataType.INTEGER);
    EntityType person = tx.putEntityType("person").attribute(name).attribute(age);
    assertThat(person.attributes().collect(toSet()), containsInAnyOrder(name, age));
    person.deleteAttribute(name);
    assertThat(person.attributes().collect(toSet()), containsInAnyOrder(age));
}
Also used : EntityType(ai.grakn.concept.EntityType) 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