use of ai.grakn.concept.RelationshipType in project grakn by graknlabs.
the class RelationshipTypeTest method whenCallingInstancesOnImplicitRelationType_RelationEdgesAreReturned.
@Test
public void whenCallingInstancesOnImplicitRelationType_RelationEdgesAreReturned() {
AttributeType<String> attributeType = tx.putAttributeType("My Special Attribute Type", AttributeType.DataType.STRING);
Attribute<String> attribute = attributeType.putAttribute("Ad thing");
EntityType entityType = tx.putEntityType("My Special Entity Type").attribute(attributeType);
Entity entity = entityType.addEntity();
RelationshipType implicitRelationshipType = tx.getRelationshipType(Schema.ImplicitType.HAS.getLabel(attributeType.getLabel()).getValue());
assertNotNull(implicitRelationshipType);
assertThat(implicitRelationshipType.instances().collect(toSet()), empty());
entity.attribute(attribute);
assertEquals(1, implicitRelationshipType.instances().count());
}
use of ai.grakn.concept.RelationshipType in project grakn by graknlabs.
the class RelationshipTypeTest method whenSettingAnImplicitRelationTypeWithInstancesAbstract_Throw.
@Test
public void whenSettingAnImplicitRelationTypeWithInstancesAbstract_Throw() {
AttributeType<String> attributeType = tx.putAttributeType("My Special Attribute Type", AttributeType.DataType.STRING);
Attribute<String> attribute = attributeType.putAttribute("Ad thing");
EntityType entityType = tx.putEntityType("My Special Entity Type").attribute(attributeType);
entityType.addEntity().attribute(attribute);
RelationshipType implicitRelationshipType = tx.getRelationshipType(Schema.ImplicitType.HAS.getLabel(attributeType.getLabel()).getValue());
expectedException.expect(GraknTxOperationException.class);
expectedException.expectMessage(GraknTxOperationException.addingInstancesToAbstractType(implicitRelationshipType).getMessage());
implicitRelationshipType.setAbstract(true);
}
use of ai.grakn.concept.RelationshipType in project grakn by graknlabs.
the class LinearTransitivityMatrixKB method buildExtensionalDB.
private void buildExtensionalDB(GraknTx graph, int n, int m) {
Role Qfrom = graph.getRole("Q-from");
Role Qto = graph.getRole("Q-to");
EntityType aEntity = graph.getEntityType("a-entity");
RelationshipType Q = graph.getRelationshipType("Q");
ConceptId[][] aInstancesIds = new ConceptId[n + 1][m + 1];
Thing aInst = putEntityWithResource(graph, "a", graph.getEntityType("entity2"), key);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
aInstancesIds[i][j] = putEntityWithResource(graph, "a" + i + "," + j, aEntity, key).getId();
}
}
Q.addRelationship().addRolePlayer(Qfrom, aInst).addRolePlayer(Qto, graph.getConcept(aInstancesIds[1][1]));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (i < n) {
Q.addRelationship().addRolePlayer(Qfrom, graph.getConcept(aInstancesIds[i][j])).addRolePlayer(Qto, graph.getConcept(aInstancesIds[i + 1][j]));
}
if (j < m) {
Q.addRelationship().addRolePlayer(Qfrom, graph.getConcept(aInstancesIds[i][j])).addRolePlayer(Qto, graph.getConcept(aInstancesIds[i][j + 1]));
}
}
}
}
use of ai.grakn.concept.RelationshipType in project grakn by graknlabs.
the class GrpcServerIT method whenGettingARelationshipType_TheInformationOnTheRelationshipTypeIsCorrect.
@Test
public void whenGettingARelationshipType_TheInformationOnTheRelationshipTypeIsCorrect() {
try (GraknTx remoteTx = remoteSession.open(GraknTxType.READ);
GraknTx localTx = localSession.open(GraknTxType.READ)) {
GetQuery query = remoteTx.graql().match(var("x").label("has-cast")).get();
RelationshipType remoteConcept = query.stream().findAny().get().get("x").asRelationshipType();
RelationshipType localConcept = localTx.getConcept(remoteConcept.getId()).asRelationshipType();
assertEqualConcepts(localConcept, remoteConcept, RelationshipType::relates);
}
}
use of ai.grakn.concept.RelationshipType in project grakn by graknlabs.
the class GraknTxJanusTest method whenDeletingARelationshipTypeWithRoles_TheRelationshipTypeIsDeleted.
@Test
public void whenDeletingARelationshipTypeWithRoles_TheRelationshipTypeIsDeleted() {
Role murderer = graknTx.putRole("murderer");
Role victim = graknTx.putRole("victim");
RelationshipType murder = graknTx.putRelationshipType("murder").relates(murderer).relates(victim);
murder.delete();
assertTrue(murder.isDeleted());
assertThat(murderer.relationshipTypes().toArray(), emptyArray());
assertThat(victim.relationshipTypes().toArray(), emptyArray());
}
Aggregations