Search in sources :

Example 26 with GraknTx

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());
    }
}
Also used : GraknTx(ai.grakn.GraknTx) Entity(ai.grakn.concept.Entity)

Example 27 with GraknTx

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());
    }
}
Also used : GraknTx(ai.grakn.GraknTx) Entity(ai.grakn.concept.Entity) RelationshipType(ai.grakn.concept.RelationshipType)

Example 28 with GraknTx

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();
    }
}
Also used : GraknTx(ai.grakn.GraknTx) Setup(org.openjdk.jmh.annotations.Setup)

Example 29 with GraknTx

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();
    }
}
Also used : GraknTx(ai.grakn.GraknTx) Entity(ai.grakn.concept.Entity) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 30 with GraknTx

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();
    }
}
Also used : GraknTx(ai.grakn.GraknTx) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Aggregations

GraknTx (ai.grakn.GraknTx)243 Test (org.junit.Test)189 EntityType (ai.grakn.concept.EntityType)54 GetQuery (ai.grakn.graql.GetQuery)52 Entity (ai.grakn.concept.Entity)51 QueryBuilder (ai.grakn.graql.QueryBuilder)49 Role (ai.grakn.concept.Role)48 RelationshipType (ai.grakn.concept.RelationshipType)46 Answer (ai.grakn.graql.admin.Answer)44 Set (java.util.Set)44 EmbeddedGraknTx (ai.grakn.kb.internal.EmbeddedGraknTx)33 Label (ai.grakn.concept.Label)28 Attribute (ai.grakn.concept.Attribute)27 Concept (ai.grakn.concept.Concept)27 HashSet (java.util.HashSet)26 GraknSession (ai.grakn.GraknSession)22 AttributeType (ai.grakn.concept.AttributeType)22 ConceptId (ai.grakn.concept.ConceptId)22 List (java.util.List)19 GraknTxType (ai.grakn.GraknTxType)17