Search in sources :

Example 61 with EntityType

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

the class JsonMigratorTest method whenMigratorExecutedOverJsonDirectory_AllDataIsPersistedInGraph.

@Test
public void whenMigratorExecutedOverJsonDirectory_AllDataIsPersistedInGraph() {
    load(factory, getFile("json", "string-or-object/schema.gql"));
    String template = "\n" + "insert $thing isa the-thing\n" + "        has a-string if (<the-thing.a-string> != null) do {<the-thing.a-string>}\n" + "        else {<the-thing>} ;";
    declareAndLoad(template, "string-or-object/data");
    try (GraknTx graph = factory.open(GraknTxType.READ)) {
        EntityType theThing = graph.getEntityType("the-thing");
        assertEquals(2, theThing.instances().count());
        Stream<Entity> things = theThing.instances();
        boolean thingsCorrect = things.allMatch(thing -> {
            Object string = getResource(graph, thing, Label.of("a-string")).getValue();
            return string.equals("hello") || string.equals("goodbye");
        });
        assertTrue(thingsCorrect);
    }
}
Also used : EntityType(ai.grakn.concept.EntityType) GraknTx(ai.grakn.GraknTx) Entity(ai.grakn.concept.Entity) Test(org.junit.Test)

Example 62 with EntityType

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

the class XMLMigratorTest method assertThingHasName.

private static void assertThingHasName(String name) {
    try (GraknTx graph = session.open(GraknTxType.READ)) {
        EntityType thingType = graph.getEntityType("thingy");
        AttributeType nameType = graph.getAttributeType("name");
        assertEquals(1, thingType.instances().count());
        thingType.instances().forEach(thing -> {
            assertEquals(1, thing.attributes(nameType).count());
            assertEquals(name, thing.attributes(nameType).iterator().next().getValue());
        });
    }
}
Also used : EntityType(ai.grakn.concept.EntityType) GraknTx(ai.grakn.GraknTx) AttributeType(ai.grakn.concept.AttributeType)

Example 63 with EntityType

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

the class XMLMigratorTest method clearGraph.

@After
public void clearGraph() {
    try (GraknTx graph = session.open(GraknTxType.WRITE)) {
        AttributeType<String> nameType = graph.getAttributeType("name");
        nameType.instances().forEach(Concept::delete);
        EntityType thingType = graph.getEntityType("thingy");
        thingType.instances().forEach(Concept::delete);
        graph.commit();
    }
}
Also used : Concept(ai.grakn.concept.Concept) EntityType(ai.grakn.concept.EntityType) GraknTx(ai.grakn.GraknTx) After(org.junit.After)

Example 64 with EntityType

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

the class PathTreeKB method buildTree.

void buildTree(GraknTx tx, Role fromRole, Role toRole, int n, int children) {
    long startTime = System.currentTimeMillis();
    EntityType vertex = tx.getEntityType("vertex");
    EntityType startVertex = tx.getEntityType("start-vertex");
    RelationshipType arc = tx.getRelationshipType("arc");
    putEntityWithResource(tx, "a0", startVertex, getKey());
    int outputThreshold = 500;
    for (int i = 1; i <= n; i++) {
        int m = IntMath.pow(children, i);
        for (int j = 0; j < m; j++) {
            putEntityWithResource(tx, "a" + i + "," + j, vertex, getKey());
            if (j != 0 && j % outputThreshold == 0) {
                System.out.println(j + " entities out of " + m + " inserted");
            }
        }
    }
    for (int j = 0; j < children; j++) {
        arc.addRelationship().addRolePlayer(fromRole, getInstance(tx, "a0")).addRolePlayer(toRole, getInstance(tx, "a1," + j));
    }
    for (int i = 1; i < n; i++) {
        int m = IntMath.pow(children, i);
        for (int j = 0; j < m; j++) {
            for (int c = 0; c < children; c++) {
                arc.addRelationship().addRolePlayer(fromRole, getInstance(tx, "a" + i + "," + j)).addRolePlayer(toRole, getInstance(tx, "a" + (i + 1) + "," + (j * children + c)));
            }
            if (j != 0 && j % outputThreshold == 0) {
                System.out.println("level " + i + "/" + (n - 1) + ": " + j + " entities out of " + m + " connected");
            }
        }
    }
    long loadTime = System.currentTimeMillis() - startTime;
    System.out.println("PathKB loading time: " + loadTime + " ms");
}
Also used : EntityType(ai.grakn.concept.EntityType) RelationshipType(ai.grakn.concept.RelationshipType)

Example 65 with EntityType

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

the class SchemaConceptTest method whenChangingTheLabelOfSchemaConceptAndThatLabelIsTakenByAnotherConcept_Throw.

@Test
public void whenChangingTheLabelOfSchemaConceptAndThatLabelIsTakenByAnotherConcept_Throw() {
    Label label = Label.of("mylabel");
    EntityType e1 = tx.putEntityType("Entity1");
    tx.putEntityType(label);
    expectedException.expect(GraknTxOperationException.class);
    expectedException.expectMessage(ErrorMessage.LABEL_TAKEN.getMessage(label));
    e1.setLabel(label);
}
Also used : EntityType(ai.grakn.concept.EntityType) Label(ai.grakn.concept.Label) 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