use of ai.grakn.graql.internal.reasoner.query.ReasonerQueryImpl in project grakn by graknlabs.
the class ResolutionPlan method queryPlan.
/**
* compute the query resolution plan - list of queries ordered by their cost as computed by the graql traversal planner
* @return list of prioritised queries
*/
public LinkedList<ReasonerQueryImpl> queryPlan() {
LinkedList<ReasonerQueryImpl> queries = new LinkedList<>();
LinkedList<Atom> atoms = new LinkedList<>(plan);
List<Atom> nonResolvableAtoms = new ArrayList<>();
while (!atoms.isEmpty()) {
Atom top = atoms.remove();
if (top.isRuleResolvable()) {
if (!nonResolvableAtoms.isEmpty()) {
queries.add(ReasonerQueries.create(nonResolvableAtoms, tx));
nonResolvableAtoms.clear();
}
queries.add(ReasonerQueries.atomic(top));
} else {
nonResolvableAtoms.add(top);
if (atoms.isEmpty())
queries.add(ReasonerQueries.create(nonResolvableAtoms, tx));
}
}
return queries;
}
use of ai.grakn.graql.internal.reasoner.query.ReasonerQueryImpl in project grakn by graknlabs.
the class QueryTest method testQueryReiterationCondition_AnotherCyclicalRuleGraph.
@Test
public void testQueryReiterationCondition_AnotherCyclicalRuleGraph() {
EmbeddedGraknTx<?> graph = snbGraph.tx();
String patternString = "{($x, $y);}";
ReasonerQueryImpl query = ReasonerQueries.create(conjunction(patternString, graph), graph);
assertTrue(query.requiresReiteration());
}
use of ai.grakn.graql.internal.reasoner.query.ReasonerQueryImpl in project grakn by graknlabs.
the class QueryTest method testAlphaEquivalence.
// check two queries are alpha-equivalent - equal up to the choice of free variables
@Test
public void testAlphaEquivalence() {
EmbeddedGraknTx<?> graph = geoKB.tx();
String patternString = "{" + "$x isa city, has name 'Warsaw';" + "$y isa region;" + "($x, $y) isa is-located-in;" + "($y, $z) isa is-located-in;" + "$z isa country, has name 'Poland';}";
String patternString2 = "{" + "($r, $ctr) isa is-located-in;" + "($c, $r) isa is-located-in;" + "$c isa city, has name 'Warsaw';" + "$r isa region;" + "$ctr isa country, has name 'Poland';}";
ReasonerQueryImpl query = ReasonerQueries.create(conjunction(patternString, graph), graph);
ReasonerQueryImpl query2 = ReasonerQueries.create(conjunction(patternString2, graph), graph);
queryEquivalence(query, query2, true);
}
use of ai.grakn.graql.internal.reasoner.query.ReasonerQueryImpl in project grakn by graknlabs.
the class QueryTest method testAlphaEquivalence_nonMatchingTypes.
// tests various configurations of alpha-equivalence with extra type atoms present
@Test
public void testAlphaEquivalence_nonMatchingTypes() {
EmbeddedGraknTx<?> graph = geoKB.tx();
String polandId = getConcept(graph, "name", "Poland").getId().getValue();
String patternString = "{$y id '" + polandId + "'; $y isa country; (geo-entity: $y1, entity-location: $y), isa is-located-in;}";
String patternString2 = "{$x1 id '" + polandId + "'; $y isa country; (geo-entity: $x1, entity-location: $x2), isa is-located-in;}";
String patternString3 = "{$y id '" + polandId + "'; $x isa city; (geo-entity: $x, entity-location: $y), isa is-located-in; $y isa country;}";
String patternString4 = "{$x isa city; (entity-location: $y1, geo-entity: $x), isa is-located-in;}";
String patternString5 = "{(geo-entity: $y1, entity-location: $y2), isa is-located-in;}";
ReasonerQueryImpl query = ReasonerQueries.create(conjunction(patternString, graph), graph);
ReasonerQueryImpl query2 = ReasonerQueries.create(conjunction(patternString2, graph), graph);
ReasonerQueryImpl query3 = ReasonerQueries.create(conjunction(patternString3, graph), graph);
ReasonerQueryImpl query4 = ReasonerQueries.create(conjunction(patternString4, graph), graph);
ReasonerQueryImpl query5 = ReasonerQueries.create(conjunction(patternString5, graph), graph);
queryEquivalence(query, query2, false);
queryEquivalence(query, query3, false);
queryEquivalence(query2, query3, false);
queryEquivalence(query, query4, false);
queryEquivalence(query, query5, false);
queryEquivalence(query3, query4, false);
queryEquivalence(query3, query5, false);
queryEquivalence(query4, query5, false);
}
use of ai.grakn.graql.internal.reasoner.query.ReasonerQueryImpl in project grakn by graknlabs.
the class QueryTest method testWhenReifyingRelation_ExtraAtomIsCreatedWithUserDefinedName.
@Test
public void testWhenReifyingRelation_ExtraAtomIsCreatedWithUserDefinedName() {
EmbeddedGraknTx<?> graph = geoKB.tx();
String patternString = "{(geo-entity: $x, entity-location: $y) isa is-located-in;}";
String patternString2 = "{($x, $y) relates geo-entity;}";
Conjunction<VarPatternAdmin> pattern = conjunction(patternString, graph);
Conjunction<VarPatternAdmin> pattern2 = conjunction(patternString2, graph);
ReasonerQueryImpl query = ReasonerQueries.create(pattern, graph);
ReasonerQueryImpl query2 = ReasonerQueries.create(pattern2, graph);
assertEquals(query.getAtoms(RelationshipAtom.class).findFirst().orElse(null).isUserDefined(), false);
assertEquals(query2.getAtoms(RelationshipAtom.class).findFirst().orElse(null).isUserDefined(), true);
assertEquals(query.getAtoms().size(), 1);
assertEquals(query2.getAtoms().size(), 2);
}
Aggregations