Search in sources :

Example 21 with Concept

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

the class GrpcServerTest method whenGettingIsImplicitProperty_IsImplicitIsReturned.

@Test
public void whenGettingIsImplicitProperty_IsImplicitIsReturned() throws InterruptedException {
    ConceptId id = ConceptId.of("V123456");
    Concept concept = mock(Concept.class, RETURNS_DEEP_STUBS);
    when(tx.getConcept(id)).thenReturn(concept);
    when(concept.isSchemaConcept()).thenReturn(true);
    when(concept.asSchemaConcept().isImplicit()).thenReturn(true);
    try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
        tx.send(openRequest(MYKS, GraknTxType.READ));
        tx.receive().ok();
        tx.send(GrpcUtil.runConceptMethodRequest(id, ConceptMethods.IS_IMPLICIT));
        assertTrue(ConceptMethods.IS_IMPLICIT.get(conceptConverter, client, tx.receive().ok()));
    }
}
Also used : GrpcConcept(ai.grakn.rpc.generated.GrpcConcept) Concept(ai.grakn.concept.Concept) TxGrpcCommunicator(ai.grakn.grpc.TxGrpcCommunicator) ConceptId(ai.grakn.concept.ConceptId) Test(org.junit.Test)

Example 22 with Concept

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

the class GrpcServerTest method whenRemovingRolePlayer_RolePlayerIsRemoved.

@Test
public void whenRemovingRolePlayer_RolePlayerIsRemoved() throws InterruptedException {
    ConceptId conceptId = ConceptId.of("V123456");
    ConceptId roleId = ConceptId.of("ROLE");
    ConceptId playerId = ConceptId.of("PLAYER");
    Concept concept = mock(Concept.class, RETURNS_DEEP_STUBS);
    when(tx.getConcept(conceptId)).thenReturn(concept);
    when(concept.isRelationship()).thenReturn(true);
    Role role = mock(Role.class, RETURNS_DEEP_STUBS);
    when(tx.getConcept(roleId)).thenReturn(role);
    when(role.isRole()).thenReturn(true);
    when(role.asRole()).thenReturn(role);
    when(role.getId()).thenReturn(roleId);
    Entity player = mock(Entity.class, RETURNS_DEEP_STUBS);
    when(tx.getConcept(playerId)).thenReturn(player);
    when(player.isEntity()).thenReturn(true);
    when(player.asEntity()).thenReturn(player);
    when(player.isThing()).thenReturn(true);
    when(player.asThing()).thenReturn(player);
    when(player.getId()).thenReturn(playerId);
    try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
        tx.send(openRequest(MYKS, GraknTxType.READ));
        tx.receive().ok();
        ConceptMethod<Void> conceptMethod = ConceptMethods.removeRolePlayer(RolePlayer.create(role, player));
        tx.send(GrpcUtil.runConceptMethodRequest(conceptId, conceptMethod));
        tx.receive().ok();
        verify(concept.asRelationship()).removeRolePlayer(role, player);
    }
}
Also used : GrpcConcept(ai.grakn.rpc.generated.GrpcConcept) Concept(ai.grakn.concept.Concept) Role(ai.grakn.concept.Role) Entity(ai.grakn.concept.Entity) TxGrpcCommunicator(ai.grakn.grpc.TxGrpcCommunicator) ConceptId(ai.grakn.concept.ConceptId) Test(org.junit.Test)

Example 23 with Concept

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

the class XMLMigratorTest method clearGraph.

@After
public void clearGraph() {
    try (GraknTx graph = session.open(GraknTxType.WRITE)) {
        AttributeType<String> nameType = graph.getAttributeType("name");
        nameType.instances().forEach(Concept::delete);
        EntityType thingType = graph.getEntityType("thingy");
        thingType.instances().forEach(Concept::delete);
        graph.commit();
    }
}
Also used : Concept(ai.grakn.concept.Concept) EntityType(ai.grakn.concept.EntityType) GraknTx(ai.grakn.GraknTx) After(org.junit.After)

Example 24 with Concept

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

the class GrpcServerIT method whenGettingAConcept_TheInformationOnTheConceptIsCorrect.

@Test
public void whenGettingAConcept_TheInformationOnTheConceptIsCorrect() {
    try (GraknTx remoteTx = remoteSession.open(GraknTxType.READ);
        GraknTx localTx = localSession.open(GraknTxType.READ)) {
        GetQuery query = remoteTx.graql().match(var("x")).get();
        for (Answer answer : query) {
            Concept remoteConcept = answer.get("x");
            Concept localConcept = localTx.getConcept(remoteConcept.getId());
            assertEquals(localConcept.isAttribute(), remoteConcept.isAttribute());
            assertEquals(localConcept.isAttributeType(), remoteConcept.isAttributeType());
            assertEquals(localConcept.isEntity(), remoteConcept.isEntity());
            assertEquals(localConcept.isEntityType(), remoteConcept.isEntityType());
            assertEquals(localConcept.isRelationship(), remoteConcept.isRelationship());
            assertEquals(localConcept.isRelationshipType(), remoteConcept.isRelationshipType());
            assertEquals(localConcept.isRole(), remoteConcept.isRole());
            assertEquals(localConcept.isRule(), remoteConcept.isRule());
            assertEquals(localConcept.isSchemaConcept(), remoteConcept.isSchemaConcept());
            assertEquals(localConcept.isThing(), remoteConcept.isThing());
            assertEquals(localConcept.isType(), remoteConcept.isType());
            assertEquals(localConcept.getId(), remoteConcept.getId());
            assertEquals(localConcept.isDeleted(), remoteConcept.isDeleted());
            assertEquals(localConcept.keyspace(), remoteConcept.keyspace());
        }
    }
}
Also used : Concept(ai.grakn.concept.Concept) SchemaConcept(ai.grakn.concept.SchemaConcept) GraknTx(ai.grakn.GraknTx) Answer(ai.grakn.graql.admin.Answer) GetQuery(ai.grakn.graql.GetQuery) Test(org.junit.Test)

Example 25 with Concept

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

the class ReasonerQueryImpl method getRoleSubstitution.

public Answer getRoleSubstitution() {
    Map<Var, Concept> roleSub = new HashMap<>();
    getAtoms(RelationshipAtom.class).flatMap(RelationshipAtom::getRolePredicates).forEach(p -> {
        Concept concept = tx().getConcept(p.getPredicate());
        if (concept == null)
            throw GraqlQueryException.idNotFound(p.getPredicate());
        roleSub.put(p.getVarName(), concept);
    });
    return new QueryAnswer(roleSub);
}
Also used : Concept(ai.grakn.concept.Concept) QueryAnswer(ai.grakn.graql.internal.query.QueryAnswer) HashMap(java.util.HashMap) Var(ai.grakn.graql.Var)

Aggregations

Concept (ai.grakn.concept.Concept)91 Test (org.junit.Test)56 ConceptId (ai.grakn.concept.ConceptId)26 GraknTx (ai.grakn.GraknTx)25 Answer (ai.grakn.graql.admin.Answer)25 SchemaConcept (ai.grakn.concept.SchemaConcept)19 Label (ai.grakn.concept.Label)18 GrpcConcept (ai.grakn.rpc.generated.GrpcConcept)18 QueryBuilder (ai.grakn.graql.QueryBuilder)17 Var (ai.grakn.graql.Var)15 Set (java.util.Set)15 Role (ai.grakn.concept.Role)14 QueryAnswer (ai.grakn.graql.internal.query.QueryAnswer)14 HashSet (java.util.HashSet)13 List (java.util.List)12 AttributeType (ai.grakn.concept.AttributeType)11 EntityType (ai.grakn.concept.EntityType)11 Schema (ai.grakn.util.Schema)10 Collectors (java.util.stream.Collectors)10 Stream (java.util.stream.Stream)10