Search in sources :

Example 41 with Relationship

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

Example 42 with 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, ","));
}
Also used : Relationship(ai.grakn.concept.Relationship) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Printer(ai.grakn.graql.Printer) Match(ai.grakn.graql.Match) Test(org.junit.Test)

Example 43 with Relationship

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));
}
Also used : InsertQuery(ai.grakn.graql.InsertQuery) Answer(ai.grakn.graql.admin.Answer) Entity(ai.grakn.concept.Entity) Relationship(ai.grakn.concept.Relationship) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 44 with Relationship

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);
}
Also used : EntityType(ai.grakn.concept.EntityType) Entity(ai.grakn.concept.Entity) Attribute(ai.grakn.concept.Attribute) Relationship(ai.grakn.concept.Relationship) Label(ai.grakn.concept.Label) Test(org.junit.Test)

Example 45 with Relationship

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()));
}
Also used : EntityType(ai.grakn.concept.EntityType) Role(ai.grakn.concept.Role) Relationship(ai.grakn.concept.Relationship) RelationshipType(ai.grakn.concept.RelationshipType) Thing(ai.grakn.concept.Thing) Test(org.junit.Test)

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