Search in sources :

Example 61 with Concept

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

the class GrpcServerTest method whenGettingALabelForANonSchemaConcept_Throw.

@Test
public void whenGettingALabelForANonSchemaConcept_Throw() throws InterruptedException {
    ConceptId id = ConceptId.of("V123456");
    Concept concept = mock(Concept.class);
    when(tx.getConcept(id)).thenReturn(concept);
    when(concept.isSchemaConcept()).thenReturn(false);
    when(concept.asSchemaConcept()).thenThrow(EXCEPTION);
    try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
        tx.send(openRequest(MYKS, GraknTxType.READ));
        tx.receive().ok();
        tx.send(GrpcUtil.runConceptMethodRequest(id, ConceptMethods.GET_LABEL));
        exception.expect(hasStatus(Status.UNKNOWN.withDescription(EXCEPTION_MESSAGE)));
        throw tx.receive().error();
    }
}
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 62 with Concept

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

the class GrpcServerTest method whenGettingAConcept_ReturnTheConcept.

@Test
public void whenGettingAConcept_ReturnTheConcept() throws InterruptedException {
    ConceptId id = ConceptId.of("V123456");
    Concept concept = mock(Concept.class, RETURNS_DEEP_STUBS);
    when(concept.getId()).thenReturn(id);
    when(concept.isRelationship()).thenReturn(true);
    when(tx.getConcept(id)).thenReturn(concept);
    try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
        tx.send(openRequest(MYKS, GraknTxType.READ));
        tx.receive().ok();
        tx.send(GrpcUtil.getConceptRequest(id));
        GrpcConcept.OptionalConcept response = tx.receive().ok().getOptionalConcept();
        assertEquals(id.getValue(), response.getPresent().getId().getValue());
        assertEquals(BaseType.Relationship, response.getPresent().getBaseType());
    }
}
Also used : GrpcConcept(ai.grakn.rpc.generated.GrpcConcept) Concept(ai.grakn.concept.Concept) GrpcConcept(ai.grakn.rpc.generated.GrpcConcept) TxGrpcCommunicator(ai.grakn.grpc.TxGrpcCommunicator) ConceptId(ai.grakn.concept.ConceptId) Test(org.junit.Test)

Example 63 with Concept

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

the class GrpcServerTest method whenGettingIsInferredProperty_IsInferredIsReturned.

@Test
public void whenGettingIsInferredProperty_IsInferredIsReturned() throws InterruptedException {
    ConceptId id = ConceptId.of("V123456");
    Concept concept = mock(Concept.class, RETURNS_DEEP_STUBS);
    when(tx.getConcept(id)).thenReturn(concept);
    when(concept.isThing()).thenReturn(true);
    when(concept.asThing().isInferred()).thenReturn(false);
    try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
        tx.send(openRequest(MYKS, GraknTxType.READ));
        tx.receive().ok();
        tx.send(GrpcUtil.runConceptMethodRequest(id, ConceptMethods.IS_INFERRED));
        assertFalse(ConceptMethods.IS_INFERRED.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 64 with Concept

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

the class AtomicTest method testRuleApplicability_InstancesMakeRuleInapplicable_NoRoleTypes_NoRelationType.

@Test
public void testRuleApplicability_InstancesMakeRuleInapplicable_NoRoleTypes_NoRelationType() {
    EmbeddedGraknTx<?> graph = ruleApplicabilitySet.tx();
    Concept concept = getConcept(graph, "name", "noRoleEntity");
    String relationString = "{" + "($x, $y);" + "$x id '" + concept.getId().getValue() + "';" + "}";
    Atom relation = ReasonerQueries.atomic(conjunction(relationString, graph), graph).getAtom();
    assertThat(relation.getApplicableRules().collect(toSet()), empty());
}
Also used : Concept(ai.grakn.concept.Concept) Atom(ai.grakn.graql.internal.reasoner.atom.Atom) RelationshipAtom(ai.grakn.graql.internal.reasoner.atom.binary.RelationshipAtom) ResourceAtom(ai.grakn.graql.internal.reasoner.atom.binary.ResourceAtom) Test(org.junit.Test)

Example 65 with Concept

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

the class GenealogyTest method hasDuplicates.

private boolean hasDuplicates(List<Answer> answers) {
    boolean hasDuplicates = false;
    Iterator<Answer> it = answers.iterator();
    while (it.hasNext() && !hasDuplicates) {
        Answer answer = it.next();
        Set<Concept> existing = new HashSet<>();
        hasDuplicates = answer.entrySet().stream().filter(entry -> existing.add(entry.getValue())).count() != answer.size();
        if (hasDuplicates)
            System.out.println(answer.toString());
    }
    return hasDuplicates;
}
Also used : Concept(ai.grakn.concept.Concept) QueryBuilder(ai.grakn.graql.QueryBuilder) Matchers.empty(org.hamcrest.Matchers.empty) BeforeClass(org.junit.BeforeClass) Iterator(java.util.Iterator) GraqlTestUtil.assertCollectionsEqual(ai.grakn.util.GraqlTestUtil.assertCollectionsEqual) Concept(ai.grakn.concept.Concept) GenealogyKB(ai.grakn.test.kbs.GenealogyKB) Graql(ai.grakn.graql.Graql) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Answer(ai.grakn.graql.admin.Answer) GetQuery(ai.grakn.graql.GetQuery) Sets(com.google.common.collect.Sets) HashSet(java.util.HashSet) Assert.assertThat(org.junit.Assert.assertThat) List(java.util.List) SampleKBContext(ai.grakn.test.rule.SampleKBContext) ClassRule(org.junit.ClassRule) Assert.assertEquals(org.junit.Assert.assertEquals) Answer(ai.grakn.graql.admin.Answer) HashSet(java.util.HashSet)

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