use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class ReasoningTests method reasoningWithNeqProperty.
// Expected result: 2 relations obtained by correctly finding reified relations
@Test
public void reasoningWithNeqProperty() {
QueryBuilder qb = testSet27.tx().graql().infer(true);
String queryString = "match (related-state: $s) isa holds; get;";
List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
List<Answer> exact = qb.<GetQuery>parse("match $s isa state, has name 's2'; get;").execute();
assertTrue(answers.containsAll(exact));
assertTrue(exact.containsAll(answers));
}
use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class ReasoningTests method ternaryRelationsRequiryingDifferentMultiunifiers.
@Test
public void ternaryRelationsRequiryingDifferentMultiunifiers() {
QueryBuilder qb = testSet29.tx().graql().infer(true);
String queryString = "match " + "(role1: $a, role2: $b, role3: $c) isa ternary-base;" + "get;";
String queryString2 = "match " + "(role: $a, role2: $b, role: $c) isa ternary-base;" + "$b has name 'b';" + "get;";
String queryString3 = "match " + "($r: $a) isa ternary-base;" + "get;";
String queryString4 = "match " + "($r: $b) isa ternary-base;" + "$b has name 'b';" + "get;";
List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
assertEquals(answers.size(), 27);
List<Answer> answers2 = qb.<GetQuery>parse(queryString2).execute();
assertEquals(answers2.size(), 9);
List<Answer> answers3 = qb.<GetQuery>parse(queryString3).execute();
assertEquals(answers3.size(), 12);
List<Answer> answers4 = qb.<GetQuery>parse(queryString4).execute();
assertEquals(answers4.size(), 4);
}
use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class ReasoningTests method reasoningWithEntityTypes.
// Expected result: Relations between all entity instances including relation between each instance and itself
@Test
public void reasoningWithEntityTypes() {
QueryBuilder qb = testSet24.tx().graql().infer(true);
QueryBuilder qbm = testSet24.tx().graql().infer(true);
String queryString = "match (role1:$x1, role2:$x2) isa relation1; get;";
List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
List<Answer> answers2 = qbm.<GetQuery>parse(queryString).execute();
assertEquals(answers.size(), 9);
assertEquals(answers2.size(), 9);
assertTrue(answers.containsAll(answers2));
assertTrue(answers2.containsAll(answers));
}
use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class ReasoningTests method unificationWithVarDuplicates_SymmetricRelation.
// Expected result: Both queries should return a non-empty result, with $x/$y mapped to a unique entity.
@Test
public void unificationWithVarDuplicates_SymmetricRelation() {
QueryBuilder qb = testSet1b.tx().graql().infer(true);
String queryString = "match (symmetricRole: $x, symmetricRole: $x) isa relation1; get;";
String queryString2 = "match (symmetricRole: $x, symmetricRole: $y) isa relation1; get;";
List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
List<Answer> answers2 = qb.<GetQuery>parse(queryString2).execute();
assertEquals(2, answers.size());
assertEquals(8, answers2.size());
assertNotEquals(answers.size() * answers2.size(), 0);
answers.forEach(x -> assertEquals(x.size(), 1));
answers2.forEach(x -> assertEquals(x.size(), 2));
}
use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class ReasoningTests method instanceTypeHierarchyRespected_queryOverwritesTypes.
// Expected result: Single answer obtained only if the rule query containing super type is correctly executed.
@Test
public void instanceTypeHierarchyRespected_queryOverwritesTypes() {
QueryBuilder qb = testSet19.tx().graql().infer(true);
String queryString = "match " + "$x isa subEntity1;" + "$y isa entity1;" + "(role1: $x, role2: $y) isa relation1;";
String queryString2 = queryString + "$y has name 'a';";
List<Answer> answers = qb.<GetQuery>parse(queryString + "get;").execute();
assertEquals(answers.size(), 2);
List<Answer> answers2 = qb.<GetQuery>parse(queryString2 + "get;").execute();
assertEquals(answers2.size(), 2);
}
Aggregations