Search in sources :

Example 26 with Relationship

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());
}
Also used : Relationship(ai.grakn.concept.Relationship) Property(com.pholser.junit.quickcheck.Property)

Example 27 with Relationship

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());
}
Also used : Relationship(ai.grakn.concept.Relationship) Property(com.pholser.junit.quickcheck.Property)

Example 28 with Relationship

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);
    }
}
Also used : Entity(ai.grakn.concept.Entity) HashSet(java.util.HashSet) Set(java.util.Set) Attribute(ai.grakn.concept.Attribute) HashMap(java.util.HashMap) RelationshipType(ai.grakn.concept.RelationshipType) Role(ai.grakn.concept.Role) EntityType(ai.grakn.concept.EntityType) GraknTx(ai.grakn.GraknTx) Relationship(ai.grakn.concept.Relationship) Test(org.junit.Test)

Example 29 with Relationship

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());
}
Also used : Relationship(ai.grakn.concept.Relationship) Property(com.pholser.junit.quickcheck.Property)

Example 30 with Relationship

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());
}
Also used : Relationship(ai.grakn.concept.Relationship) Property(com.pholser.junit.quickcheck.Property)

Aggregations

Relationship (ai.grakn.concept.Relationship)50 Test (org.junit.Test)36 Role (ai.grakn.concept.Role)27 EntityType (ai.grakn.concept.EntityType)22 RelationshipType (ai.grakn.concept.RelationshipType)22 Entity (ai.grakn.concept.Entity)15 Thing (ai.grakn.concept.Thing)11 Label (ai.grakn.concept.Label)9 HashSet (java.util.HashSet)9 Attribute (ai.grakn.concept.Attribute)8 ConceptId (ai.grakn.concept.ConceptId)8 GraknTx (ai.grakn.GraknTx)7 Set (java.util.Set)7 Concept (ai.grakn.concept.Concept)6 Stream (java.util.stream.Stream)6 Type (ai.grakn.concept.Type)5 Answer (ai.grakn.graql.admin.Answer)5 Schema (ai.grakn.util.Schema)5 Property (com.pholser.junit.quickcheck.Property)5 Collectors (java.util.stream.Collectors)5