Search in sources :

Example 41 with GetQuery

use of ai.grakn.graql.GetQuery in project grakn by graknlabs.

the class GrpcServerIT method whenGettingARole_TheInformationOnTheRoleIsCorrect.

@Test
public void whenGettingARole_TheInformationOnTheRoleIsCorrect() {
    try (GraknTx remoteTx = remoteSession.open(GraknTxType.READ);
        GraknTx localTx = localSession.open(GraknTxType.READ)) {
        GetQuery query = remoteTx.graql().match(var("x").label("actor")).get();
        Role remoteConcept = query.stream().findAny().get().get("x").asRole();
        Role localConcept = localTx.getConcept(remoteConcept.getId()).asRole();
        assertEqualConcepts(localConcept, remoteConcept, Role::playedByTypes);
        assertEqualConcepts(localConcept, remoteConcept, Role::relationshipTypes);
    }
}
Also used : Role(ai.grakn.concept.Role) GraknTx(ai.grakn.GraknTx) GetQuery(ai.grakn.graql.GetQuery) Test(org.junit.Test)

Example 42 with GetQuery

use of ai.grakn.graql.GetQuery in project grakn by graknlabs.

the class GrpcServerIT method whenGettingAnEntityType_TheInformationOnTheEntityTypeIsCorrect.

@Test
public void whenGettingAnEntityType_TheInformationOnTheEntityTypeIsCorrect() {
    try (GraknTx remoteTx = remoteSession.open(GraknTxType.READ);
        GraknTx localTx = localSession.open(GraknTxType.READ)) {
        GetQuery query = remoteTx.graql().match(var("x").label("person")).get();
        EntityType remoteConcept = query.stream().findAny().get().get("x").asEntityType();
        EntityType localConcept = localTx.getConcept(remoteConcept.getId()).asEntityType();
        // There actually aren't any new methods on EntityType, but we should still check we can get them
        assertEquals(localConcept.getId(), remoteConcept.getId());
    }
}
Also used : EntityType(ai.grakn.concept.EntityType) GraknTx(ai.grakn.GraknTx) GetQuery(ai.grakn.graql.GetQuery) Test(org.junit.Test)

Example 43 with GetQuery

use of ai.grakn.graql.GetQuery in project grakn by graknlabs.

the class GrpcServerIT method whenExecutingAnInvalidQuery_Throw.

@Test
public void whenExecutingAnInvalidQuery_Throw() throws Throwable {
    try (GraknTx tx = remoteSession.open(GraknTxType.READ)) {
        GetQuery query = tx.graql().match(var("x").isa("not-a-thing")).get();
        exception.expect(GraqlQueryException.class);
        exception.expectMessage(GraqlQueryException.labelNotFound(Label.of("not-a-thing")).getMessage());
        query.execute();
    }
}
Also used : GraknTx(ai.grakn.GraknTx) GetQuery(ai.grakn.graql.GetQuery) Test(org.junit.Test)

Example 44 with GetQuery

use of ai.grakn.graql.GetQuery in project grakn by graknlabs.

the class DirectIsaTest method testMatchSyntax.

@Test
public void testMatchSyntax() {
    QueryBuilder queryBuilder = tx.graql();
    Match matchQuery;
    GetQuery getQuery;
    matchQuery = queryBuilder.match(x.directIsa(thingy1));
    assertEquals("match $x isa! thingy1;", matchQuery.toString());
    matchQuery = queryBuilder.match(x.directIsa(y));
    assertEquals("match $x isa! $y;", matchQuery.toString());
    getQuery = queryBuilder.parse("match $x isa! thingy1; get;");
    assertEquals(queryBuilder.match(x.directIsa(thingy1)), getQuery.match());
    getQuery = queryBuilder.parse("match $x isa! $y; get;");
    assertEquals(queryBuilder.match(x.directIsa(y)), getQuery.match());
}
Also used : GetQuery(ai.grakn.graql.GetQuery) QueryBuilder(ai.grakn.graql.QueryBuilder) Match(ai.grakn.graql.Match) Test(org.junit.Test)

Example 45 with GetQuery

use of ai.grakn.graql.GetQuery in project grakn by graknlabs.

the class QueryParserTest method whenSearchingForImplicitType_EnsureQueryCanBeParsed.

@Test
public void whenSearchingForImplicitType_EnsureQueryCanBeParsed() {
    GetQuery expected = match(var("x").plays("@has-release-date-owner")).get();
    GetQuery parsed = parse("match $x plays @has-release-date-owner; get;");
    assertEquals(expected, parsed);
}
Also used : GetQuery(ai.grakn.graql.GetQuery) Test(org.junit.Test)

Aggregations

GetQuery (ai.grakn.graql.GetQuery)163 Test (org.junit.Test)161 Answer (ai.grakn.graql.admin.Answer)65 QueryBuilder (ai.grakn.graql.QueryBuilder)61 GraknTx (ai.grakn.GraknTx)51 EmbeddedGraknTx (ai.grakn.kb.internal.EmbeddedGraknTx)23 QueryAnswer (ai.grakn.graql.internal.query.QueryAnswer)14 SampleKBContext (ai.grakn.test.rule.SampleKBContext)12 Concept (ai.grakn.concept.Concept)9 List (java.util.List)8 Assert.assertEquals (org.junit.Assert.assertEquals)7 Assert.assertTrue (org.junit.Assert.assertTrue)7 Set (java.util.Set)6 Label (ai.grakn.concept.Label)5 RelationshipType (ai.grakn.concept.RelationshipType)5 VarPatternAdmin (ai.grakn.graql.admin.VarPatternAdmin)5 ReasonerAtomicQuery (ai.grakn.graql.internal.reasoner.query.ReasonerAtomicQuery)5 Sets (com.google.common.collect.Sets)5 Collectors (java.util.stream.Collectors)5 Collectors.toSet (java.util.stream.Collectors.toSet)5