Search in sources :

Example 21 with GetQuery

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

the class ReasonerTest method testReasoningWithQueryContainingLimit.

@Test
public void testReasoningWithQueryContainingLimit() {
    GraknTx graph = nonMaterialisedGeoKB.tx();
    String limitQueryString = "match (geo-entity: $x, entity-location: $y)isa is-located-in;limit 5; get;";
    String queryString = "match (geo-entity: $x, entity-location: $y)isa is-located-in; get;";
    QueryBuilder iqb = graph.graql().infer(true);
    GetQuery limitQuery = iqb.parse(limitQueryString);
    GetQuery query = iqb.parse(queryString);
    List<Answer> limitedAnswers = limitQuery.execute();
    List<Answer> answers = query.execute();
    assertEquals(limitedAnswers.size(), 5);
    assertTrue(answers.size() > limitedAnswers.size());
    assertTrue(answers.containsAll(limitedAnswers));
}
Also used : GraknTx(ai.grakn.GraknTx) EmbeddedGraknTx(ai.grakn.kb.internal.EmbeddedGraknTx) Answer(ai.grakn.graql.admin.Answer) GetQuery(ai.grakn.graql.GetQuery) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 22 with GetQuery

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

the class ReasonerTest method testParsingQueryContainingDataType.

@Test
public void testParsingQueryContainingDataType() {
    String queryString = " match $x sub " + Schema.MetaSchema.ATTRIBUTE.getLabel().getValue() + ", datatype string; get;";
    GetQuery query = snbKB.tx().graql().infer(true).parse(queryString);
    GetQuery query2 = snbKB.tx().graql().infer(false).parse(queryString);
    assertQueriesEqual(query, query2);
}
Also used : GetQuery(ai.grakn.graql.GetQuery) Test(org.junit.Test)

Example 23 with GetQuery

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

the class ReasonerTest method testParsingQueryContainingTypeRegex.

@Test
public void testParsingQueryContainingTypeRegex() {
    String queryString = " match $x sub " + Schema.MetaSchema.ATTRIBUTE.getLabel().getValue() + ", regex /name/; get;";
    GetQuery query = snbKB.tx().graql().infer(true).parse(queryString);
    GetQuery query2 = snbKB.tx().graql().infer(false).parse(queryString);
    assertQueriesEqual(query, query2);
}
Also used : GetQuery(ai.grakn.graql.GetQuery) Test(org.junit.Test)

Example 24 with GetQuery

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

the class ReasonerTest method testReasoningWithQueryContainingResourceComparison.

@Test
public void testReasoningWithQueryContainingResourceComparison() {
    // recommendations of products for people older than Denis - Frank, Karl and Gary
    String queryString = "match " + "$b has name 'Denis', has age $x;" + "$p has name $name, has age $y; $y val > $x;" + "$pr isa product;($p, $pr) isa recommendation;" + "get $p, $y, $pr, $name;";
    String explicitQuery = "match $p isa person, has age $y, has name $name;$pr isa product, has name $yName;" + "{$name val 'Frank';$yName val 'Nocturnes';} or" + "{$name val 'Karl Fischer';{$yName val 'Faust';} or {$yName val 'Nocturnes';};} or " + "{$name val 'Gary';$yName val 'The Wall';};get $p, $pr, $y, $name;";
    GetQuery query = snbKB.tx().graql().infer(true).parse(queryString);
    GetQuery query2 = snbKB.tx().graql().infer(false).parse(explicitQuery);
    assertQueriesEqual(query, query2);
}
Also used : GetQuery(ai.grakn.graql.GetQuery) Test(org.junit.Test)

Example 25 with GetQuery

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

the class ReasonerTest method testReasoningWithQueryWithNoRelationTypeWithRoles2.

@Test
public void testReasoningWithQueryWithNoRelationTypeWithRoles2() {
    GraknTx graph = nonMaterialisedGeoKB.tx();
    String queryString = "match $x isa city;$y isa country;(geo-entity: $x, $y); get;";
    String queryString2 = "match $x isa city;$y isa country;" + "(geo-entity: $x, entity-location: $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)

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