use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class ReasoningTests method recursiveRelationsWithSharedNeqPredicate_relationsAreEquivalent.
/**
* Tests a scenario in which the neq predicate binds free variables of two recursive equivalent relations.
* Corresponds to the following pattern:
*
* x
* / \
* / \
* v v
* y != z
*/
@Test
public void recursiveRelationsWithSharedNeqPredicate_relationsAreEquivalent() {
QueryBuilder qb = testSet29.tx().graql().infer(true);
String baseQueryString = "match " + "(role1: $x, role2: $y) isa binary-base;" + "(role1: $x, role2: $z) isa binary-base;" + "$y != $z;";
List<Answer> baseAnswers = qb.<GetQuery>parse(baseQueryString + "get;").execute();
assertEquals(baseAnswers.size(), 18);
baseAnswers.forEach(ans -> {
assertEquals(ans.size(), 3);
assertNotEquals(ans.get("y"), ans.get("z"));
});
String queryString = baseQueryString + "$x has name 'a';";
String explicitString = "match " + "$x has name 'a';" + "{$y has name 'a';$z has name 'b';} or " + "{$y has name 'a';$z has name 'c';} or " + "{$y has name 'b';$z has name 'a';} or" + "{$y has name 'b';$z has name 'c';} or " + "{$y has name 'c';$z has name 'a';} or " + "{$y has name 'c';$z has name 'b';};";
List<Answer> answers = qb.<GetQuery>parse(queryString + "get;").execute();
List<Answer> answers2 = qb.infer(false).<GetQuery>parse(explicitString + "get;").execute();
assertTrue(baseAnswers.containsAll(answers));
assertTrue(answers.containsAll(answers2));
assertTrue(answers2.containsAll(answers));
}
use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class GeoInferenceTest method testTransitiveQuery_withSubstitution.
@Test
public void testTransitiveQuery_withSubstitution() {
GraknTx graph = geoKB.tx();
QueryBuilder iqb = graph.graql().infer(true);
Concept poland = getConcept(graph, "name", "Poland");
Concept europe = getConcept(graph, "name", "Europe");
String queryString = "match " + "(geo-entity: $x, entity-location: $y) isa is-located-in;" + "$y id '" + poland.getId().getValue() + "'; get;";
String queryString2 = "match " + "(geo-entity: $x, entity-location: $y) isa is-located-in;" + "$y id '" + europe.getId().getValue() + "'; 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(), poland.getId().getValue()));
assertEquals(answers.size(), 6);
List<Answer> answers2 = iqb.materialise(false).<GetQuery>parse(queryString2).execute();
answers2.forEach(ans -> assertEquals(ans.size(), 2));
answers2.forEach(ans -> assertEquals(ans.get(var("y")).getId().getValue(), europe.getId().getValue()));
assertEquals(answers2.size(), 21);
}
use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class GeoInferenceTest method testLazy.
@Test
public void testLazy() {
QueryBuilder iqb = geoKB.tx().graql().infer(true);
String queryString = "match (geo-entity: $x, entity-location: $y) isa is-located-in; limit 1; get;";
String queryString2 = "match (geo-entity: $x, entity-location: $y) isa is-located-in; limit 22; get;";
String queryString3 = "match (geo-entity: $x, entity-location: $y) isa is-located-in; get;";
List<Answer> answers = iqb.materialise(false).<GetQuery>parse(queryString).execute();
List<Answer> answers2 = iqb.materialise(false).<GetQuery>parse(queryString2).execute();
List<Answer> answers3 = iqb.materialise(false).<GetQuery>parse(queryString3).execute();
assertTrue(answers3.containsAll(answers));
assertTrue(answers3.containsAll(answers2));
}
use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class GeoInferenceTest method testTransitiveQuery_Closure_variableRoles.
@Test
public void testTransitiveQuery_Closure_variableRoles() {
QueryBuilder iqb = geoKB.tx().graql().infer(true);
String queryString = "match ($r1: $x, $r2: $y) isa is-located-in; get;";
List<Answer> answers = iqb.materialise(false).<GetQuery>parse(queryString).execute();
answers.forEach(ans -> assertEquals(ans.size(), 4));
assertEquals(answers.size(), 408);
List<Answer> answers2 = iqb.materialise(true).<GetQuery>parse(queryString).execute();
answers2.forEach(ans -> assertEquals(ans.size(), 4));
assertCollectionsEqual(answers, answers2);
}
use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class GeoInferenceTest method testTransitiveQuery_variableRoles_withSubstitution_withRelationVar.
@Test
public void testTransitiveQuery_variableRoles_withSubstitution_withRelationVar() {
GraknTx graph = geoKB.tx();
QueryBuilder iqb = geoKB.tx().graql().infer(true);
Concept masovia = getConcept(graph, "name", "Masovia");
String queryString = "match " + "$x ($r1: $x1, $r2: $x2) isa is-located-in;" + "$x2 id '" + masovia.getId().getValue() + "'; get;";
List<Answer> answers = iqb.materialise(false).<GetQuery>parse(queryString).execute();
assertEquals(answers.size(), 20);
answers.forEach(ans -> assertEquals(ans.size(), 5));
List<Answer> answers2 = iqb.materialise(true).<GetQuery>parse(queryString).execute();
answers2.forEach(ans -> assertEquals(ans.size(), 5));
assertCollectionsEqual(answers, answers2);
}
Aggregations