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