use of ai.grakn.concept.Relationship in project grakn by graknlabs.
the class RelationshipTypePropertyTest method whenAddingARelation_TheRelationHasNoResources.
@Property
public void whenAddingARelation_TheRelationHasNoResources(@NonMeta @NonAbstract RelationshipType type) {
Relationship relationship = type.addRelationship();
assertThat(relationship.attributes().collect(toSet()), empty());
}
use of ai.grakn.concept.Relationship in project grakn by graknlabs.
the class RelationshipTypePropertyTest method whenAddingARelation_TheRelationHasNoRolePlayers.
@Property
public void whenAddingARelation_TheRelationHasNoRolePlayers(@NonMeta @NonAbstract RelationshipType type) {
Relationship relationship = type.addRelationship();
assertThat(relationship.rolePlayers().collect(toSet()), empty());
}
use of ai.grakn.concept.Relationship in project grakn by graknlabs.
the class DegreeTest method testRelationshipPlaysARole.
@Test
public void testRelationshipPlaysARole() throws InvalidKBException {
Role pet = tx.putRole("pet");
Role owner = tx.putRole("owner");
RelationshipType mansBestFriend = tx.putRelationshipType("mans-best-friend").relates(pet).relates(owner);
EntityType person = tx.putEntityType("person").plays(owner);
EntityType animal = tx.putEntityType("animal").plays(pet);
Role ownership = tx.putRole("ownership");
Role ownershipResource = tx.putRole("ownership-resource");
RelationshipType hasOwnershipResource = tx.putRelationshipType("has-ownership-resource").relates(ownership).relates(ownershipResource);
AttributeType<String> startDate = tx.putAttributeType("start-date", AttributeType.DataType.STRING);
startDate.plays(ownershipResource);
mansBestFriend.plays(ownership);
// add instances
Entity coco = animal.addEntity();
Entity dave = person.addEntity();
Relationship daveOwnsCoco = mansBestFriend.addRelationship().addRolePlayer(owner, dave).addRolePlayer(pet, coco);
Attribute aStartDate = startDate.putAttribute("01/01/01");
hasOwnershipResource.addRelationship().addRolePlayer(ownershipResource, aStartDate).addRolePlayer(ownership, daveOwnsCoco);
Map<Long, Set<String>> referenceDegrees = new HashMap<>();
referenceDegrees.put(1L, Sets.newHashSet(coco.getId().getValue(), dave.getId().getValue(), aStartDate.getId().getValue(), daveOwnsCoco.getId().getValue()));
tx.commit();
try (GraknTx graph = session.open(GraknTxType.READ)) {
Map<Long, Set<String>> degrees = graph.graql().compute().centrality().usingDegree().execute();
assertEquals(referenceDegrees, degrees);
}
}
use of ai.grakn.concept.Relationship in project grakn by graknlabs.
the class RelationshipTypePropertyTest method whenAddingARelation_TheDirectTypeOfTheRelationIsTheTypeItWasCreatedFrom.
@Property
public void whenAddingARelation_TheDirectTypeOfTheRelationIsTheTypeItWasCreatedFrom(@NonMeta @NonAbstract RelationshipType type) {
Relationship relationship = type.addRelationship();
assertEquals(type, relationship.type());
}
use of ai.grakn.concept.Relationship in project grakn by graknlabs.
the class RelationshipTypePropertyTest method whenAddingARelation_TheRelationIsInNoRelations.
@Property
public void whenAddingARelation_TheRelationIsInNoRelations(@NonMeta @NonAbstract RelationshipType type) {
Relationship relationship = type.addRelationship();
assertThat(relationship.relationships().collect(toSet()), empty());
}
Aggregations