Search in sources :

Example 51 with GraknTx

use of ai.grakn.GraknTx in project grakn by graknlabs.

the class CorenessTest method testOnEmptyGraph_ReturnsEmptyMap.

@Test
public void testOnEmptyGraph_ReturnsEmptyMap() {
    try (GraknTx graph = session.open(GraknTxType.READ)) {
        Map<Long, Set<String>> result = graph.graql().compute().centrality().usingKCore().execute();
        assertTrue(result.isEmpty());
    }
}
Also used : GraknTx(ai.grakn.GraknTx) Set(java.util.Set) Test(org.junit.Test)

Example 52 with GraknTx

use of ai.grakn.GraknTx in project grakn by graknlabs.

the class CorenessTest method testOnGraphWithoutRelationships_ReturnsEmptyMap.

@Test
public void testOnGraphWithoutRelationships_ReturnsEmptyMap() {
    try (GraknTx graph = session.open(GraknTxType.WRITE)) {
        graph.putEntityType(thing).addEntity();
        graph.putEntityType(anotherThing).addEntity();
        Map<Long, Set<String>> result = graph.graql().compute().centrality().usingKCore().execute();
        assertTrue(result.isEmpty());
    }
}
Also used : GraknTx(ai.grakn.GraknTx) Set(java.util.Set) Test(org.junit.Test)

Example 53 with GraknTx

use of ai.grakn.GraknTx in project grakn by graknlabs.

the class CorenessTest method testOnGraphWithFourEntitiesAndSixRelationships.

@Test
public void testOnGraphWithFourEntitiesAndSixRelationships() {
    addSchemaAndEntities();
    try (GraknTx graph = session.open(GraknTxType.READ)) {
        Map<Long, Set<String>> result = graph.graql().compute().centrality().usingKCore().execute();
        assertEquals(1, result.size());
        assertEquals(4, result.get(3L).size());
        result = graph.graql().compute().centrality().usingKCore().of(thing).execute();
        assertEquals(1, result.size());
        assertEquals(2, result.get(3L).size());
        result = graph.graql().compute().centrality().usingKCore().in(thing, anotherThing, related).execute();
        assertEquals(1, result.size());
        assertEquals(4, result.get(2L).size());
    }
}
Also used : GraknTx(ai.grakn.GraknTx) Set(java.util.Set) Test(org.junit.Test)

Example 54 with GraknTx

use of ai.grakn.GraknTx in project grakn by graknlabs.

the class CorenessTest method testDisconnectedCores.

@Test
public void testDisconnectedCores() {
    try (GraknTx graph = session.open(GraknTxType.WRITE)) {
        EntityType entityType1 = graph.putEntityType(thing);
        EntityType entityType2 = graph.putEntityType(anotherThing);
        Role role1 = graph.putRole("role1");
        Role role2 = graph.putRole("role2");
        RelationshipType relationshipType1 = graph.putRelationshipType(related).relates(role1).relates(role2);
        Role role3 = graph.putRole("role3");
        Role role4 = graph.putRole("role4");
        RelationshipType relationshipType2 = graph.putRelationshipType(veryRelated).relates(role3).relates(role4);
        entityType1.plays(role1).plays(role2).plays(role3).plays(role4);
        entityType2.plays(role1).plays(role2).plays(role3).plays(role4);
        Entity entity0 = entityType1.addEntity();
        Entity entity1 = entityType1.addEntity();
        Entity entity2 = entityType1.addEntity();
        Entity entity3 = entityType1.addEntity();
        Entity entity4 = entityType1.addEntity();
        Entity entity5 = entityType1.addEntity();
        Entity entity6 = entityType1.addEntity();
        Entity entity7 = entityType1.addEntity();
        Entity entity8 = entityType1.addEntity();
        relationshipType1.addRelationship().addRolePlayer(role1, entity1).addRolePlayer(role2, entity2);
        relationshipType1.addRelationship().addRolePlayer(role1, entity2).addRolePlayer(role2, entity3);
        relationshipType1.addRelationship().addRolePlayer(role1, entity3).addRolePlayer(role2, entity4);
        relationshipType1.addRelationship().addRolePlayer(role1, entity1).addRolePlayer(role2, entity3);
        relationshipType1.addRelationship().addRolePlayer(role1, entity1).addRolePlayer(role2, entity4);
        relationshipType1.addRelationship().addRolePlayer(role1, entity2).addRolePlayer(role2, entity4);
        relationshipType1.addRelationship().addRolePlayer(role1, entity5).addRolePlayer(role2, entity6);
        relationshipType2.addRelationship().addRolePlayer(role3, entity5).addRolePlayer(role4, entity7);
        relationshipType2.addRelationship().addRolePlayer(role3, entity5).addRolePlayer(role4, entity8);
        relationshipType2.addRelationship().addRolePlayer(role3, entity6).addRolePlayer(role4, entity7);
        relationshipType2.addRelationship().addRolePlayer(role3, entity6).addRolePlayer(role4, entity8);
        relationshipType2.addRelationship().addRolePlayer(role3, entity7).addRolePlayer(role4, entity8);
        relationshipType1.addRelationship().addRolePlayer(role1, entity0).addRolePlayer(role2, entity1);
        relationshipType1.addRelationship().addRolePlayer(role1, entity0).addRolePlayer(role2, entity8);
        graph.commit();
    }
    Map<Long, Set<String>> result;
    try (GraknTx graph = session.open(GraknTxType.READ)) {
        result = graph.graql().compute().centrality().usingKCore().execute();
        assertEquals(2, result.size());
        assertEquals(8, result.get(3L).size());
        assertEquals(1, result.get(2L).size());
        result = graph.graql().compute().centrality().usingKCore().minK(3L).execute();
        assertEquals(1, result.size());
        assertEquals(8, result.get(3L).size());
    }
}
Also used : EntityType(ai.grakn.concept.EntityType) Role(ai.grakn.concept.Role) GraknTx(ai.grakn.GraknTx) Entity(ai.grakn.concept.Entity) Set(java.util.Set) RelationshipType(ai.grakn.concept.RelationshipType) Test(org.junit.Test)

Example 55 with GraknTx

use of ai.grakn.GraknTx in project grakn by graknlabs.

the class CorenessTest method testImplicitTypeShouldBeIncluded.

@Test
public void testImplicitTypeShouldBeIncluded() {
    addSchemaAndEntities();
    try (GraknTx graph = session.open(GraknTxType.WRITE)) {
        String aResourceTypeLabel = "aResourceTypeLabel";
        AttributeType<String> attributeType = graph.putAttributeType(aResourceTypeLabel, AttributeType.DataType.STRING);
        graph.getEntityType(thing).attribute(attributeType);
        graph.getEntityType(anotherThing).attribute(attributeType);
        Attribute Attribute1 = attributeType.putAttribute("blah");
        graph.getConcept(entityId1).asEntity().attribute(Attribute1);
        graph.getConcept(entityId2).asEntity().attribute(Attribute1);
        graph.getConcept(entityId3).asEntity().attribute(Attribute1);
        graph.getConcept(entityId4).asEntity().attribute(Attribute1);
        Attribute Attribute2 = attributeType.putAttribute("bah");
        graph.getConcept(entityId1).asEntity().attribute(Attribute2);
        graph.getConcept(entityId2).asEntity().attribute(Attribute2);
        graph.getConcept(entityId3).asEntity().attribute(Attribute2);
        graph.commit();
    }
    Map<Long, Set<String>> result;
    try (GraknTx graph = session.open(GraknTxType.READ)) {
        result = graph.graql().compute().centrality().usingKCore().execute();
        System.out.println("result = " + result);
        assertEquals(2, result.size());
        assertEquals(5, result.get(4L).size());
        assertEquals(1, result.get(3L).size());
        result = graph.graql().compute().centrality().usingKCore().minK(4L).execute();
        assertEquals(1, result.size());
        assertEquals(5, result.get(4L).size());
    }
}
Also used : GraknTx(ai.grakn.GraknTx) Set(java.util.Set) Attribute(ai.grakn.concept.Attribute) Test(org.junit.Test)

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