Class Request

Class Documentation

class Request

A Request is an internal representation used to represent a request after processed by TextProcessor into sentences constituted by marian::Words.

The batching mechanism (BatchingPool) draws from multiple Requests and compiles sentences into a batch. When a batch completes translation (at BatchTranslator, intended in a different thread), backward propogation happens through:

Batch::completeBatch(...)
    -> RequestSentence::completeSentence(..)
       -> Request::processHistory(...)

When all sentences in a Request are completed, responseBuilder is triggered with the compiled Histories, to construct the Response corresponding to the Request and set value of the promise which triggers the future at client.

Public Functions

Request(size_t Id, const TranslationModel &model, Segments &&segments, ResponseBuilder &&responseBuilder, std::optional<TranslationCache> &cache)

Constructs an internal representation of the Request identified by Id, processed Segments and accepts a callback (ResponseBuilder) which builds the Response upon completion of the Request.

Parameters
  • [in] Id: Identifier assigned to Request by Service.

  • [in] model: TranslationModel for identifying a unique translation unit key (model, words in a sentence) for cache.

  • [in] segments: Each segment is a unit to be translated.

  • [in] responseBuilder: Callback function (of ResponseBuilder type) to be triggered upon the completion of translation of all units in a Request.

  • [in] cache: Cache supplied externally to attempt to fetch translations or store them after completion for reuse later.

size_t segmentTokens(size_t index) const

Obtain the count of tokens in the segment correponding to index.

Used to insert sentence from multiple requests into the corresponding size bucket.

size_t numSegments() const

Obtain number of segments in a request.

Segment getSegment(size_t index) const

Obtains segment corresponding to index to create a batch of segments among several requests.

bool operator<(const Request &request) const

For notions of priority among requests, used to enable std::set in BatchingPool.

void processHistory(size_t index, Ptr<History> history)

Processes a history obtained after translating in a heterogenous batch compiled from requests.

bool cacheHitPrefilled(size_t index) const