Search in sources :

Example 46 with Thing

use of ai.grakn.concept.Thing in project grakn by graknlabs.

the class TransitivityChainKB method buildExtensionalDB.

private void buildExtensionalDB(GraknTx graph, int n) {
    Role qfrom = graph.getRole("Q-from");
    Role qto = graph.getRole("Q-to");
    EntityType aEntity = graph.getEntityType("a-entity");
    RelationshipType q = graph.getRelationshipType("Q");
    Thing aInst = putEntityWithResource(graph, "a", graph.getEntityType("entity2"), key);
    ConceptId[] aInstanceIds = new ConceptId[n];
    for (int i = 0; i < n; i++) {
        aInstanceIds[i] = putEntityWithResource(graph, "a" + i, aEntity, key).getId();
    }
    q.addRelationship().addRolePlayer(qfrom, aInst).addRolePlayer(qto, graph.getConcept(aInstanceIds[0]));
    for (int i = 0; i < n - 1; i++) {
        q.addRelationship().addRolePlayer(qfrom, graph.getConcept(aInstanceIds[i])).addRolePlayer(qto, graph.getConcept(aInstanceIds[i + 1]));
    }
}
Also used : Role(ai.grakn.concept.Role) EntityType(ai.grakn.concept.EntityType) RelationshipType(ai.grakn.concept.RelationshipType) Thing(ai.grakn.concept.Thing) ConceptId(ai.grakn.concept.ConceptId)

Example 47 with Thing

use of ai.grakn.concept.Thing 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

Thing (ai.grakn.concept.Thing)47 Role (ai.grakn.concept.Role)30 Test (org.junit.Test)29 RelationshipType (ai.grakn.concept.RelationshipType)17 EntityType (ai.grakn.concept.EntityType)14 Relationship (ai.grakn.concept.Relationship)12 HashSet (java.util.HashSet)9 Set (java.util.Set)9 GraknTx (ai.grakn.GraknTx)7 Attribute (ai.grakn.concept.Attribute)7 ConceptId (ai.grakn.concept.ConceptId)7 AttributeType (ai.grakn.concept.AttributeType)6 Concept (ai.grakn.concept.Concept)6 Entity (ai.grakn.concept.Entity)6 Collectors (java.util.stream.Collectors)5 Label (ai.grakn.concept.Label)4 Schema (ai.grakn.util.Schema)4 Collection (java.util.Collection)4 Map (java.util.Map)4 GraknSession (ai.grakn.GraknSession)3