use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class GeoInferenceTest method testTransitiveQuery_withSpecificResource_noRoles.
@Test
public void testTransitiveQuery_withSpecificResource_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 has name 'Masovia'; 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 has name 'Masovia'; 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 ReasoningTests method reasoningWithLimitHigherThanNumberOfResults_ReturnsConsistentResults.
// Expected result: The same set of results is always returned
@Test
public void reasoningWithLimitHigherThanNumberOfResults_ReturnsConsistentResults() {
QueryBuilder qb = testSet23.tx().graql().infer(true);
String queryString = "match (friend1:$x1, friend2:$x2) isa knows-trans;limit 60; get;";
List<Answer> oldAnswers = qb.<GetQuery>parse(queryString).execute();
for (int i = 0; i < 5; i++) {
List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
assertEquals(answers.size(), 6);
assertTrue(answers.containsAll(oldAnswers));
assertTrue(oldAnswers.containsAll(answers));
}
}
use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class ReasoningTests method reasoningWithReifiedRelations.
// tests if partial substitutions are propagated correctly - atom disjointness may lead to variable loss (bug #15476)
// Expected result: 2 relations obtained by correctly finding reified relations
@Test
public void reasoningWithReifiedRelations() {
QueryBuilder qb = testSet26.tx().graql().infer(true);
String queryString = "match (role1: $x1, role2: $x2) isa relation2; get;";
List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
assertEquals(answers.size(), 2);
String queryString2 = "match " + "$b isa entity2;" + "$b has res1 'value';" + "$rel1 has res2 'value1';" + "$rel1 (role1: $p, role2: $b) isa relation1;" + "$rel2 has res2 'value2';" + "$rel2 (role1: $c, role2: $b) isa relation1; get;";
List<Answer> answers2 = qb.<GetQuery>parse(queryString2).execute();
assertEquals(answers2.size(), 2);
Set<Var> vars = Sets.newHashSet(var("b"), var("p"), var("c"), var("rel1"), var("rel2"));
answers2.forEach(ans -> assertTrue(ans.vars().containsAll(vars)));
}
use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class ReasoningTests method duplicatesNotProducedWhenResolvingNonResolvableConjunctionsWithoutType.
// Expected result: number of answers equal to specified limit (no duplicates produced)
@Test
public void duplicatesNotProducedWhenResolvingNonResolvableConjunctionsWithoutType() {
QueryBuilder qb = testSet28.tx().graql().infer(true);
String queryString = "match " + "(role1: $x, role2: $y);" + "(role1: $y, role2: $z);" + "(role3: $z, role4: $w) isa relation3;" + "limit 3; get;";
assertEquals(qb.<GetQuery>parse(queryString).execute().size(), 3);
}
use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class ReasoningTests method instanceTypeHierarchyRespected_queryOverwritesTypes_recursiveRule.
// Expected result: Single answer obtained only if the rule query containing super type is correctly executed.
@Test
public void instanceTypeHierarchyRespected_queryOverwritesTypes_recursiveRule() {
QueryBuilder qb = testSet19recursive.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