use of ai.grakn.concept.Entity 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.concept.Entity in project grakn by graknlabs.
the class DegreeTest method testSubIsAccountedForInSubgraph.
@Test
public void testSubIsAccountedForInSubgraph() {
Role pet = tx.putRole("pet");
Role owner = tx.putRole("owner");
Entity person = tx.putEntityType("person").plays(owner).addEntity();
EntityType animal = tx.putEntityType("animal").plays(pet);
Entity dog = tx.putEntityType("dog").sup(animal).addEntity();
tx.putRelationshipType("mans-best-friend").relates(pet).relates(owner).addRelationship().addRolePlayer(pet, dog).addRolePlayer(owner, person);
Map<Long, Set<String>> correctDegrees = new HashMap<>();
correctDegrees.put(1L, Sets.newHashSet(person.getId().getValue(), dog.getId().getValue()));
tx.commit();
try (GraknTx graph = session.open(GraknTxType.READ)) {
// set subgraph, use animal instead of dog
Set<Label> ct = Sets.newHashSet(Label.of("person"), Label.of("animal"), Label.of("mans-best-friend"));
Map<Long, Set<String>> degrees = graph.graql().compute().centrality().usingDegree().in(ct).execute();
// check that dog has a degree to confirm sub has been inferred
assertEquals(correctDegrees, degrees);
}
}
use of ai.grakn.concept.Entity in project grakn by graknlabs.
the class KCoreTest 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<String, Set<String>> result;
try (GraknTx graph = session.open(GraknTxType.READ)) {
result = graph.graql().compute().cluster().usingKCore().kValue(3L).execute();
assertEquals(2, result.size());
assertEquals(4, result.values().iterator().next().size());
System.out.println("result = " + result);
result = graph.graql().compute().cluster().usingKCore().kValue(2L).execute();
assertEquals(1, result.size());
assertEquals(9, result.values().iterator().next().size());
}
}
use of ai.grakn.concept.Entity in project grakn by graknlabs.
the class CSVMigratorTest method whenLinesIsSetToN_OnlyFirstNLinesAreProcessed.
@Test
public void whenLinesIsSetToN_OnlyFirstNLinesAreProcessed() {
load(factory, getFile("csv", "pets/schema.gql"));
String template = getFileAsString("csv", "pets/template.gql");
declareAndLoad(template, "pets/data/pets.quotes", new MigratorBuilder().setUri(engine.uri()).setKeyspace(keyspace).setRetries(0).setFailFast(false).setLines(3).build());
try (GraknTx graph = factory.open(GraknTxType.WRITE)) {
// Re Open Transaction
Collection<Entity> pets = graph.getEntityType("pet").instances().collect(Collectors.toSet());
TestCase.assertEquals(3, pets.size());
Collection<Entity> cats = graph.getEntityType("cat").instances().collect(Collectors.toSet());
TestCase.assertEquals(2, cats.size());
Collection<Entity> dogs = graph.getEntityType("dog").instances().collect(Collectors.toSet());
TestCase.assertEquals(0, dogs.size());
}
}
use of ai.grakn.concept.Entity in project grakn by graknlabs.
the class JsonMigratorMainTest method runAndAssertDataCorrect.
private void runAndAssertDataCorrect(String... args) {
run(args);
try (GraknTx graph = session.open(GraknTxType.READ)) {
EntityType personType = graph.getEntityType("person");
assertEquals(1, personType.instances().count());
Entity person = personType.instances().iterator().next();
Entity address = getProperty(graph, person, "has-address").asEntity();
Entity streetAddress = getProperty(graph, address, "address-has-street").asEntity();
Attribute number = getResource(graph, streetAddress, Label.of("number"));
assertEquals(21L, number.getValue());
Collection<Thing> phoneNumbers = getProperties(graph, person, "has-phone");
assertEquals(2, phoneNumbers.size());
}
}
Aggregations