use of ai.grakn.concept.Thing in project grakn by graknlabs.
the class CastingTest method whenUpdatingRelation_EnsureRolePlayersAreUpdated.
@Test
public void whenUpdatingRelation_EnsureRolePlayersAreUpdated() {
Entity e1 = entityType.addEntity();
Entity e3 = entityType.addEntity();
RelationshipImpl relation = (RelationshipImpl) relationshipType.addRelationship().addRolePlayer(role1, e1);
Set<Thing> things = relation.reified().get().castingsRelation().map(Casting::getRolePlayer).collect(Collectors.toSet());
Set<Role> roles = relation.reified().get().castingsRelation().map(Casting::getRole).collect(Collectors.toSet());
assertThat(things, containsInAnyOrder(e1));
assertThat(roles, containsInAnyOrder(role1));
// Now Update
relation.addRolePlayer(role2, e1).addRolePlayer(role3, e3);
things = relation.reified().get().castingsRelation().map(Casting::getRolePlayer).collect(Collectors.toSet());
roles = relation.reified().get().castingsRelation().map(Casting::getRole).collect(Collectors.toSet());
assertThat(things, containsInAnyOrder(e1, e3));
assertThat(roles, containsInAnyOrder(role1, role2, role3));
}
use of ai.grakn.concept.Thing in project grakn by graknlabs.
the class MigratorTestUtils method getResources.
public static Stream<Attribute> getResources(GraknTx graph, Thing thing, Label label) {
Role roleOwner = graph.getSchemaConcept(Schema.ImplicitType.HAS_OWNER.getLabel(label));
Role roleOther = graph.getSchemaConcept(Schema.ImplicitType.HAS_VALUE.getLabel(label));
Stream<Relationship> relations = thing.relationships(roleOwner);
return relations.flatMap(r -> r.rolePlayers(roleOther)).map(Concept::asAttribute);
}
use of ai.grakn.concept.Thing in project grakn by graknlabs.
the class RelationshipTest method ensureRelationToStringContainsRolePlayerInformation.
@Test
public void ensureRelationToStringContainsRolePlayerInformation() {
Role role1 = tx.putRole("role type 1");
Role role2 = tx.putRole("role type 2");
RelationshipType relationshipType = tx.putRelationshipType("A relationship Type").relates(role1).relates(role2);
EntityType type = tx.putEntityType("concept type").plays(role1).plays(role2);
Thing thing1 = type.addEntity();
Thing thing2 = type.addEntity();
Relationship relationship = relationshipType.addRelationship().addRolePlayer(role1, thing1).addRolePlayer(role2, thing2);
String mainDescription = "ID [" + relationship.getId() + "] Type [" + relationship.type().getLabel() + "] Roles and Role Players:";
String rolerp1 = " Role [" + role1.getLabel() + "] played by [" + thing1.getId() + ",]";
String rolerp2 = " Role [" + role2.getLabel() + "] played by [" + thing2.getId() + ",]";
assertTrue("Relationship toString missing main description", relationship.toString().contains(mainDescription));
assertTrue("Relationship toString missing role and role player definition", relationship.toString().contains(rolerp1));
assertTrue("Relationship toString missing role and role player definition", relationship.toString().contains(rolerp2));
}
use of ai.grakn.concept.Thing 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());
}
}
use of ai.grakn.concept.Thing in project grakn by graknlabs.
the class ValidatorTest method whenCommittingGraphWhichFollowsValidationRules_Commit.
@Test
public void whenCommittingGraphWhichFollowsValidationRules_Commit() {
RelationshipType cast = tx.putRelationshipType("Cast");
Role feature = tx.putRole("Feature");
Role actor = tx.putRole("Actor");
EntityType movie = tx.putEntityType("Movie");
EntityType person = tx.putEntityType("Person");
Thing pacino = person.addEntity();
Thing godfather = movie.addEntity();
EntityType genre = tx.putEntityType("Genre");
Role movieOfGenre = tx.putRole("Movie of Genre");
Role movieGenre = tx.putRole("Movie Genre");
Thing crime = genre.addEntity();
RelationshipType movieHasGenre = tx.putRelationshipType("Movie Has Genre");
// Construction
cast.relates(feature);
cast.relates(actor);
cast.addRelationship().addRolePlayer(feature, godfather).addRolePlayer(actor, pacino);
movieHasGenre.addRelationship().addRolePlayer(movieOfGenre, godfather).addRolePlayer(movieGenre, crime);
movieHasGenre.relates(movieOfGenre);
movieHasGenre.relates(movieGenre);
movie.plays(movieOfGenre);
person.plays(actor);
movie.plays(feature);
genre.plays(movieGenre);
tx.commit();
}
Aggregations