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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations