tcflib.service module

This moduls provides a base implementation of a TCF compatible web service.

class tcflib.service.Worker(**options)[source]

Bases: object

A Worker is responsible for running a single transformation. This is the base class.

Input data are passed to a Worker instance during initialization. The Worker class implements a run() method that returns the output data.

For efficiency reasons, a worker can get either a byte string or a tcf.TextCorpus as input. This allows to pass tcf.TextCorpus objects around without serializing them. If a byte string serialization is required, use tcf.serialize().

setup(input_data)[source]

Read input_data and parse them into a tcf.TextCorpus.

run(input_data)[source]

This method is called to perform the actual data transformation. Subclasses must override this method.

class tcflib.service.AddingWorker(**options)[source]

Bases: tcflib.service.Worker

An AddingWorker adds annotations to the input data.

run(input_data)[source]

Parse input data and run annotation.

Subclasses usually do not override this method, but add_annotations().

add_annotations()[source]

Subclasses usually override this method.

class tcflib.service.ImportingWorker(**options)[source]

Bases: tcflib.service.Worker

An ImportingWorker converts input data to TCF.

setup(input_data)[source]

Read input_data and parse them into a tcf.TextCorpus.

run(input_data)[source]

Parse input data and run annotation.

Subclasses usually do not override this method, but import_().

import_()[source]

Subclasses usually override this method.

class tcflib.service.ExportingWorker(**options)[source]

Bases: tcflib.service.Worker

A ExportingWorker converts TCF data into other formats.

run(input_data)[source]

Parse input data and run annotation.

Subclasses usually do not override this method, but export().

export()[source]

Subclasses usually override this method.

class tcflib.service.RemoteWorker(**options)[source]

Bases: tcflib.service.Worker

A RemoteWorker defers the actual work to a web service.

This class can either be instantiated directly, passing the url parameter to its constructor, or it can be subclassed, setting the url class variable.

url = ''

The URL of the remote service.

run(input_data)[source]

Pass input_data to a remote service.

class tcflib.service.Write(filename)[source]

Bases: object

A dummy worker that writes its input into a file.

It returns the input unchanged, so it can be used to write out intermediate results in a chain.

tcflib.service.Read(filename)[source]

A dummy worker that reads input from a file.

tcflib.service.get_arg_parser(worker_class=None)[source]

Create an ArgumentParser with default options.

tcflib.service.run_as_cli(worker_class)[source]

Run a worker from the commandline.

In order for a worker to be called from the command line, the module defining the worker should call run_as_cli() when run standalone.

tcflib.service.run_as_service(worker_class, port)[source]

Run a worker as a web service.