use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class GeoInferenceTest method testTransitiveQuery_withSpecificResource.
@Test
public void testTransitiveQuery_withSpecificResource() {
GraknTx graph = geoKB.tx();
QueryBuilder iqb = graph.graql().infer(true);
String queryString = "match " + "(geo-entity: $x, entity-location: $y) isa is-located-in;" + "$y has name 'Poland'; get;";
String queryString2 = "match " + "(geo-entity: $x, entity-location: $y) isa is-located-in;" + "$y has name 'Europe'; get;";
Concept poland = getConcept(graph, "name", "Poland");
Concept europe = getConcept(graph, "name", "Europe");
List<Answer> answers = iqb.materialise(false).<GetQuery>parse(queryString).execute();
answers.forEach(ans -> assertEquals(ans.size(), 2));
answers.forEach(ans -> assertEquals(ans.get(var("y")).getId().getValue(), poland.getId().getValue()));
assertEquals(answers.size(), 6);
List<Answer> answers2 = iqb.materialise(false).<GetQuery>parse(queryString2).execute();
answers2.forEach(ans -> assertEquals(ans.size(), 2));
answers2.forEach(ans -> assertEquals(ans.get(var("y")).getId().getValue(), europe.getId().getValue()));
assertEquals(answers2.size(), 21);
}
use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class GeoInferenceTest method testTransitiveQuery_withSubstitution_noRoles.
@Test
public void testTransitiveQuery_withSubstitution_noRoles() {
GraknTx graph = geoKB.tx();
QueryBuilder iqb = graph.graql().infer(true);
Concept masovia = getConcept(graph, "name", "Masovia");
String queryString = "match " + "($x, $y) isa is-located-in;" + "$y id '" + masovia.getId().getValue() + "'; get;";
String queryString2 = "match " + "{(geo-entity: $x, entity-location: $y) isa is-located-in or " + "(geo-entity: $y, entity-location: $x) isa is-located-in;};" + "$y id '" + masovia.getId().getValue() + "'; get;";
List<Answer> answers = iqb.materialise(false).<GetQuery>parse(queryString).execute();
answers.forEach(ans -> assertEquals(ans.size(), 2));
answers.forEach(ans -> assertEquals(ans.get(var("y")).getId().getValue(), masovia.getId().getValue()));
assertEquals(answers.size(), 5);
List<Answer> answers2 = iqb.materialise(false).<GetQuery>parse(queryString2).execute();
assertCollectionsEqual(answers, answers2);
}
use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class GeoInferenceTest method testTransitiveQuery_Closure.
@Test
public void testTransitiveQuery_Closure() {
QueryBuilder iqb = geoKB.tx().graql().infer(true);
String queryString = "match (geo-entity: $x, entity-location: $y) isa is-located-in; get;";
List<Answer> answers = iqb.materialise(false).<GetQuery>parse(queryString).execute();
assertEquals(answers.size(), 51);
List<Answer> answers2 = iqb.materialise(true).<GetQuery>parse(queryString).execute();
assertCollectionsEqual(answers, answers2);
}
use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class SNBInferenceTest method testBook.
@Test
public void testBook() {
QueryBuilder qb = snbGraph.tx().graql().infer(false);
QueryBuilder iqb = snbGraph.tx().graql().infer(true);
String queryString = "match $x isa person;" + "($x, $y) isa recommendation;" + "$c isa category;$c has name 'book';" + "($y, $c) isa typing;" + "get $x, $y;";
String explicitQuery = "match $x isa person, has name $nx;$y isa product, has name $ny;" + "{$nx val 'Alice';$ny val 'War of the Worlds';} or" + "{$nx val 'Karl Fischer';$ny val 'Faust';} or " + "{$nx val 'Denis';{$ny val 'Colour of Magic';} or {$ny val 'Dorian Gray';};};get $x, $y;";
assertQueriesEqual(iqb.materialise(false).parse(queryString), qb.parse(explicitQuery));
assertQueriesEqual(iqb.materialise(true).parse(queryString), qb.parse(explicitQuery));
}
use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class SNBInferenceTest method testTransitivity.
/**
* Tests transitivity
*/
@Test
public void testTransitivity() {
QueryBuilder qb = snbGraph.tx().graql().infer(false);
QueryBuilder iqb = snbGraph.tx().graql().infer(true);
String queryString = "match " + "$x isa university;$y isa country;(located-subject: $x, subject-location: $y) isa resides; get;";
String explicitQuery = "match $x isa university, has name 'University of Cambridge';" + "$y isa country, has name 'UK'; get;";
assertQueriesEqual(iqb.materialise(false).parse(queryString), qb.parse(explicitQuery));
assertQueriesEqual(iqb.materialise(true).parse(queryString), qb.parse(explicitQuery));
}
Aggregations