Search in sources :

Example 6 with Request

use of com.vaticle.typedb.core.reasoner.resolution.framework.Request in project grakn by graknlabs.

the class NegationResolver method receiveFail.

@Override
protected void receiveFail(com.vaticle.typedb.core.reasoner.resolution.framework.Response.Fail fromDownstream, int iteration) {
    LOG.trace("{}: Receiving Failed: {}, therefore is SATISFIED", name(), fromDownstream);
    if (isTerminated())
        return;
    Request toDownstream = fromDownstream.sourceRequest();
    Request fromUpstream = fromUpstream(toDownstream);
    BoundsState boundsState = this.boundsStates.get(fromUpstream.partialAnswer().conceptMap());
    boundsState.setSatisfied();
    for (BoundsState.Awaiting awaiting : boundsState.awaiting) {
        answerToUpstream(upstreamAnswer(awaiting.request), awaiting.request, awaiting.iterationRequested);
    }
    boundsState.clearAwaiting();
}
Also used : Request(com.vaticle.typedb.core.reasoner.resolution.framework.Request)

Example 7 with Request

use of com.vaticle.typedb.core.reasoner.resolution.framework.Request in project grakn by graknlabs.

the class CompoundResolver method receiveFail.

@Override
protected void receiveFail(Response.Fail fromDownstream, int iteration) {
    LOG.trace("{}: received Exhausted, with iter {}: {}", name(), iteration, fromDownstream);
    if (isTerminated())
        return;
    Request toDownstream = fromDownstream.sourceRequest();
    Request fromUpstream = fromUpstream(toDownstream);
    RequestState requestState = requestStates.get(fromUpstream);
    if (iteration < requestState.iteration()) {
        // short circuit old iteration failed messages back out of the actor model
        failToUpstream(fromUpstream, iteration);
        return;
    }
    requestState.downstreamManager().removeDownstream(fromDownstream.sourceRequest());
    nextAnswer(fromUpstream, requestState, iteration);
}
Also used : Request(com.vaticle.typedb.core.reasoner.resolution.framework.Request)

Example 8 with Request

use of com.vaticle.typedb.core.reasoner.resolution.framework.Request in project grakn by graknlabs.

the class ConclusionResolver method receiveFail.

@Override
protected void receiveFail(Response.Fail fromDownstream, int iteration) {
    LOG.trace("{}: received Fail: {}", name(), fromDownstream);
    if (isTerminated())
        return;
    Request toDownstream = fromDownstream.sourceRequest();
    Request fromUpstream = fromUpstream(toDownstream);
    ConclusionRequestState<?> requestState = this.requestStates.get(fromUpstream);
    if (iteration < requestState.iteration()) {
        // short circuit old iteration fail messages to upstream
        failToUpstream(fromUpstream, iteration);
        return;
    }
    requestState.downstreamManager().removeDownstream(fromDownstream.sourceRequest());
    nextAnswer(fromUpstream, requestState, iteration);
}
Also used : Request(com.vaticle.typedb.core.reasoner.resolution.framework.Request)

Example 9 with Request

use of com.vaticle.typedb.core.reasoner.resolution.framework.Request in project grakn by graknlabs.

the class ConjunctionResolver method toNextChild.

private void toNextChild(Response.Answer fromDownstream, int iteration, Request fromUpstream, RequestState requestState, Plans.Plan plan) {
    int nextResolverIndex = fromDownstream.planIndex() + 1;
    Resolvable<?> nextResolvable = plan.get(nextResolverIndex);
    ResolverRegistry.ResolverView nextPlannedDownstream = downstreamResolvers.get(nextResolvable);
    final Partial<?> downstream = toDownstream(fromDownstream.answer().asCompound(), nextPlannedDownstream, nextResolvable);
    Request downstreamRequest = Request.create(driver(), nextPlannedDownstream.resolver(), downstream, nextResolverIndex);
    requestFromDownstream(downstreamRequest, fromUpstream, iteration);
    // negated requests can be used twice in a parallel setting, and return the same answer twice
    if (!nextResolvable.isNegated() || (nextResolvable.isNegated() && !requestState.downstreamManager().contains(downstreamRequest))) {
        requestState.downstreamManager().addDownstream(downstreamRequest);
    }
}
Also used : ResolverRegistry(com.vaticle.typedb.core.reasoner.resolution.ResolverRegistry) Request(com.vaticle.typedb.core.reasoner.resolution.framework.Request)

Example 10 with Request

use of com.vaticle.typedb.core.reasoner.resolution.framework.Request in project grakn by graknlabs.

the class ConjunctionResolver method receiveAnswer.

@Override
protected void receiveAnswer(Response.Answer fromDownstream, int iteration) {
    LOG.trace("{}: received Answer: {}", name(), fromDownstream);
    if (isTerminated())
        return;
    Request toDownstream = fromDownstream.sourceRequest();
    Request fromUpstream = fromUpstream(toDownstream);
    RequestState requestState = requestStates.get(fromUpstream);
    Plans.Plan plan = plans.getActive(fromUpstream);
    // this could be either implemented with a different response type: FinalAnswer, or splitting Request into ReusableRequest vs SingleRequest
    if (plan.get(toDownstream.planIndex()).isNegated())
        requestState.downstreamManager().removeDownstream(toDownstream);
    Partial.Compound<?, ?> partialAnswer = fromDownstream.answer().asCompound();
    if (plan.isLast(fromDownstream.planIndex())) {
        Optional<AnswerState> upstreamAnswer = toUpstreamAnswer(partialAnswer);
        boolean answerAccepted = upstreamAnswer.isPresent() && tryAcceptUpstreamAnswer(upstreamAnswer.get(), fromUpstream, iteration);
        if (!answerAccepted)
            nextAnswer(fromUpstream, requestState, iteration);
    } else {
        toNextChild(fromDownstream, iteration, fromUpstream, requestState, plan);
    }
}
Also used : Partial(com.vaticle.typedb.core.reasoner.resolution.answer.AnswerState.Partial) Request(com.vaticle.typedb.core.reasoner.resolution.framework.Request) AnswerState(com.vaticle.typedb.core.reasoner.resolution.answer.AnswerState)

Aggregations

Request (com.vaticle.typedb.core.reasoner.resolution.framework.Request)16 ConceptMap (com.vaticle.typedb.core.concept.answer.ConceptMap)4 Partial (com.vaticle.typedb.core.reasoner.resolution.answer.AnswerState.Partial)3 Compound (com.vaticle.typedb.core.reasoner.resolution.answer.AnswerState.Partial.Compound)3 ResolverRegistry (com.vaticle.typedb.core.reasoner.resolution.ResolverRegistry)2 AnswerState (com.vaticle.typedb.core.reasoner.resolution.answer.AnswerState)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Unifier (com.vaticle.typedb.core.logic.resolvable.Unifier)1 Identifier (com.vaticle.typedb.core.traversal.common.Identifier)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Set (java.util.Set)1