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);
}
}
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());
});
}
}
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();
}
}
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");
}
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);
}
Aggregations