Search in sources :

Example 11 with GetQuery

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

the class ReasonerTest method testReasoningWithQueryContainingTypeVar.

@Test
public void testReasoningWithQueryContainingTypeVar() {
    String queryString = "match $x isa person;$y isa $type;($x, $y) isa recommendation; get;";
    String explicitQuery = "match $y isa $type;" + "{$x has name 'Alice';$y has name 'War of the Worlds';} or" + "{$x has name 'Bob';" + "{$y has name 'Ducatti 1299';} or " + "{$y has name 'The Good the Bad the Ugly';};} or" + "{$x has name 'Charlie';" + "{$y has name 'Blizzard of Ozz';} or " + "{$y has name 'Stratocaster';};} or " + "{$x has name 'Denis';" + "{$y has name 'Colour of Magic';} or " + "{$y has name 'Dorian Gray';};} or" + "{$x has name 'Frank';$y has name 'Nocturnes';} or" + "{$x has name 'Karl Fischer';" + "{$y has name 'Faust';} or " + "{$y has name 'Nocturnes';};} or " + "{$x has name 'Gary';$y has name 'The Wall';} or" + "{$x has name 'Charlie';" + "{$y has name 'Yngwie Malmsteen';} or " + "{$y has name 'Cacophony';} or " + "{$y has name 'Steve Vai';} or " + "{$y has name 'Black Sabbath';};} or " + "{$x has name 'Gary';$y has name 'Pink Floyd';}; get;";
    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 12 with GetQuery

use of ai.grakn.graql.GetQuery 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 13 with GetQuery

use of ai.grakn.graql.GetQuery 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 14 with GetQuery

use of ai.grakn.graql.GetQuery 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)

Example 15 with GetQuery

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

the class OntologicalQueryTest method allInstancesOfTypesThatAreSubTypeOfGivenType_needInferenceToGetAllResults.

@Test
public void allInstancesOfTypesThatAreSubTypeOfGivenType_needInferenceToGetAllResults() {
    GraknTx tx = testContext.tx();
    QueryBuilder qb = tx.graql().infer(true);
    String queryString = "match $x isa $type; $type sub relationship; get;";
    List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
    assertEquals(answers.size(), tx.getRelationshipType("relationship").subs().flatMap(RelationshipType::instances).count());
    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) RelationshipType(ai.grakn.concept.RelationshipType) 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