use of ai.grakn.concept.Relationship in project grakn by graknlabs.
the class RelationshipTypeImpl method addRelationship.
public Relationship addRelationship(boolean isInferred) {
Relationship relationship = addInstance(Schema.BaseType.RELATIONSHIP, (vertex, type) -> vertex().tx().factory().buildRelation(vertex, type), isInferred, true);
vertex().tx().txCache().addNewRelationship(relationship);
return relationship;
}
use of ai.grakn.concept.Relationship in project grakn by graknlabs.
the class GraqlPrinterTest method whenGettingOutputForRelation_TheResultShouldHaveCommasBetweenRolePlayers.
@Test
public void whenGettingOutputForRelation_TheResultShouldHaveCommasBetweenRolePlayers() {
Printer printer = Printers.graql(true);
Match match = rule.tx().graql().match(var("r").isa("has-cluster"));
Relationship relationship = match.get("r").iterator().next().asRelationship();
long numRolePlayers = relationship.rolePlayers().count();
long numCommas = numRolePlayers - 1;
String relationString = printer.graqlString(relationship);
assertEquals(relationString + " should have " + numCommas + " commas separating role-players", numCommas, StringUtils.countMatches(relationString, ","));
}
use of ai.grakn.concept.Relationship in project grakn by graknlabs.
the class InsertQueryTest method whenAddingProvenanceToAnExistingRelationship_TheProvenanceIsAdded.
@Test
public void whenAddingProvenanceToAnExistingRelationship_TheProvenanceIsAdded() {
InsertQuery query = qb.match(w.isa("movie").has(title, x.val("The Muppets"), y)).insert(x, w, y.has("provenance", z.val("Someone told me")));
Answer answer = Iterables.getOnlyElement(query.execute());
Entity movie = answer.get(w).asEntity();
Attribute<String> theTitle = answer.get(x).asAttribute();
Relationship hasTitle = answer.get(y).asRelationship();
Attribute<String> provenance = answer.get(z).asAttribute();
assertThat(hasTitle.rolePlayers().toArray(), arrayContainingInAnyOrder(movie, theTitle));
assertThat(hasTitle.attributes().toArray(), arrayContaining(provenance));
}
use of ai.grakn.concept.Relationship in project grakn by graknlabs.
the class EntityTest method checkKeyCreatesCorrectResourceStructure.
@Test
public void checkKeyCreatesCorrectResourceStructure() {
Label resourceLabel = Label.of("A Attribute Thing");
EntityType entityType = tx.putEntityType("A Thing");
AttributeType<String> attributeType = tx.putAttributeType(resourceLabel, AttributeType.DataType.STRING);
entityType.key(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.KEY, Schema.ImplicitType.KEY_OWNER, Schema.ImplicitType.KEY_VALUE);
}
use of ai.grakn.concept.Relationship in project grakn by graknlabs.
the class EntityTest method whenDeletingLastRolePlayerInRelation_TheRelationIsDeleted.
@Test
public void whenDeletingLastRolePlayerInRelation_TheRelationIsDeleted() throws GraknTxOperationException {
EntityType type = tx.putEntityType("Concept Type");
RelationshipType relationshipType = tx.putRelationshipType("relationTypes");
Role role1 = tx.putRole("role1");
Thing rolePlayer1 = type.addEntity();
Relationship relationship = relationshipType.addRelationship().addRolePlayer(role1, rolePlayer1);
assertNotNull(tx.getConcept(relationship.getId()));
rolePlayer1.delete();
assertNull(tx.getConcept(relationship.getId()));
}
Aggregations