use of ai.grakn.graql.admin.Answer 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.admin.Answer 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.admin.Answer 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.admin.Answer 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.admin.Answer 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));
}
Aggregations