Class BlockingService

Nested Relationships

Nested Types

Class Documentation

class BlockingService

See AsyncService.

BlockingService is a not-threaded counterpart of AsyncService which can operate only in a blocking workflow (queue a bunch of texts and optional args to translate, wait till the translation finishes).

Public Functions

BlockingService(const BlockingService::Config &config)

Construct a BlockingService with configuration loaded from an Options object.

Does not require any keys, values to be set.

std::vector<Response> translateMultiple(std::shared_ptr<TranslationModel> translationModel, std::vector<std::string> &&source, const std::vector<ResponseOptions> &responseOptions)

Translate multiple text-blobs in a single blocking API call, providing ResponseOptions which applies across all text-blobs dictating how to construct Response.

ResponseOptions can be used to enable/disable additional information like quality-scores, alignments etc. If you have async/multithread capabilities, it is recommended to work with AsyncService instead of this class. Note that due to batching differences and consequent floating-point rounding differences, this is not guaranteed to have the same output as AsyncService.

Parameters
  • [in] translationModel: TranslationModel to use for the request.

  • [in] source: rvalue reference of the string to be translated

  • [in] responseOptions: ResponseOptions per source-item indicating whether or not to include some member in the Response, also specify any additional configurable parameters.

std::vector<Response> pivotMultiple(std::shared_ptr<TranslationModel> first, std::shared_ptr<TranslationModel> second, std::vector<std::string> &&sources, const std::vector<ResponseOptions> &responseOptions)

With the supplied two translation models, translate using first and then the second generating a response as if it were translated from first’s source language to second’s target langauge.

Requires first’s target to be second’s source to work correctly - effectively implementing pivoting translation via an intermediate language.

Return

responses corresponding to the source-text which can be used as if they were translated with translateMultiple.

Parameters
  • [in] first: TranslationModel capable of translating from source language to pivot language.

  • [in] second: TranslationModel capable of translating between pivot and target language.

  • [move]: sources: The input source texts to be translated.

  • [in] options: Options indicating whether or not to include optional members per source-text. See ResponseOptions.

TranslationCache::Stats cacheStats()
struct Config

Public Members

size_t cacheSize = {0}

Size in History items to be stored in the cache.

A value of 0 means no caching. Loosely corresponds to sentences to cache in the real world. Note that cache has a random-eviction policy. The peak storage at full occupancy is controlled by this parameter. However, whether we attain full occupancy or not is controlled by random factors - specifically how uniformly the hash distributes.

Logger::Config logger

Configurations for logging.

Public Static Functions

template<class App>
static void addOptions(App &app, Config &config)