use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class TypeInferenceQueryTest method typeInferenceQueries.
private void typeInferenceQueries(List<RelationshipType> possibleTypes, String pattern, EmbeddedGraknTx<?> graph) {
QueryBuilder qb = graph.graql();
List<Answer> typedAnswers = typedAnswers(possibleTypes, pattern, graph);
List<Answer> unTypedAnswers = qb.match(qb.parser().parsePattern(pattern)).get().execute();
assertEquals(typedAnswers.size(), unTypedAnswers.size());
GraqlTestUtil.assertCollectionsEqual(typedAnswers, unTypedAnswers);
}
use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class CWInferenceTest method testTransactionQuery.
@Test
public void testTransactionQuery() {
QueryBuilder qb = cwKB2.tx().graql().infer(false);
String queryString = "match ($t1, $t2, $t3) isa transaction; get;";
String explicitQuery = "match " + "{$t1 has name 'colonelWest';$t2 has name 'Tomahawk';$t3 has name 'Nono';} or " + "{$t1 has name 'colonelWest';$t3 has name 'Tomahawk';$t2 has name 'Nono';} or " + "{$t2 has name 'colonelWest';$t1 has name 'Tomahawk';$t3 has name 'Nono';} or " + "{$t2 has name 'colonelWest';$t3 has name 'Tomahawk';$t1 has name 'Nono';} or " + "{$t3 has name 'colonelWest';$t2 has name 'Tomahawk';$t1 has name 'Nono';} or " + "{$t3 has name 'colonelWest';$t1 has name 'Tomahawk';$t2 has name 'Nono';};" + "get;";
assertQueriesEqual(iqb.parse(queryString), qb.parse(explicitQuery));
}
use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class GeoInferenceTest method testRelationVarQuery_Closure_withAndWithoutRelationPlayers.
@Test
public void testRelationVarQuery_Closure_withAndWithoutRelationPlayers() {
QueryBuilder iqb = geoKB.tx().graql().infer(true);
String queryString = "match $x isa is-located-in; get;";
String queryString2 = "match $x ($x1, $x2) isa is-located-in;get $x;";
List<Answer> answers = iqb.materialise(false).<GetQuery>parse(queryString).execute();
List<Answer> answers2 = iqb.materialise(true).<GetQuery>parse(queryString).execute();
List<Answer> answers3 = iqb.materialise(false).<GetQuery>parse(queryString2).execute();
List<Answer> answers4 = iqb.materialise(true).<GetQuery>parse(queryString2).execute();
assertCollectionsEqual(answers, answers2);
assertCollectionsEqual(answers3, answers4);
assertEquals(answers.size(), 51);
assertEquals(answers3.size(), 51);
}
use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class GeoInferenceTest method testTransitiveQuery_Closure_NoRoles.
@Test
public void testTransitiveQuery_Closure_NoRoles() {
QueryBuilder iqb = geoKB.tx().graql().infer(true);
String queryString = "match ($x, $y) isa is-located-in; get;";
List<Answer> answers = iqb.materialise(false).<GetQuery>parse(queryString).execute();
List<Answer> answers2 = iqb.materialise(true).<GetQuery>parse(queryString).execute();
assertEquals(answers.size(), 102);
assertCollectionsEqual(answers, answers2);
}
use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class GeoInferenceTest method testTransitiveQuery_Closure_singleVariableRole.
@Test
public void testTransitiveQuery_Closure_singleVariableRole() {
QueryBuilder iqb = geoKB.tx().graql().infer(true);
String queryString = "match ($x, $r2: $y) isa is-located-in; get;";
List<Answer> answers = iqb.materialise(false).<GetQuery>parse(queryString).execute();
List<Answer> answers2 = iqb.materialise(true).<GetQuery>parse(queryString).execute();
answers.forEach(ans -> assertEquals(ans.size(), 3));
assertEquals(answers.size(), 204);
answers2.forEach(ans -> assertEquals(ans.size(), 3));
assertCollectionsEqual(answers, answers2);
}
Aggregations