Search in sources :

Example 1 with Request

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

the class ConcludableResolver 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);
    if (iteration < iterationByRoot.get(fromUpstream.partialAnswer().root())) {
        // short circuit old iteration failed messages to upstream
        failToUpstream(fromUpstream, iteration);
    } else {
        CachingRequestState<?, ConceptMap> requestState = this.requestStates.get(fromUpstream);
        assert iteration == requestState.iteration();
        if (requestState.isExploration()) {
            requestState.asExploration().downstreamManager().removeDownstream(fromDownstream.sourceRequest());
        }
        nextAnswer(fromUpstream, requestState, iteration);
    }
}
Also used : Request(com.vaticle.typedb.core.reasoner.resolution.framework.Request) ConceptMap(com.vaticle.typedb.core.concept.answer.ConceptMap)

Example 2 with Request

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

the class ConclusionResolver 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);
    ConclusionRequestState<? extends Partial.Concludable<?>> requestState = this.requestStates.get(fromUpstream);
    if (!requestState.isComplete()) {
        FunctionalIterator<Map<Identifier.Variable, Concept>> materialisations = conclusion.materialise(fromDownstream.answer().conceptMap(), traversalEngine, conceptMgr);
        if (!materialisations.hasNext())
            throw TypeDBException.of(ILLEGAL_STATE);
        requestState.newMaterialisedAnswers(fromDownstream.answer(), materialisations);
    }
    nextAnswer(fromUpstream, requestState, iteration);
}
Also used : Identifier(com.vaticle.typedb.core.traversal.common.Identifier) Partial(com.vaticle.typedb.core.reasoner.resolution.answer.AnswerState.Partial) Request(com.vaticle.typedb.core.reasoner.resolution.framework.Request) HashMap(java.util.HashMap) Map(java.util.Map) ConceptMap(com.vaticle.typedb.core.concept.answer.ConceptMap)

Example 3 with Request

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

the class ConjunctionResolver method receiveFail.

@Override
protected void receiveFail(Response.Fail fromDownstream, int iteration) {
    LOG.trace("{}: Receiving Exhausted: {}", name(), fromDownstream);
    if (isTerminated())
        return;
    Request toDownstream = fromDownstream.sourceRequest();
    Request fromUpstream = fromUpstream(toDownstream);
    RequestState requestState = this.requestStates.get(fromUpstream);
    if (iteration < requestState.iteration()) {
        // short circuit old iteration failed 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 4 with Request

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

the class NegationResolver method tryAnswer.

private void tryAnswer(Request fromUpstream, BoundsState boundsState) {
    /*
        NOTE:
           Correctness: concludables that get reused in the negated portion, would conflate recursion/reiteration state from
              the toplevel root with the negation iterations, which we cannot allow. So, we must use THIS resolver
              as a sort of new root!
        */
    assert fromUpstream.partialAnswer().isCompound();
    Compound.Nestable downstreamPartial = fromUpstream.partialAnswer().asCompound().filterToNestable(negated.retrieves());
    Request request = Request.create(driver(), this.downstream, downstreamPartial);
    requestFromDownstream(request, fromUpstream, 0);
    boundsState.setRequested();
}
Also used : Request(com.vaticle.typedb.core.reasoner.resolution.framework.Request) Compound(com.vaticle.typedb.core.reasoner.resolution.answer.AnswerState.Partial.Compound)

Example 5 with Request

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

the class NegationResolver method receiveAnswer.

@Override
protected void receiveAnswer(com.vaticle.typedb.core.reasoner.resolution.framework.Response.Answer fromDownstream, int iteration) {
    LOG.trace("{}: received Answer: {}, therefore is FAILED", name(), fromDownstream);
    if (isTerminated())
        return;
    Request toDownstream = fromDownstream.sourceRequest();
    Request fromUpstream = fromUpstream(toDownstream);
    BoundsState boundsState = this.boundsStates.get(fromUpstream.partialAnswer().conceptMap());
    boundsState.setFailed();
    for (BoundsState.Awaiting awaiting : boundsState.awaiting) {
        failToUpstream(awaiting.request, awaiting.iterationRequested);
    }
    boundsState.clearAwaiting();
}
Also used : Request(com.vaticle.typedb.core.reasoner.resolution.framework.Request)

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