qat.generators.AbstractGenerator

class qat.generators.AbstractGenerator(*args, **kwargs)

Abstract interface for a batch generator.

An abctract generator has a single abstract method ‘generate’. This generate function can return either:

  • a generator (use of keyword ‘yield’)

  • a Batch

An optional method ‘post_process’ can be also defined to parse the result. This method is used if one of the following condition is met:

The batch generator section give some examples of dummy batch generators

abstract generate(specs, *args, **kwargs)

Generates a batch. This function could return either an iterator or a Batch

serve(port, host_ip='localhost', server_type=None)

Runs the batch generator inside a server

Parameters
  • port (int) – the port on which to listen

  • host_ip (str, optional) – the hostname on which to publish the API. Defaults to ‘localhost’

  • server_type (str, optional) –

    type of server. The different types or server are:

    • ”simple”: single-thread server, accepts one connection at a time (default server type)

    • ”threaded”: multi-thread server, each connection starts a new thread

    • ”pool”: multi-thread server, each connection runs in a thread, with a maximum of 10 running threads

    • ”fork”: multi-process server, each connection runs in a new process

wrapper_post_process(result)

Post process the result returned by the second part of the stack.

First, this method will call the post process method of the plugin piped to this AbstractGenerator

Then, if post processing the result is a BatchResult, the result is post processed by this AbstractGenetor:

  • If ‘generate’ returned a generator, the result is sent to this generator

  • If ‘generate’ returned a Batch, call method ‘post_process’

Parameters

( (result) – class:`~qat.core.BatchResult): batch result

Returns

parsed post processed result

Return type

ParsedPostProcessedResult