use of ai.grakn.graql.internal.reasoner.state.CumulativeState 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