use of ai.grakn.concept.Relationship in project grakn by graknlabs.
the class MatchTest method whenQueryingForAnImplicitRelationById_TheRelationIsReturned.
@Test
public void whenQueryingForAnImplicitRelationById_TheRelationIsReturned() {
Match match = qb.match(var("x").isa(label(Schema.ImplicitType.HAS.getLabel("name"))));
Relationship relationship = match.get("x").findAny().get().asRelationship();
Match queryById = qb.match(var("x").id(relationship.getId()));
assertThat(queryById, variable(x, contains(MatchableConcept.of(relationship))));
}
use of ai.grakn.concept.Relationship in project grakn by graknlabs.
the class SchemaMutationTest method whenChangingTheSuperTypeOfAnEntityTypeWhichHasAResource_EnsureTheResourceIsStillAccessibleViaTheRelationTypeInstances_ByPreventingChange.
@Test
public void whenChangingTheSuperTypeOfAnEntityTypeWhichHasAResource_EnsureTheResourceIsStillAccessibleViaTheRelationTypeInstances_ByPreventingChange() {
AttributeType<String> name = tx.putAttributeType("name", AttributeType.DataType.STRING);
// Create a person and allow person to have a name
EntityType person = tx.putEntityType("person").attribute(name);
// Create a man which is a person and is therefore allowed to have a name
EntityType man = tx.putEntityType("man").sup(person);
RelationshipType has_name = tx.getRelationshipType("@has-name");
// Create a Man and name him Bob
Attribute<String> nameBob = name.putAttribute("Bob");
man.addEntity().attribute(nameBob);
// Get The Relationship which says that our man is name bob
Relationship expectedEdge = Iterables.getOnlyElement(has_name.instances().collect(toSet()));
Role hasNameOwner = tx.getRole("@has-name-owner");
assertThat(expectedEdge.type().instances().collect(toSet()), hasItem(expectedEdge));
expectedException.expect(GraknTxOperationException.class);
expectedException.expectMessage(GraknTxOperationException.changingSuperWillDisconnectRole(person, tx.admin().getMetaEntityType(), hasNameOwner).getMessage());
// Man is no longer a person and therefore is not allowed to have a name
man.sup(tx.admin().getMetaEntityType());
}
use of ai.grakn.concept.Relationship 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.Relationship in project grakn by graknlabs.
the class EntityTest method whenAddingResourceToAnEntity_EnsureTheImplicitStructureIsCreated.
@Test
public void whenAddingResourceToAnEntity_EnsureTheImplicitStructureIsCreated() {
Label resourceLabel = Label.of("A Attribute Thing");
EntityType entityType = tx.putEntityType("A Thing");
AttributeType<String> attributeType = tx.putAttributeType(resourceLabel, AttributeType.DataType.STRING);
entityType.attribute(attributeType);
Entity entity = entityType.addEntity();
Attribute attribute = attributeType.putAttribute("A attribute thing");
entity.attribute(attribute);
Relationship relationship = entity.relationships().iterator().next();
checkImplicitStructure(attributeType, relationship, entity, Schema.ImplicitType.HAS, Schema.ImplicitType.HAS_OWNER, Schema.ImplicitType.HAS_VALUE);
}
use of ai.grakn.concept.Relationship in project grakn by graknlabs.
the class RelationshipTest method whenAddingRolePlayerToRelation_RelationIsExpanded.
@Test
public void whenAddingRolePlayerToRelation_RelationIsExpanded() {
Relationship relationship = relationshipType.addRelationship();
Role role = tx.putRole("A role");
Entity entity1 = type.addEntity();
relationship.addRolePlayer(role, entity1);
assertThat(relationship.allRolePlayers().keySet(), containsInAnyOrder(role1, role2, role3, role));
assertThat(relationship.allRolePlayers().get(role), containsInAnyOrder(entity1));
}
Aggregations