use of ai.grakn.graql.GetQuery in project grakn by graknlabs.
the class ReasonerTest method testReasoningWithQueryContainingTypeVar.
@Test
public void testReasoningWithQueryContainingTypeVar() {
String queryString = "match $x isa person;$y isa $type;($x, $y) isa recommendation; get;";
String explicitQuery = "match $y isa $type;" + "{$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;";
GetQuery query = snbKB.tx().graql().infer(true).parse(queryString);
GetQuery query2 = snbKB.tx().graql().infer(false).parse(explicitQuery);
assertQueriesEqual(query, query2);
}
use of ai.grakn.graql.GetQuery in project grakn by graknlabs.
the class ReasonerTest method testReasoningWithQueryContainingTautology.
@Test
public void testReasoningWithQueryContainingTautology() {
GraknTx graph = nonMaterialisedGeoKB.tx();
String queryString = "match ($x, $y) isa is-located-in;city sub geoObject; get;";
String queryString2 = "match ($x, $y) isa is-located-in; get;";
QueryBuilder iqb = graph.graql().infer(true);
GetQuery query = iqb.parse(queryString);
GetQuery query2 = iqb.parse(queryString2);
assertQueriesEqual(query, query2);
}
use of ai.grakn.graql.GetQuery in project grakn by graknlabs.
the class ReasonerTest method testReasoningWithQueryContainingTypeHas.
@Test
public void testReasoningWithQueryContainingTypeHas() {
GraknTx graph = nonMaterialisedGeoKB.tx();
String queryString = "match $x isa $type;$type has name;$y isa country;$y has name 'Poland';" + "($x, $y) isa is-located-in;get $x, $y;";
String queryString2 = "match $y isa country;$y has name 'Poland';" + "($x, $y) isa is-located-in; get;";
QueryBuilder iqb = graph.graql().infer(true);
GetQuery query = iqb.parse(queryString);
GetQuery query2 = iqb.parse(queryString2);
assertQueriesEqual(query, query2);
}
use of ai.grakn.graql.GetQuery in project grakn by graknlabs.
the class OntologicalQueryTest method allInstancesOfTypesThatCanHaveAGivenResourceType.
/**
* HasAtom *
*/
@Test
public void allInstancesOfTypesThatCanHaveAGivenResourceType() {
GraknTx tx = testContext.tx();
QueryBuilder qb = tx.graql().infer(true);
String queryString = "match $x isa $type; $type has name; get;";
List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
// 1 x noRoleEntity + 3 x 3 (hierarchy) anotherTwoRoleEntities
assertEquals(answers.size(), 10);
assertCollectionsEqual(answers, qb.infer(false).<GetQuery>parse(queryString).execute());
}
use of ai.grakn.graql.GetQuery in project grakn by graknlabs.
the class OntologicalQueryTest method allInstancesOfTypesThatAreSubTypeOfGivenType_needInferenceToGetAllResults.
@Test
public void allInstancesOfTypesThatAreSubTypeOfGivenType_needInferenceToGetAllResults() {
GraknTx tx = testContext.tx();
QueryBuilder qb = tx.graql().infer(true);
String queryString = "match $x isa $type; $type sub relationship; get;";
List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
assertEquals(answers.size(), tx.getRelationshipType("relationship").subs().flatMap(RelationshipType::instances).count());
assertCollectionsEqual(answers, qb.infer(false).<GetQuery>parse(queryString).execute());
}
Aggregations