tcflib.service module¶
This moduls provides a base implementation of a TCF compatible web service.
-
class
tcflib.service.Worker(**options)[source]¶ Bases:
objectA
Workeris responsible for running a single transformation. This is the base class.Input data are passed to a
Workerinstance during initialization. TheWorkerclass implements arun()method that returns the output data.For efficiency reasons, a worker can get either a byte string or a
tcf.TextCorpusas input. This allows to passtcf.TextCorpusobjects around without serializing them. If a byte string serialization is required, usetcf.serialize().
-
class
tcflib.service.AddingWorker(**options)[source]¶ Bases:
tcflib.service.WorkerAn
AddingWorkeradds 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.WorkerAn
ImportingWorkerconverts input data to TCF.
-
class
tcflib.service.ExportingWorker(**options)[source]¶ Bases:
tcflib.service.WorkerA
ExportingWorkerconverts TCF data into other formats.
-
class
tcflib.service.RemoteWorker(**options)[source]¶ Bases:
tcflib.service.WorkerA
RemoteWorkerdefers 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:
objectA 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.