Search in sources :

Example 6 with MultiUnifierImpl

use of ai.grakn.graql.internal.reasoner.MultiUnifierImpl in project grakn by graknlabs.

the class LazyQueryCache method getAnswerStreamWithUnifier.

@Override
public Pair<Stream<Answer>, MultiUnifier> getAnswerStreamWithUnifier(Q query) {
    CacheEntry<Q, LazyAnswerIterator> match = this.getEntry(query);
    if (match != null) {
        Q equivalentQuery = match.query();
        MultiUnifier multiUnifier = equivalentQuery.getMultiUnifier(query);
        Stream<Answer> unified = match.cachedElement().stream().flatMap(a -> a.unify(multiUnifier));
        return new Pair<>(unified, multiUnifier);
    }
    Stream<Answer> answerStream = record(query, query.getQuery().stream().map(a -> a.explain(new LookupExplanation(query))));
    return new Pair<>(answerStream, new MultiUnifierImpl());
}
Also used : Pair(ai.grakn.graql.internal.reasoner.utils.Pair) Stream(java.util.stream.Stream) ReasonerQueryImpl(ai.grakn.graql.internal.reasoner.query.ReasonerQueryImpl) MultiUnifier(ai.grakn.graql.admin.MultiUnifier) Map(java.util.Map) Set(java.util.Set) HashMap(java.util.HashMap) Answer(ai.grakn.graql.admin.Answer) LazyAnswerIterator(ai.grakn.graql.internal.reasoner.iterator.LazyAnswerIterator) Collectors(java.util.stream.Collectors) MultiUnifierImpl(ai.grakn.graql.internal.reasoner.MultiUnifierImpl) LookupExplanation(ai.grakn.graql.internal.reasoner.explanation.LookupExplanation) Answer(ai.grakn.graql.admin.Answer) LookupExplanation(ai.grakn.graql.internal.reasoner.explanation.LookupExplanation) LazyAnswerIterator(ai.grakn.graql.internal.reasoner.iterator.LazyAnswerIterator) MultiUnifier(ai.grakn.graql.admin.MultiUnifier) MultiUnifierImpl(ai.grakn.graql.internal.reasoner.MultiUnifierImpl) Pair(ai.grakn.graql.internal.reasoner.utils.Pair)

Aggregations

MultiUnifier (ai.grakn.graql.admin.MultiUnifier)6 MultiUnifierImpl (ai.grakn.graql.internal.reasoner.MultiUnifierImpl)6 Pair (ai.grakn.graql.internal.reasoner.utils.Pair)5 Answer (ai.grakn.graql.admin.Answer)4 Map (java.util.Map)4 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 Stream (java.util.stream.Stream)4 Var (ai.grakn.graql.Var)3 Unifier (ai.grakn.graql.admin.Unifier)3 Concept (ai.grakn.concept.Concept)2 GraqlQueryException (ai.grakn.exception.GraqlQueryException)2 Atomic (ai.grakn.graql.admin.Atomic)2 Conjunction (ai.grakn.graql.admin.Conjunction)2 ReasonerQuery (ai.grakn.graql.admin.ReasonerQuery)2 UnifierComparison (ai.grakn.graql.admin.UnifierComparison)2 VarPatternAdmin (ai.grakn.graql.admin.VarPatternAdmin)2 QueryAnswer (ai.grakn.graql.internal.query.QueryAnswer)2 UnifierImpl (ai.grakn.graql.internal.reasoner.UnifierImpl)2 Atom (ai.grakn.graql.internal.reasoner.atom.Atom)2