use of ai.grakn.graql.internal.reasoner.plan.ResolutionPlan in project grakn by graknlabs.
the class ResolutionPlanTest method makeSureConnectednessPreservedWhenRelationsWithSameTypesPresent_longerChain.
@Test
public void makeSureConnectednessPreservedWhenRelationsWithSameTypesPresent_longerChain() {
EmbeddedGraknTx<?> testTx = testContext.tx();
String queryString = "{" + "(role1:$x, role2: $y) isa relation;" + "(role1:$y, role2: $z) isa anotherRelation;" + "(role1:$z, role2: $w) isa yetAnotherRelation;" + "(role1:$w, role2: $u) isa relation;" + "(role1:$u, role2: $v) isa anotherRelation;" + "(role1:$v, role2: $q) isa yetAnotherRelation;" + "}";
ReasonerQueryImpl query = ReasonerQueries.create(conjunction(queryString, testTx), testTx);
ImmutableList<Atom> plan = new ResolutionPlan(query).plan();
UnmodifiableIterator<Atom> iterator = plan.iterator();
Set<Var> vars = new HashSet<>();
vars.addAll(iterator.next().getVarNames());
while (iterator.hasNext()) {
Atom next = iterator.next();
Set<Var> varNames = next.getVarNames();
assertTrue(!Sets.intersection(varNames, vars).isEmpty());
vars.addAll(varNames);
}
}
use of ai.grakn.graql.internal.reasoner.plan.ResolutionPlan in project grakn by graknlabs.
the class ResolutionPlanTest method makeSureConnectednessPreservedWhenRelationsWithSameTypesPresent.
@Test
public void makeSureConnectednessPreservedWhenRelationsWithSameTypesPresent() {
EmbeddedGraknTx<?> testTx = testContext.tx();
String queryString = "{" + "(role1:$x, role2: $y) isa relation;" + "(role1:$y, role2: $z) isa anotherRelation;" + "(role1:$z, role2: $w) isa relation;" + "(role1:$w, role2: $u) isa anotherRelation;" + "(role1:$u, role2: $v) isa relation;" + "}";
ReasonerQueryImpl query = ReasonerQueries.create(conjunction(queryString, testTx), testTx);
ImmutableList<Atom> plan = new ResolutionPlan(query).plan();
UnmodifiableIterator<Atom> iterator = plan.iterator();
Set<Var> vars = new HashSet<>();
vars.addAll(iterator.next().getVarNames());
while (iterator.hasNext()) {
Atom next = iterator.next();
Set<Var> varNames = next.getVarNames();
assertTrue(!Sets.intersection(varNames, vars).isEmpty());
vars.addAll(varNames);
}
}
use of ai.grakn.graql.internal.reasoner.plan.ResolutionPlan in project grakn by graknlabs.
the class ReasonerQueryImpl method queryStateIterator.
/**
* @param parent parent state
* @param subGoals set of visited sub goals
* @param cache query cache
* @return query state iterator (db iter + unifier + state iter) for this query
*/
public Pair<Iterator<ResolutionState>, MultiUnifier> queryStateIterator(QueryStateBase parent, Set<ReasonerAtomicQuery> subGoals, QueryCache<ReasonerAtomicQuery> cache) {
Iterator<AnswerState> dbIterator;
Iterator<QueryStateBase> subGoalIterator;
if (!this.isRuleResolvable()) {
dbIterator = this.getQuery().stream().map(ans -> ans.explain(new JoinExplanation(this, ans))).map(ans -> new AnswerState(ans, parent.getUnifier(), parent)).iterator();
subGoalIterator = Collections.emptyIterator();
} else {
dbIterator = Collections.emptyIterator();
LinkedList<ReasonerQueryImpl> subQueries = new ResolutionPlan(this).queryPlan();
LOG.trace("CQ plan:\n" + subQueries.stream().map(sq -> sq.toString() + (sq.isRuleResolvable() ? "*" : "")).collect(Collectors.joining("\n")));
subGoalIterator = Iterators.singletonIterator(new CumulativeState(subQueries, new QueryAnswer(), parent.getUnifier(), parent, subGoals, cache));
}
return new Pair<>(Iterators.concat(dbIterator, subGoalIterator), new MultiUnifierImpl());
}
Aggregations