use of ai.grakn.GraknTx in project grakn by graknlabs.
the class MigratorTestUtils method assertPetGraphCorrect.
/**
* Check that the pet graph has been loaded correctly
*/
public static void assertPetGraphCorrect(GraknSession session) {
try (GraknTx graph = session.open(GraknTxType.READ)) {
Collection<Entity> pets = graph.getEntityType("pet").instances().collect(Collectors.toSet());
assertEquals(9, pets.size());
Collection<Entity> cats = graph.getEntityType("cat").instances().collect(Collectors.toSet());
assertEquals(2, cats.size());
Collection<Entity> hamsters = graph.getEntityType("hamster").instances().collect(Collectors.toSet());
assertEquals(1, hamsters.size());
AttributeType<String> name = graph.getAttributeType("name");
AttributeType<String> death = graph.getAttributeType("death");
Entity puffball = name.getAttribute("Puffball").ownerInstances().iterator().next().asEntity();
assertEquals(0, puffball.attributes(death).count());
Entity bowser = name.getAttribute("Bowser").ownerInstances().iterator().next().asEntity();
assertEquals(1, bowser.attributes(death).count());
}
}
use of ai.grakn.GraknTx in project grakn by graknlabs.
the class MigratorTestUtils method assertPokemonGraphCorrect.
/**
* Check that the pokemon graph has been loaded correctly
*/
public static void assertPokemonGraphCorrect(GraknSession session) {
try (GraknTx graph = session.open(GraknTxType.READ)) {
Collection<Entity> pokemon = graph.getEntityType("pokemon").instances().collect(Collectors.toSet());
assertEquals(9, pokemon.size());
AttributeType<String> typeid = graph.getAttributeType("type-id");
AttributeType<String> pokedexno = graph.getAttributeType("pokedex-no");
Entity grass = typeid.getAttribute("12").ownerInstances().iterator().next().asEntity();
Entity poison = typeid.getAttribute("4").ownerInstances().iterator().next().asEntity();
Entity bulbasaur = pokedexno.getAttribute("1").ownerInstances().iterator().next().asEntity();
RelationshipType relation = graph.getRelationshipType("has-type");
assertNotNull(grass);
assertNotNull(poison);
assertNotNull(bulbasaur);
assertRelationBetweenInstancesExists(graph, bulbasaur, grass, relation.getLabel());
assertRelationBetweenInstancesExists(graph, bulbasaur, poison, relation.getLabel());
}
}
use of ai.grakn.GraknTx in project grakn by graknlabs.
the class AddWithCommitBenchmark method setup.
@Setup
public void setup() throws Throwable {
session = sessionContext.newSession();
try (GraknTx tx = session.open(GraknTxType.WRITE)) {
role1 = tx.putRole("benchmark_role1");
role2 = tx.putRole("benchmark_role2");
entityType = tx.putEntityType("benchmark_Entitytype").plays(role1).plays(role2);
relationshipType = tx.putRelationshipType("benchmark_relationshipType").relates(role1).relates(role2);
tx.commit();
}
}
use of ai.grakn.GraknTx in project grakn by graknlabs.
the class AddWithCommitBenchmark method addRelation.
@Benchmark
public void addRelation() {
try (GraknTx graph = session.open(GraknTxType.WRITE)) {
Entity entity1 = entityType.addEntity();
Entity entity2 = entityType.addEntity();
relationshipType.addRelationship().addRolePlayer(role1, entity1).addRolePlayer(role2, entity2);
graph.commit();
}
}
use of ai.grakn.GraknTx in project grakn by graknlabs.
the class AddWithCommitBenchmark method addEntity.
@Benchmark
public void addEntity() {
try (GraknTx graph = session.open(GraknTxType.WRITE)) {
entityType.addEntity();
graph.commit();
}
}
Aggregations