Search in sources :

Example 86 with QueryBuilder

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

the class QueryValidityTest method whenQueryingForMismatchedResourceTypeLabel_Throws.

@Test
public void whenQueryingForMismatchedResourceTypeLabel_Throws() throws GraqlQueryException {
    QueryBuilder qb = testContext.tx().graql().infer(true);
    String queryString = "match $x has binary $r; get;";
    expectedException.expect(GraqlQueryException.class);
    qb.<GetQuery>parse(queryString).execute();
}
Also used : QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 87 with QueryBuilder

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

the class QueryValidityTest method whenQueryingForInexistentRelationTypeLabelViaVariable_emptyResultReturned.

@Test
public void whenQueryingForInexistentRelationTypeLabelViaVariable_emptyResultReturned() {
    QueryBuilder qb = testContext.tx().graql().infer(true);
    String queryString = "match ($x, $y) isa $type; $type label jakas-relacja; get;";
    assertThat(qb.<GetQuery>parse(queryString).execute(), empty());
}
Also used : GetQuery(ai.grakn.graql.GetQuery) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 88 with QueryBuilder

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

the class RecursiveInferenceTest method testPathSymmetric.

@Test
public void testPathSymmetric() {
    final int N = 2;
    SampleKBContext kb = PathTreeSymmetricKB.context(N, 3);
    QueryBuilder qb = kb.tx().graql().infer(false);
    QueryBuilder iqb = kb.tx().graql().infer(true);
    String queryString = "match ($x, $y) isa path;$x has index 'a0'; get $y;";
    String explicitQuery = "match {$y isa vertex;} or {$y isa start-vertex;}; get;";
    assertQueriesEqual(iqb.materialise(false).parse(queryString), qb.parse(explicitQuery));
    assertQueriesEqual(iqb.materialise(true).parse(queryString), qb.parse(explicitQuery));
}
Also used : SampleKBContext(ai.grakn.test.rule.SampleKBContext) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 89 with QueryBuilder

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

the class RecursiveInferenceTest method testReachabilitySymmetric.

@Test
public void testReachabilitySymmetric() {
    QueryBuilder qb = reachabilitySymmetricContext.tx().graql().infer(false);
    QueryBuilder iqb = reachabilitySymmetricContext.tx().graql().infer(true);
    String queryString = "match ($x, $y) isa reachable;$x has index 'a';get $y;";
    String explicitQuery = "match $y has index $indY;" + "{$indY val 'a';} or {$indY val 'b';} or {$indY val 'c';} or {$indY val 'd';};get $y;";
    assertQueriesEqual(iqb.materialise(false).parse(queryString), qb.parse(explicitQuery));
    assertQueriesEqual(iqb.materialise(true).parse(queryString), qb.parse(explicitQuery));
}
Also used : QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 90 with QueryBuilder

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

the class RecursiveInferenceTest method testReverseSameGeneration.

/**
 *from Abiteboul - Foundations of databases p. 312/Cao test 6.14 p. 89
 */
@Test
public void testReverseSameGeneration() {
    QueryBuilder qb = recursivityRSGContext.tx().graql().infer(false);
    QueryBuilder iqb = recursivityRSGContext.tx().graql().infer(true);
    String queryString = "match (RSG-from: $x, RSG-to: $y) isa RevSG;$x has name 'a'; get $y;";
    String explicitQuery = "match $y isa person, has name $name;" + "{$name val 'b';} or {$name val 'c';} or {$name val 'd';};get $y;";
    assertQueriesEqual(iqb.materialise(false).parse(queryString), qb.parse(explicitQuery));
    assertQueriesEqual(iqb.materialise(true).parse(queryString), qb.parse(explicitQuery));
}
Also used : QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Aggregations

QueryBuilder (ai.grakn.graql.QueryBuilder)208 Test (org.junit.Test)202 Answer (ai.grakn.graql.admin.Answer)101 GetQuery (ai.grakn.graql.GetQuery)60 GraknTx (ai.grakn.GraknTx)51 SampleKBContext (ai.grakn.test.rule.SampleKBContext)20 EmbeddedGraknTx (ai.grakn.kb.internal.EmbeddedGraknTx)18 Concept (ai.grakn.concept.Concept)16 QueryAnswer (ai.grakn.graql.internal.query.QueryAnswer)9 Ignore (org.junit.Ignore)8 Var (ai.grakn.graql.Var)5 VarPattern (ai.grakn.graql.VarPattern)5 List (java.util.List)5 Label (ai.grakn.concept.Label)4 ReasonerAtomicQuery (ai.grakn.graql.internal.reasoner.query.ReasonerAtomicQuery)4 Sets (com.google.common.collect.Sets)4 Assert.assertEquals (org.junit.Assert.assertEquals)4 RelationshipType (ai.grakn.concept.RelationshipType)3 Graql (ai.grakn.graql.Graql)3 Graql.var (ai.grakn.graql.Graql.var)3