Search in sources :

Example 26 with GetQuery

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

the class ReasonerTest method testReasoningWithQueryWithNoRelationTypeWithRoles.

@Test
public void testReasoningWithQueryWithNoRelationTypeWithRoles() {
    GraknTx graph = nonMaterialisedGeoKB.tx();
    String queryString = "match $x isa city;$y isa country;(geo-entity: $x, $y);$y has name 'Poland'; get;";
    String queryString2 = "match $x isa city;$y isa country;" + "(geo-entity: $x, entity-location: $y) isa is-located-in;$y has name 'Poland'; 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 27 with GetQuery

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

the class ReasonerTest method testReasoningWithQueryContainingPlays2.

@Test
public void testReasoningWithQueryContainingPlays2() {
    String queryString = "match $x isa person;$y isa $type;$type plays recommended-product;($x, $y) isa recommendation; get;";
    String queryString2 = "match $x isa person;$y isa $type;{$type label 'product';} or {$type label 'tag';};($x, $y) isa recommendation; 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 28 with GetQuery

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

the class ReasonerTest method testReasoningWithQueryContainingRelationTypeVar.

@Test
public void testReasoningWithQueryContainingRelationTypeVar() {
    GraknTx graph = nonMaterialisedGeoKB.tx();
    String queryString = "match (geo-entity: $x) isa $type;$type label 'is-located-in'; get $x;";
    String queryString2 = "match (geo-entity: $x, entity-location: $y)isa is-located-in; get $x;";
    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 29 with GetQuery

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

the class MatchBenchmark method match.

@Benchmark
public void match() {
    Match match = graph.graql().match(var("x").isa(BENCHMARK_ENTITY_TYPE).has(BENCHMARK_ATTRIBUTE_TYPE, "0"));
    GetQuery answers = match.get();
    Optional<Answer> first = answers.stream().findFirst();
    first.get();
}
Also used : Answer(ai.grakn.graql.admin.Answer) GetQuery(ai.grakn.graql.GetQuery) Match(ai.grakn.graql.Match) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 30 with GetQuery

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

the class PhilosophersExampleIT method testAlexanderIsTheOnlyPharaoh.

@Test
public void testAlexanderIsTheOnlyPharaoh() {
    GetQuery pharaoh = qb.parse("match has name $x, has title contains 'Pharaoh'; get;");
    assertEquals("Alexander", pharaoh.iterator().next().get("x").asAttribute().getValue());
}
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