Search in sources :

Example 6 with GetQuery

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

the class ReasonerTest method testReasoningWithQueryContainingTypeVar2.

@Test
public void testReasoningWithQueryContainingTypeVar2() {
    String thing = Schema.MetaSchema.THING.getLabel().getValue();
    GraknTx graph = nonMaterialisedGeoKB.tx();
    String queryString = "match $x isa $type;" + "(geo-entity: $x, entity-location: $y) isa is-located-in; $y isa country;$y has name 'Poland'; get;";
    String explicitQuery = "match $y has name 'Poland';$x isa $type;$x has " + Schema.MetaSchema.ATTRIBUTE.getLabel().getValue() + " $name;" + "{" + "{$name val 'Warsaw-Polytechnics' or $name val 'University-of-Warsaw';};" + "{$type label 'university' or $type label 'entity' or $type label '" + thing + "';};" + "} or {" + "{$name val 'Warsaw' or $name val 'Wroclaw';};" + "{$type label 'city' or $type label 'geoObject' or $type label 'entity' or $type label '" + thing + "';};" + "} or {" + "{$name val 'Masovia' or $name val 'Silesia';};" + "{$type label 'region' or $type label 'geoObject' or $type label 'entity' or $type label '" + thing + "';};" + "}; get $x, $y, $type;";
    GetQuery query = graph.graql().infer(true).parse(queryString);
    GetQuery query2 = graph.graql().infer(false).parse(explicitQuery);
    assertQueriesEqual(query, query2);
}
Also used : GraknTx(ai.grakn.GraknTx) EmbeddedGraknTx(ai.grakn.kb.internal.EmbeddedGraknTx) GetQuery(ai.grakn.graql.GetQuery) Test(org.junit.Test)

Example 7 with GetQuery

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

the class ReasonerTest method testReasoningWithQueryContainingSub.

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

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

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

the class ReasonerTest method testParsingQueryContainingIsAbstract.

@Test
public void testParsingQueryContainingIsAbstract() {
    String queryString = "match $x is-abstract; 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 10 with GetQuery

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

the class ReasonerTest method testReasoningWithQueryContainingRelationVariableWithMaterialisation_requeryingDoesntCreateDuplicates.

@Test
public void testReasoningWithQueryContainingRelationVariableWithMaterialisation_requeryingDoesntCreateDuplicates() {
    String queryString = "match $x isa is-located-in; get;";
    String queryString2 = "match $x (geo-entity: $x1, entity-location: $x2) isa is-located-in; get $x;";
    String queryString3 = "match $x ($x1, $x2) isa is-located-in; get $x;";
    GetQuery query = geoKB.tx().graql().infer(true).parse(queryString);
    GetQuery query2 = geoKB2.tx().graql().infer(true).parse(queryString2);
    GetQuery query3 = geoKB3.tx().graql().infer(true).parse(queryString3);
    assertQueriesEqual(query, query2);
    assertQueriesEqual(query2, query3);
    List<Answer> requeriedAnswers = query.execute();
    List<Answer> requeriedAnswers2 = query2.execute();
    List<Answer> requeriedAnswers3 = query3.execute();
    assertCollectionsEqual(requeriedAnswers, requeriedAnswers2);
    assertCollectionsEqual(requeriedAnswers2, requeriedAnswers3);
}
Also used : Answer(ai.grakn.graql.admin.Answer) 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