use of ai.grakn.concept.Role in project grakn by graknlabs.
the class NguyenKB method buildExtensionalDB.
private void buildExtensionalDB(GraknTx graph, int n) {
Role Rfrom = graph.getRole("R-rA");
Role Rto = graph.getRole("R-rB");
Role qfrom = graph.getRole("Q-rA");
Role qto = graph.getRole("Q-rB");
Role Pfrom = graph.getRole("P-rA");
Role Pto = graph.getRole("P-rB");
EntityType entity = graph.getEntityType("entity2");
EntityType aEntity = graph.getEntityType("a-entity");
EntityType bEntity = graph.getEntityType("b-entity");
RelationshipType r = graph.getRelationshipType("R");
RelationshipType p = graph.getRelationshipType("P");
RelationshipType q = graph.getRelationshipType("Q");
ConceptId cId = putEntityWithResource(graph, "c", entity, key).getId();
ConceptId dId = putEntityWithResource(graph, "d", entity, key).getId();
ConceptId eId = putEntityWithResource(graph, "e", entity, key).getId();
ConceptId[] aInstancesIds = new ConceptId[n + 2];
ConceptId[] bInstancesIds = new ConceptId[n + 2];
aInstancesIds[n + 1] = putEntityWithResource(graph, "a" + (n + 1), aEntity, key).getId();
for (int i = 0; i <= n; i++) {
aInstancesIds[i] = putEntityWithResource(graph, "a" + i, aEntity, key).getId();
bInstancesIds[i] = putEntityWithResource(graph, "b" + i, bEntity, key).getId();
}
p.addRelationship().addRolePlayer(Pfrom, graph.getConcept(cId)).addRolePlayer(Pto, graph.getConcept(dId));
r.addRelationship().addRolePlayer(Rfrom, graph.getConcept(dId)).addRolePlayer(Rto, graph.getConcept(eId));
q.addRelationship().addRolePlayer(qfrom, graph.getConcept(eId)).addRolePlayer(qto, graph.getConcept(aInstancesIds[0]));
for (int i = 0; i <= n; i++) {
p.addRelationship().addRolePlayer(Pfrom, graph.getConcept(bInstancesIds[i])).addRolePlayer(Pto, graph.getConcept(cId));
p.addRelationship().addRolePlayer(Pfrom, graph.getConcept(cId)).addRolePlayer(Pto, graph.getConcept(bInstancesIds[i]));
q.addRelationship().addRolePlayer(qfrom, graph.getConcept(aInstancesIds[i])).addRolePlayer(qto, graph.getConcept(bInstancesIds[i]));
q.addRelationship().addRolePlayer(qfrom, graph.getConcept(bInstancesIds[i])).addRolePlayer(qto, graph.getConcept(aInstancesIds[i + 1]));
}
}
use of ai.grakn.concept.Role in project grakn by graknlabs.
the class EntityTypeTest method whenCreatingEntityTypeUsingLabelTakenByAnotherType_Throw.
@Test
public void whenCreatingEntityTypeUsingLabelTakenByAnotherType_Throw() {
Role original = tx.putRole("Role Type");
expectedException.expect(PropertyNotUniqueException.class);
expectedException.expectMessage(PropertyNotUniqueException.cannotCreateProperty(original, Schema.VertexProperty.SCHEMA_LABEL, original.getLabel()).getMessage());
tx.putEntityType(original.getLabel());
}
use of ai.grakn.concept.Role in project grakn by graknlabs.
the class EntityTypeTest method whenGettingTheRolesPlayedByType_ReturnTheRoles.
@Test
public void whenGettingTheRolesPlayedByType_ReturnTheRoles() throws Exception {
Role monster = tx.putRole("monster");
Role animal = tx.putRole("animal");
Role monsterEvil = tx.putRole("evil monster").sup(monster);
EntityType creature = tx.putEntityType("creature").plays(monster).plays(animal);
EntityType creatureMysterious = tx.putEntityType("mysterious creature").sup(creature).plays(monsterEvil);
assertThat(creature.plays().collect(toSet()), containsInAnyOrder(monster, animal));
assertThat(creatureMysterious.plays().collect(toSet()), containsInAnyOrder(monster, animal, monsterEvil));
}
use of ai.grakn.concept.Role in project grakn by graknlabs.
the class RelationshipTypeTest method whenMutatingRolesOfRelationType_EnsureRelationTypeRolesAreAlwaysUpdated.
@Test
public void whenMutatingRolesOfRelationType_EnsureRelationTypeRolesAreAlwaysUpdated() {
RelationshipType relationshipType = tx.putRelationshipType("c1");
Role role1 = tx.putRole("c2");
Role role2 = tx.putRole("c3");
assertThat(relationshipType.relates().collect(toSet()), empty());
relationshipType.relates(role1).relates(role2);
assertThat(relationshipType.relates().collect(toSet()), containsInAnyOrder(role1, role2));
relationshipType.deleteRelates(role1);
assertThat(relationshipType.relates().collect(toSet()), containsInAnyOrder(role2));
}
use of ai.grakn.concept.Role in project grakn by graknlabs.
the class RelationshipTypeTest method whenGettingTheRolesOfRelationTypes_AllTheRolesAreReturned.
@Test
public void whenGettingTheRolesOfRelationTypes_AllTheRolesAreReturned() throws Exception {
RelationshipType relationshipType = tx.putRelationshipType("relationTypes");
Role role1 = tx.putRole("role1");
Role role2 = tx.putRole("role2");
Role role3 = tx.putRole("role3");
relationshipType.relates(role1).relates(role2).relates(role3);
assertThat(relationshipType.relates().collect(toSet()), containsInAnyOrder(role1, role2, role3));
}
Aggregations