Search in sources :

Example 6 with QueryBuilder

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

the class ReasonerTest method testParsingQueryWithComma.

@Test
public void testParsingQueryWithComma() {
    String queryString = "match $x isa person, has firstname 'Bob', has name 'Bob', val 'Bob', has age <21; get;";
    String queryString2 = "match $x isa person; $x has firstname 'Bob';$x has name 'Bob';$x val 'Bob';$x has age <21; get;";
    QueryBuilder iqb = snbKB.tx().graql().infer(true);
    GetQuery query = iqb.parse(queryString);
    GetQuery query2 = iqb.parse(queryString2);
    assertQueriesEqual(query, query2);
}
Also used : GetQuery(ai.grakn.graql.GetQuery) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 7 with QueryBuilder

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

the class ReasonerTest method testReasoningWithQueryContainingTautology.

@Test
public void testReasoningWithQueryContainingTautology() {
    GraknTx graph = nonMaterialisedGeoKB.tx();
    String queryString = "match ($x, $y) isa is-located-in;city sub geoObject; get;";
    String queryString2 = "match ($x, $y) isa is-located-in; get;";
    QueryBuilder iqb = graph.graql().infer(true);
    GetQuery query = iqb.parse(queryString);
    GetQuery query2 = iqb.parse(queryString2);
    assertQueriesEqual(query, query2);
}
Also used : GraknTx(ai.grakn.GraknTx) EmbeddedGraknTx(ai.grakn.kb.internal.EmbeddedGraknTx) GetQuery(ai.grakn.graql.GetQuery) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 8 with QueryBuilder

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

the class ReasonerTest method testReasoningWithQueryContainingTypeHas.

@Test
public void testReasoningWithQueryContainingTypeHas() {
    GraknTx graph = nonMaterialisedGeoKB.tx();
    String queryString = "match $x isa $type;$type has name;$y isa country;$y has name 'Poland';" + "($x, $y) isa is-located-in;get $x, $y;";
    String queryString2 = "match $y isa country;$y has name 'Poland';" + "($x, $y) isa is-located-in; get;";
    QueryBuilder iqb = graph.graql().infer(true);
    GetQuery query = iqb.parse(queryString);
    GetQuery query2 = iqb.parse(queryString2);
    assertQueriesEqual(query, query2);
}
Also used : GraknTx(ai.grakn.GraknTx) EmbeddedGraknTx(ai.grakn.kb.internal.EmbeddedGraknTx) GetQuery(ai.grakn.graql.GetQuery) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 9 with QueryBuilder

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

the class ReasonerTest method testReasoningWithQueryContainingContradiction.

@Test
public void testReasoningWithQueryContainingContradiction() {
    GraknTx graph = nonMaterialisedGeoKB.tx();
    // geoObject sub city always returns an empty set
    String queryString = "match ($x, $y) isa is-located-in;geoObject sub city; get;";
    QueryBuilder iqb = graph.graql().infer(true);
    List<Answer> answers = iqb.<GetQuery>parse(queryString).execute();
    assertThat(answers, empty());
}
Also used : GraknTx(ai.grakn.GraknTx) EmbeddedGraknTx(ai.grakn.kb.internal.EmbeddedGraknTx) Answer(ai.grakn.graql.admin.Answer) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 10 with QueryBuilder

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

the class OntologicalQueryTest method allInstancesOfTypesThatCanHaveAGivenResourceType.

/**
 * HasAtom *
 */
@Test
public void allInstancesOfTypesThatCanHaveAGivenResourceType() {
    GraknTx tx = testContext.tx();
    QueryBuilder qb = tx.graql().infer(true);
    String queryString = "match $x isa $type; $type has name; get;";
    List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
    // 1 x noRoleEntity + 3 x 3 (hierarchy) anotherTwoRoleEntities
    assertEquals(answers.size(), 10);
    assertCollectionsEqual(answers, qb.infer(false).<GetQuery>parse(queryString).execute());
}
Also used : GraknTx(ai.grakn.GraknTx) Answer(ai.grakn.graql.admin.Answer) GetQuery(ai.grakn.graql.GetQuery) 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