use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class SNBInferenceTest method testOrdering.
/**
* Tests Bug #7416
* the $t variable in the query matches with $t from rules so if the rule var is not changed an extra condition is created
* which renders the query unsatisfiable
*/
@Test
public void testOrdering() {
QueryBuilder qb = snbGraph.tx().graql().infer(false);
QueryBuilder iqb = snbGraph.tx().graql().infer(true);
// select recommendationS of Karl Fischer and their types
String queryString = "match $p isa product;$x isa person;$x has name 'Karl Fischer';" + "($x, $p) isa recommendation; ($p, $t) isa typing; get $p, $t;";
String explicitQuery = "match $p isa product;" + "$x isa person;$x has name 'Karl Fischer';{($x, $p) isa recommendation;} or" + "{$x isa person;$tt isa tag;$tt has name 'Johann Wolfgang von Goethe';" + "($x, $tt) isa tagging;$p isa product;$p has name 'Faust';} or" + "{$x isa person; $p isa product;$p has name 'Nocturnes'; $tt isa tag; ($tt, $x), isa tagging;};" + "($p, $t) isa typing; get $p, $t;";
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 testRecommendation.
@Test
public void testRecommendation() {
QueryBuilder qb = snbGraph.tx().graql().infer(false);
QueryBuilder iqb = snbGraph.tx().graql().infer(true);
String queryString = "match $x isa person;($x, $y) isa recommendation; get;";
String limitedQueryString = "match $x isa person;($x, $y) isa recommendation; limit 1; get;";
GetQuery query = iqb.parse(queryString);
GetQuery limitedQuery = iqb.parse(limitedQueryString);
String explicitQuery = "match $x isa person;" + "{$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;";
long startTime = System.nanoTime();
List<Answer> limitedAnswers = limitedQuery.execute();
System.out.println("limited time: " + (System.nanoTime() - startTime) / 1e6);
startTime = System.nanoTime();
List<Answer> answers = query.execute();
System.out.println("full time: " + (System.nanoTime() - startTime) / 1e6);
assertCollectionsEqual(answers, qb.<GetQuery>parse(explicitQuery).execute());
assertTrue(answers.containsAll(limitedAnswers));
}
use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class SNBInferenceTest method testProduct.
/**
* Tests relation filtering and rel vars matching
*/
@Test
public void testProduct() {
QueryBuilder qb = snbGraph.tx().graql().infer(false);
QueryBuilder iqb = snbGraph.tx().graql().infer(true);
String queryString = "match " + "$y isa person;$yy isa product;($y, $yy) isa recommendation; get;";
String explicitQuery = "match $y isa person, has name $ny; $yy isa product, has name $nyy;" + "{$ny val 'Alice';$nyy val 'War of the Worlds';} or" + "{$ny val 'Bob';{$nyy val 'Ducatti 1299';} or {$nyy val 'The Good the Bad the Ugly';};} or" + "{$ny val 'Charlie';{$nyy val 'Blizzard of Ozz';} or {$nyy val 'Stratocaster';};} or " + "{$ny val 'Denis';{$nyy val 'Colour of Magic';} or {$nyy val 'Dorian Gray';};} or" + "{$ny val 'Frank';$nyy val 'Nocturnes';} or" + "{$ny val 'Karl Fischer';{$nyy val 'Faust';} or {$nyy val 'Nocturnes';};} or " + "{$ny val 'Gary';$nyy val 'The Wall';};get $y, $yy;";
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 testInverseVars.
/**
* Tests Bug #7422
*/
@Test
public void testInverseVars() {
QueryBuilder qb = snbGraph.tx().graql().infer(false);
QueryBuilder iqb = snbGraph.tx().graql().infer(true);
// select recommendation of Karl Fischer and their types
String queryString = "match $p isa product;" + "$x isa person;$x has name 'Karl Fischer'; ($p, $x) isa recommendation; ($p, $t) isa typing; get $p, $t;";
String explicitQuery = "match $p isa product;" + "$x isa person;$x has name 'Karl Fischer';{($x, $p) isa recommendation;} or" + "{$x isa person; $p isa product;$p has name 'Nocturnes'; $tt isa tag; ($tt, $x), isa tagging;} or" + "{$x isa person;$tt isa tag;$tt has name 'Johann Wolfgang von Goethe';($x, $tt) isa tagging;" + "$p isa product;$p has name 'Faust';};" + "($p, $t) isa typing; get $p, $t;";
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 testTransitivity2Prime.
@Test
public void testTransitivity2Prime() {
QueryBuilder qb = snbGraph.tx().graql().infer(false);
QueryBuilder iqb = snbGraph.tx().graql().infer(true);
String queryString = "match $x isa company;$y isa country;" + "($x, $y) isa resides; get;";
String explicitQuery = "match " + "$x isa company, has name 'Grakn';" + "$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