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. TheWorker
class implements arun()
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 passtcf.TextCorpus
objects around without serializing them. If a byte string serialization is required, usetcf.serialize()
.
-
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()
.
-
-
class
tcflib.service.
ImportingWorker
(**options)[source]¶ Bases:
tcflib.service.Worker
An
ImportingWorker
converts input data to TCF.
-
class
tcflib.service.
ExportingWorker
(**options)[source]¶ Bases:
tcflib.service.Worker
A
ExportingWorker
converts TCF data into other formats.
-
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.
-
-
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.
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.