Class TheWorksExample
- java.lang.Object
-
- nzilbb.ag.automation.Annotator
-
- nzilbb.ag.automation.example.theworks.TheWorksExample
-
- All Implemented Interfaces:
Function<Graph,Graph>
,UnaryOperator<Graph>
,ImplementsDictionaries
,GraphTransformer
,MonitorableTask
@UsesFileSystem @UsesRelationalDatabase public class TheWorksExample extends Annotator implements ImplementsDictionaries
This is an example annotator which implements all possible features of an annotator.The annotator:
- Includes a conf web-app
- Includes a task web-app
-
-
Constructor Summary
Constructors Constructor Description TheWorksExample()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
getAnnotatorId()
This class implements its own version ofAnnotator.getAnnotatorId()
which is not necessary unless there's a class-name clash with some other annotator.String
getConfig()
Provides the overall configuration of the annotator.Dictionary
getDictionary(String id)
Gets the identified dictionary.List<String>
getDictionaryIds()
Lists the dictionaries implemented by this Annotator.String
getInputLayer()
Getter forinputLayer
: ID of input layer.Double
getLabelConfidence()
Getter forlabelConfidence
: Value for annotator confidence.int
getLeftPadding()
Getter forleftPadding
: How many spaces to add on the left.String
getMinimumApiVersion()
Get the minimum version of the nzilbb.ag API supported by the serializer.String
getOutputLayer()
Getter foroutputLayer
: ID of output layer.String[]
getOutputLayers()
Determines which layers the annotator will create/update/delete annotations on.String
getPrefix()
Getter forprefix
: Prefix to add.String[]
getRequiredLayers()
Determines which layers the annotator requires in order to annotate a graph.Boolean
getReverse()
Getter forreverse
: Reverse annotation labels setting.Integer
getRightPadding()
Getter forrightPadding
: How many spaces to add on the right.Integer
getSimulatedInstallationDuration()
Getter forsimulatedInstallationDuration
: How long, in seconds, the #setConfig(String) method should take to return.void
setConfig(String config)
Specifies the overall configuration of the annotator, and runs any processing required to install the annotator.TheWorksExample
setInputLayer(String newInputLayer)
Setter forinputLayer
: ID of input layer.TheWorksExample
setLabelConfidence(Double newLabelConfidence)
Setter forlabelConfidence
: Value for annotator confidence.TheWorksExample
setLeftPadding(int newLeftPadding)
Setter forleftPadding
: How many spaces to add on the left.TheWorksExample
setOutputLayer(String newOutputLayer)
Setter foroutputLayer
: ID of output layer.void
setPadding(int leftPadding, int rightPadding)
Sets the padding.TheWorksExample
setPrefix(String newPrefix)
Setter forprefix
: Prefix to add.void
setRdbConnectionFactory(ConnectionFactory db)
Sets the information required for connecting to the relational database.void
setReverse(Boolean newReverse)
Setter forreverse
: Reverse annotation labels setting.TheWorksExample
setRightPadding(Integer newRightPadding)
Setter forrightPadding
: How many spaces to add on the right.TheWorksExample
setSimulatedInstallationDuration(Integer newSimulatedInstallationDuration)
Setter forsimulatedInstallationDuration
: How long, in seconds, the #setConfig(String) method should take to return.void
setTaskParameters(String parameters)
Sets the configuration for a given annotation task.Graph
transform(Graph graph)
Transforms the graph.void
uninstall()
Runs any processing required to uninstall the annotator.String
uploadFile(File file)
Accepts an uploaded file.-
Methods inherited from class nzilbb.ag.automation.Annotator
cancel, getCancellationObservers, getPercentComplete, getPercentCompleteObservers, getRunning, getRunningObservers, getSchema, getStatus, getStatusObservers, getStore, getVersion, getWorkingDirectory, newConnection, setCancellationObservers, setSchema, setStatus, setStore, setWorkingDirectory, transformFragments, transformTranscripts
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface nzilbb.ag.GraphTransformer
apply
-
Methods inherited from interface nzilbb.ag.automation.ImplementsDictionaries
tagAllInstances
-
Methods inherited from interface nzilbb.util.MonitorableTask
getTaskId
-
-
-
-
Method Detail
-
getMinimumApiVersion
public String getMinimumApiVersion()
Get the minimum version of the nzilbb.ag API supported by the serializer.- Specified by:
getMinimumApiVersion
in classAnnotator
- Returns:
- Minimum version of the nzilbb.ag API supported by the serializer.
- See Also:
Constants.VERSION
-
getAnnotatorId
public String getAnnotatorId()
This class implements its own version ofAnnotator.getAnnotatorId()
which is not necessary unless there's a class-name clash with some other annotator.If such a class exists, you would need this method to return something other than
getClass().getSimpleName()
.- Overrides:
getAnnotatorId
in classAnnotator
- Returns:
- The annotator's ID.
-
setRdbConnectionFactory
public void setRdbConnectionFactory(ConnectionFactory db) throws SQLException
Sets the information required for connecting to the relational database.This is automatically called if the annotator is annotated with
UsesRelationalDatabase
, providing the implementation with access to a relational database.- Overrides:
setRdbConnectionFactory
in classAnnotator
- Parameters:
db
- Factory for making new connections to the database.- Throws:
SQLException
- If the annotator can't connect to the given database.
-
uninstall
public void uninstall()
Runs any processing required to uninstall the annotator.In this case, the table created in rdbConnectionFactory() is DROPped.
-
getConfig
public String getConfig()
Provides the overall configuration of the annotator.This implementation uses
Annotator.beanPropertiesToQueryString()
to generate the string from the current bean properties.- Overrides:
getConfig
in classAnnotator
- Returns:
- The overall configuration of the annotator, which will be passed to the config/index.html configuration webapp, if any. This configuration may be null, or a string that serializes the annotators configuration state in any encoding the implementor prefers. The resulting string must be interpretable by the config/index.html webapp.
- See Also:
setConfig(String)
,Annotator.beanPropertiesToQueryString()
-
setConfig
public void setConfig(String config) throws InvalidConfigurationException
Specifies the overall configuration of the annotator, and runs any processing required to install the annotator.This processing is assumed to be synchronous (this method doesn't return until it's complete) and long-running, so the
MonitorableTask
methods should provide a way for the caller to monitor/cancel processing - i.e. the Annotator class should provide an indication of progress by callingAnnotator.setPercentComplete(Integer)
and should regularly checkAnnotator.isCancelling()
to determine if installation should be stopped.If the user should provide information before this method is called, a config web-app must be provided to implement the user interface, which sets any required configuration by invoking methods of the annotator as required, and invoking setConfig when configuration is ready.
If the configuration needs to be persistent between installing the annotator the first time and subsequently upgrading it, then it is the annotator's responsibility to serialize it in a form which can be retrieved for a later call to
getConfig()
.This implementation uses
Annotator.beanPropertiesFromQueryString(String)
to configure the bean properties from the query string.- Overrides:
setConfig
in classAnnotator
- Throws:
InvalidConfigurationException
- See Also:
getConfig()
,Annotator.beanPropertiesFromQueryString(String)
-
setTaskParameters
public void setTaskParameters(String parameters) throws InvalidConfigurationException
Sets the configuration for a given annotation task.- Specified by:
setTaskParameters
in classAnnotator
- Parameters:
parameters
- The configuration of the annotator; This annotator has no task parmeter web-app, so parameters will always be null.- Throws:
InvalidConfigurationException
-
getInputLayer
public String getInputLayer()
Getter forinputLayer
: ID of input layer.- Returns:
- ID of input layer.
-
setInputLayer
public TheWorksExample setInputLayer(String newInputLayer)
Setter forinputLayer
: ID of input layer.- Parameters:
newInputLayer
- ID of input layer.
-
getOutputLayer
public String getOutputLayer()
Getter foroutputLayer
: ID of output layer.- Returns:
- ID of output layer.
-
setOutputLayer
public TheWorksExample setOutputLayer(String newOutputLayer)
Setter foroutputLayer
: ID of output layer.- Parameters:
newOutputLayer
- ID of output layer.
-
getRequiredLayers
public String[] getRequiredLayers() throws InvalidConfigurationException
Determines which layers the annotator requires in order to annotate a graph.- Specified by:
getRequiredLayers
in classAnnotator
- Returns:
- A list of layer IDs. In this case, the annotator only requires the schema's word layer.
- Throws:
InvalidConfigurationException
- IfsetTaskParameters(String)
orAnnotator.setSchema(Schema)
have not yet been called.
-
getOutputLayers
public String[] getOutputLayers() throws InvalidConfigurationException
Determines which layers the annotator will create/update/delete annotations on.- Specified by:
getOutputLayers
in classAnnotator
- Returns:
- A list of layer IDs. In this case, the annotator has no task web-app for specifying an output layer, and doesn't update any layers, so this method returns an empty array.
- Throws:
InvalidConfigurationException
- IfsetTaskParameters(String)
orAnnotator.setSchema(Schema)
have not yet been called.
-
transform
public Graph transform(Graph graph) throws TransformationException
Transforms the graph. In this case, the graph is simply summarized, by counting all tokens of each word type, and printing out the result to stdout.- Specified by:
transform
in interfaceGraphTransformer
- Parameters:
graph
- The graph to transform.- Returns:
- The changes introduced by the tranformation.
- Throws:
TransformationException
- If the transformation cannot be completed.
-
getReverse
public Boolean getReverse()
Getter forreverse
: Reverse annotation labels setting.- Returns:
- Reverse annotation labels setting.
-
setReverse
public void setReverse(Boolean newReverse)
Setter forreverse
: Reverse annotation labels setting.- Parameters:
newReverse
- Reverse annotation labels setting.
-
getLeftPadding
public int getLeftPadding()
Getter forleftPadding
: How many spaces to add on the left.- Returns:
- How many spaces to add on the left.
-
setLeftPadding
public TheWorksExample setLeftPadding(int newLeftPadding)
Setter forleftPadding
: How many spaces to add on the left.- Parameters:
newLeftPadding
- How many spaces to add on the left.
-
getRightPadding
public Integer getRightPadding()
Getter forrightPadding
: How many spaces to add on the right.- Returns:
- How many spaces to add on the right.
-
setRightPadding
public TheWorksExample setRightPadding(Integer newRightPadding)
Setter forrightPadding
: How many spaces to add on the right.- Parameters:
newRightPadding
- How many spaces to add on the right.
-
setPadding
public void setPadding(int leftPadding, int rightPadding)
Sets the padding.- Parameters:
leftPadding
-rightPadding
-
-
getPrefix
public String getPrefix()
Getter forprefix
: Prefix to add.- Returns:
- Prefix to add.
-
setPrefix
public TheWorksExample setPrefix(String newPrefix)
Setter forprefix
: Prefix to add.- Parameters:
newPrefix
- Prefix to add.
-
getLabelConfidence
public Double getLabelConfidence()
Getter forlabelConfidence
: Value for annotator confidence.- Returns:
- Value for annotator confidence.
-
setLabelConfidence
public TheWorksExample setLabelConfidence(Double newLabelConfidence)
Setter forlabelConfidence
: Value for annotator confidence.- Parameters:
newLabelConfidence
- Value for annotator confidence.
-
uploadFile
public String uploadFile(File file)
Accepts an uploaded file.- Parameters:
file
- The file uploaded by the webapp.- Returns:
- null if upload was successful, an error message otherwise.
-
getSimulatedInstallationDuration
public Integer getSimulatedInstallationDuration()
Getter forsimulatedInstallationDuration
: How long, in seconds, the #setConfig(String) method should take to return.- Returns:
- How long, in seconds, the #setConfig(String) method should take to return.
-
setSimulatedInstallationDuration
public TheWorksExample setSimulatedInstallationDuration(Integer newSimulatedInstallationDuration)
Setter forsimulatedInstallationDuration
: How long, in seconds, the #setConfig(String) method should take to return.- Parameters:
newSimulatedInstallationDuration
- How long, in seconds, the #setConfig(String) method should take to return.
-
getDictionaryIds
public List<String> getDictionaryIds()
Lists the dictionaries implemented by this Annotator.This method can assume that the following methods have been previously called:
- Specified by:
getDictionaryIds
in interfaceImplementsDictionaries
- Returns:
- A (possibly empty) list of IDs of dictionaries.
-
getDictionary
public Dictionary getDictionary(String id) throws DictionaryException
Gets the identified dictionary.This method can assume that the following methods have been previously called:
- Specified by:
getDictionary
in interfaceImplementsDictionaries
- Parameters:
id
- The indentifier of the desired dictionary. This can be null if the Annotator supports only one dictionary, or the Annotator has already been configured (e.g. viaAnnotator.setTaskParameters(String)
sufficiently to know which dictionary to return.- Returns:
- The identified dictionary.
- Throws:
DictionaryException
- If the given dictionary doesn't exist.
-
-