use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class ReasoningTests method reusingResources_queryingForGenericRelation.
// Expected result: When the head of a rule contains resource assertions, the respective unique resources should be generated or reused.
@Test
public void reusingResources_queryingForGenericRelation() {
QueryBuilder qb = testSet14.tx().graql().infer(true);
String queryString = "match $x isa entity1;($x, $y); get;";
List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
assertEquals(answers.size(), 3);
assertEquals(answers.stream().filter(answer -> answer.get("y").isAttribute()).count(), 2);
}
use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class ReasoningTests method reusingResources_usingExistingResourceToDefineResource.
// Expected result: When the head of a rule contains resource assertions, the respective unique resources should be generated or reused.
@Test
public void reusingResources_usingExistingResourceToDefineResource() {
QueryBuilder qb = testSet14.tx().graql().infer(true);
String queryString = "match $x isa entity1, has resource $y; get;";
List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
String queryString2 = "match $x isa resource; get;";
List<Answer> answers2 = qb.<GetQuery>parse(queryString2).execute();
assertEquals(answers.size(), 2);
assertEquals(answers2.size(), 1);
}
use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class ReasoningTests method reasoningOverRelationHierarchy.
// Expected result: Both queries should return a single equal match as they trigger the same rule.
@Test
public void reasoningOverRelationHierarchy() {
QueryBuilder qb = testSet20.tx().graql().infer(true);
String queryString = "match (role1: $x, role2: $y) isa relation1; get;";
String queryString2 = "match (role1: $x, role2: $y) isa sub-relation1; get;";
List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
List<Answer> answers2 = qb.<GetQuery>parse(queryString2).execute();
assertEquals(answers.size(), 1);
assertTrue(answers.containsAll(answers2));
assertTrue(answers2.containsAll(answers));
}
use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class ReasoningTests method relationTypesAreCorrectlyInferredInConjunction_TypesAreAbsent.
@Test
public void relationTypesAreCorrectlyInferredInConjunction_TypesAreAbsent() {
QueryBuilder qb = testSet28b.tx().graql().infer(true);
String queryString = "match " + "$a isa entity1;" + "($a, $b); $b isa entity3;" + "($b, $c);" + "get;";
List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
assertEquals(answers.size(), 4);
answers.forEach(ans -> assertEquals(ans.size(), 3));
}
use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class SNBInferenceTest method testBand.
@Test
public void testBand() {
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 'Band';" + "($y, $c) isa grouping;" + "get $x, $y;";
String explicitQuery = "match " + "{$x has name 'Charlie';{$y has name 'Cacophony';} or {$y has name 'Black Sabbath';};} or " + "{$x has name 'Gary';$y has name 'Pink Floyd';}; get $x, $y;";
assertQueriesEqual(iqb.materialise(false).parse(queryString), qb.parse(explicitQuery));
assertQueriesEqual(iqb.materialise(true).parse(queryString), qb.parse(explicitQuery));
}
Aggregations