gate.creole
Class Transducer

java.lang.Object
  extended by gate.util.AbstractFeatureBearer
      extended by gate.creole.AbstractResource
          extended by gate.creole.AbstractProcessingResource
              extended by gate.creole.AbstractLanguageAnalyser
                  extended by gate.creole.Transducer
All Implemented Interfaces:
ANNIEConstants, ControllerAwarePR, Executable, ActionsPublisher, LanguageAnalyser, ProcessingResource, Resource, Benchmarkable, FeatureBearer, NameBearer, Serializable
Direct Known Subclasses:
ANNIETransducer, OntologyAwareTransducer, VPChunker

@CreoleResource(name="JAPE Transducer",
                comment="A module for executing Jape grammars.",
                helpURL="http://gate.ac.uk/userguide/chap:jape",
                icon="jape")
public class Transducer
extends AbstractLanguageAnalyser
implements ActionsPublisher, Benchmarkable, ControllerAwarePR

A cascaded multi-phase transducer using the Jape language which is a variant of the CPSL language.

See Also:
Serialized Form

Nested Class Summary
protected  class Transducer.SerializeTransducerAction
          Saves the Jape Transuder to the binary file.
 
Nested classes/interfaces inherited from class gate.creole.AbstractProcessingResource
AbstractProcessingResource.InternalStatusListener, AbstractProcessingResource.IntervalProgressListener
 
Field Summary
protected  DefaultActionContext actionContext
           
protected  List<Action> actionList
           
protected  List<String> annotationAccessors
          List of class names for any custom AnnotationAccessors.
protected  Batch batch
          The actual JapeTransducer used for processing the document(s).
protected  URL binaryGrammarURL
          The URL to the serialized jape file used as grammar by this transducer.
protected  Boolean enableDebugging
          A switch used to activate the JAPE debugger.
protected  String encoding
          The encoding used for reding the grammar file(s).
protected  URL grammarURL
          The URL to the jape file used as grammar by this transducer.
protected  String inputASName
          The AnnotationSet used as input for the transducer.
protected  Ontology ontology
          The ontology that will be available on the RHS of JAPE rules.
protected  List<String> operators
          List of class names for any custom ConstraintPredicate.
protected  String outputASName
          The AnnotationSet used as output by the transducer.
static String TRANSD_ANNOTATION_ACCESSORS_PARAMETER_NAME
           
static String TRANSD_BINARY_GRAMMAR_URL_PARAMETER_NAME
           
static String TRANSD_DOCUMENT_PARAMETER_NAME
           
static String TRANSD_ENCODING_PARAMETER_NAME
           
static String TRANSD_GRAMMAR_URL_PARAMETER_NAME
           
static String TRANSD_INPUT_AS_PARAMETER_NAME
           
static String TRANSD_OPERATORS_PARAMETER_NAME
           
static String TRANSD_OUTPUT_AS_PARAMETER_NAME
           
 
Fields inherited from class gate.creole.AbstractLanguageAnalyser
corpus, document
 
Fields inherited from class gate.creole.AbstractProcessingResource
interrupted
 
Fields inherited from class gate.creole.AbstractResource
name
 
Fields inherited from class gate.util.AbstractFeatureBearer
features
 
Fields inherited from interface gate.creole.ANNIEConstants
ANNOTATION_COREF_FEATURE_NAME, DATE_ANNOTATION_TYPE, DATE_POSTED_ANNOTATION_TYPE, DEFAULT_FILE, DOCUMENT_COREF_FEATURE_NAME, JOB_ID_ANNOTATION_TYPE, LOCATION_ANNOTATION_TYPE, LOOKUP_ANNOTATION_TYPE, LOOKUP_CLASS_FEATURE_NAME, LOOKUP_INSTANCE_FEATURE_NAME, LOOKUP_LANGUAGE_FEATURE_NAME, LOOKUP_MAJOR_TYPE_FEATURE_NAME, LOOKUP_MINOR_TYPE_FEATURE_NAME, LOOKUP_ONTOLOGY_FEATURE_NAME, MONEY_ANNOTATION_TYPE, ORGANIZATION_ANNOTATION_TYPE, PERSON_ANNOTATION_TYPE, PERSON_GENDER_FEATURE_NAME, PLUGIN_DIR, PR_NAMES, SENTENCE_ANNOTATION_TYPE, SPACE_TOKEN_ANNOTATION_TYPE, TOKEN_ANNOTATION_TYPE, TOKEN_CATEGORY_FEATURE_NAME, TOKEN_KIND_FEATURE_NAME, TOKEN_LENGTH_FEATURE_NAME, TOKEN_ORTH_FEATURE_NAME, TOKEN_STRING_FEATURE_NAME
 
Constructor Summary
Transducer()
          Default constructor.
 
Method Summary
 void controllerExecutionAborted(Controller c, Throwable t)
          Called by a controller containing this PR when the controller's execution has been aborted by an exception thrown by one of the contained PR's execute methods, or by the controller itself.
 void controllerExecutionFinished(Controller c)
          Called by a controller containing this PR when the controller's execution has completed successfully.
 void controllerExecutionStarted(Controller c)
          Called by a controller containing this PR when the controller begins executing.
 void execute()
          Implementation of the run() method from Runnable.
 List<Action> getActions()
          Gets the list of actions that can be performed on this resource.
 List<String> getAnnotationAccessors()
          Gets the list of class names for any custom AnnotationAccessors.
 String getBenchmarkId()
          Get the benchmark ID of this Transducers batch.
 URL getBinaryGrammarURL()
           
 Boolean getEnableDebugging()
           
 String getEncoding()
          Gets the encoding used for reding the grammar file(s).
 URL getGrammarURL()
          Gets the URL to the grammar used to build this transducer.
 String getInputASName()
          Gets the AnnotationSet used as input by this transducer.
 Ontology getOntology()
          Gets the ontology used by this transducer.
 List<String> getOperators()
          Gets the list of class names for any custom boolean operators.
 String getOutputASName()
          Gets the AnnotationSet used as output by this transducer.
 Resource init()
          This method is the one responsible for initialising the transducer.
protected  void initCustomConstraints()
          Loads any custom operators and annotation accessors into the ConstraintFactory.
 void interrupt()
          Notifies all the PRs in this controller that they should stop their execution as soon as possible.
 void setAnnotationAccessors(List<String> annotationAccessors)
          Sets the list of class names for any custom AnnotationAccessors.
 void setBenchmarkId(String benchmarkId)
          Set the benchmark ID of this PR.
 void setBinaryGrammarURL(URL binaryGrammarURL)
           
 void setEnableDebugging(Boolean enableDebugging)
           
 void setEncoding(String newEncoding)
          Sets the encoding to be used for reding the input file(s) forming the Jape grammar.
 void setGrammarURL(URL newGrammarURL)
          Sets the grammar to be used for building this transducer.
 void setInputASName(String newInputASName)
          Sets the AnnotationSet to be used as input for the transducer.
 void setOntology(Ontology ontology)
          Sets the ontology used by this transducer.
 void setOperators(List<String> operators)
          Sets the list of class names for any custom boolean operators.
 void setOutputASName(String newOutputASName)
          Sets the AnnotationSet to be used as output by the transducer.
 
Methods inherited from class gate.creole.AbstractLanguageAnalyser
getCorpus, getDocument, setCorpus, setDocument
 
Methods inherited from class gate.creole.AbstractProcessingResource
addProgressListener, addStatusListener, cleanup, fireProcessFinished, fireProgressChanged, fireStatusChanged, isInterrupted, reInit, removeProgressListener, removeStatusListener
 
Methods inherited from class gate.creole.AbstractResource
checkParameterValues, getBeanInfo, getName, getParameterValue, getParameterValue, removeResourceListeners, setName, setParameterValue, setParameterValue, setParameterValues, setParameterValues, setResourceListeners
 
Methods inherited from class gate.util.AbstractFeatureBearer
getFeatures, setFeatures
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface gate.ProcessingResource
reInit
 
Methods inherited from interface gate.Resource
cleanup, getParameterValue, setParameterValue, setParameterValues
 
Methods inherited from interface gate.util.FeatureBearer
getFeatures, setFeatures
 
Methods inherited from interface gate.util.NameBearer
getName, setName
 
Methods inherited from interface gate.Executable
isInterrupted
 

Field Detail

TRANSD_DOCUMENT_PARAMETER_NAME

public static final String TRANSD_DOCUMENT_PARAMETER_NAME
See Also:
Constant Field Values

TRANSD_INPUT_AS_PARAMETER_NAME

public static final String TRANSD_INPUT_AS_PARAMETER_NAME
See Also:
Constant Field Values

TRANSD_OUTPUT_AS_PARAMETER_NAME

public static final String TRANSD_OUTPUT_AS_PARAMETER_NAME
See Also:
Constant Field Values

TRANSD_ENCODING_PARAMETER_NAME

public static final String TRANSD_ENCODING_PARAMETER_NAME
See Also:
Constant Field Values

TRANSD_GRAMMAR_URL_PARAMETER_NAME

public static final String TRANSD_GRAMMAR_URL_PARAMETER_NAME
See Also:
Constant Field Values

TRANSD_BINARY_GRAMMAR_URL_PARAMETER_NAME

public static final String TRANSD_BINARY_GRAMMAR_URL_PARAMETER_NAME
See Also:
Constant Field Values

TRANSD_OPERATORS_PARAMETER_NAME

public static final String TRANSD_OPERATORS_PARAMETER_NAME
See Also:
Constant Field Values

TRANSD_ANNOTATION_ACCESSORS_PARAMETER_NAME

public static final String TRANSD_ANNOTATION_ACCESSORS_PARAMETER_NAME
See Also:
Constant Field Values

actionList

protected List<Action> actionList

actionContext

protected DefaultActionContext actionContext

grammarURL

protected URL grammarURL
The URL to the jape file used as grammar by this transducer.


binaryGrammarURL

protected URL binaryGrammarURL
The URL to the serialized jape file used as grammar by this transducer.


batch

protected Batch batch
The actual JapeTransducer used for processing the document(s).


encoding

protected String encoding
The encoding used for reding the grammar file(s).


inputASName

protected String inputASName
The AnnotationSet used as input for the transducer.


outputASName

protected String outputASName
The AnnotationSet used as output by the transducer.


ontology

protected Ontology ontology
The ontology that will be available on the RHS of JAPE rules.


operators

protected List<String> operators
List of class names for any custom ConstraintPredicate.


annotationAccessors

protected List<String> annotationAccessors
List of class names for any custom AnnotationAccessors.


enableDebugging

protected Boolean enableDebugging
A switch used to activate the JAPE debugger.

Constructor Detail

Transducer

public Transducer()
Default constructor. Does nothing apart from calling the default constructor from the super class. The actual object initialisation is done via the init() method.

Method Detail

init

public Resource init()
              throws ResourceInstantiationException
This method is the one responsible for initialising the transducer. It assumes that all the needed parameters have been already set using the appropiate setXXX() methods.

Specified by:
init in interface Resource
Overrides:
init in class AbstractProcessingResource
Returns:
a reference to this
Throws:
ResourceInstantiationException

execute

public void execute()
             throws ExecutionException
Implementation of the run() method from Runnable. This method is responsible for doing all the processing of the input document.

Specified by:
execute in interface Executable
Overrides:
execute in class AbstractProcessingResource
Throws:
ExecutionException

getActions

public List<Action> getActions()
Gets the list of actions that can be performed on this resource.

Specified by:
getActions in interface ActionsPublisher
Returns:
a List of Action objects (or null values)

initCustomConstraints

protected void initCustomConstraints()
                              throws ResourceInstantiationException
Loads any custom operators and annotation accessors into the ConstraintFactory.

Throws:
ResourceInstantiationException

interrupt

public void interrupt()
Notifies all the PRs in this controller that they should stop their execution as soon as possible.

Specified by:
interrupt in interface Executable
Overrides:
interrupt in class AbstractProcessingResource

setGrammarURL

@CreoleParameter(comment="The URL to the grammar file.",
                 suffixes="jape",
                 disjunction="grammar",
                 priority=1)
public void setGrammarURL(URL newGrammarURL)
Sets the grammar to be used for building this transducer.

Parameters:
newGrammarURL - an URL to a file containing a Jape grammar.

getGrammarURL

public URL getGrammarURL()
Gets the URL to the grammar used to build this transducer.

Returns:
a URL pointing to the grammar file.

setEncoding

@CreoleParameter(comment="The encoding used for reading the grammar",
                 defaultValue="UTF-8")
public void setEncoding(String newEncoding)
Sets the encoding to be used for reding the input file(s) forming the Jape grammar. Note that if the input grammar is a multi-file one than the same encoding will be used for reding all the files. Multi file grammars with different encoding across the composing files are not supported!

Parameters:
newEncoding - a {link String} representing the encoding.

getEncoding

public String getEncoding()
Gets the encoding used for reding the grammar file(s).


setInputASName

@RunTime
@Optional
@CreoleParameter(comment="The annotation set to be used as input for the transducer")
public void setInputASName(String newInputASName)
Sets the AnnotationSet to be used as input for the transducer.

Parameters:
newInputASName - a AnnotationSet

getInputASName

public String getInputASName()
Gets the AnnotationSet used as input by this transducer.

Returns:
a AnnotationSet

setOutputASName

@RunTime
@Optional
@CreoleParameter(comment="The annotation set to be used as output for the transducer")
public void setOutputASName(String newOutputASName)
Sets the AnnotationSet to be used as output by the transducer.

Parameters:
newOutputASName - a AnnotationSet

getOutputASName

public String getOutputASName()
Gets the AnnotationSet used as output by this transducer.

Returns:
a AnnotationSet

getEnableDebugging

public Boolean getEnableDebugging()

setEnableDebugging

public void setEnableDebugging(Boolean enableDebugging)

getOperators

public List<String> getOperators()
Gets the list of class names for any custom boolean operators. Classes must implement ConstraintPredicate.


setOperators

@Optional
@CreoleParameter(comment="Class names that implement gate.jape.constraint.ConstraintPredicate.")
public void setOperators(List<String> operators)
Sets the list of class names for any custom boolean operators. Classes must implement ConstraintPredicate.


getAnnotationAccessors

public List<String> getAnnotationAccessors()
Gets the list of class names for any custom AnnotationAccessors.


setAnnotationAccessors

@Optional
@CreoleParameter(comment="Class names that implement gate.jape.constraint.AnnotationAccessor.")
public void setAnnotationAccessors(List<String> annotationAccessors)
Sets the list of class names for any custom AnnotationAccessors.


getBenchmarkId

public String getBenchmarkId()
Get the benchmark ID of this Transducers batch.

Specified by:
getBenchmarkId in interface Benchmarkable
Returns:

setBenchmarkId

public void setBenchmarkId(String benchmarkId)
Set the benchmark ID of this PR.

Specified by:
setBenchmarkId in interface Benchmarkable
Parameters:
benchmarkId - the benchmark ID, which must not contain spaces as it is already used as a separator in the log, you can use Benchmark.createBenchmarkId(String, String) for it.

getOntology

public Ontology getOntology()
Gets the ontology used by this transducer.

Returns:
an Ontology value.

setOntology

@RunTime
@Optional
@CreoleParameter(comment="The ontology to be used by this transducer")
public void setOntology(Ontology ontology)
Sets the ontology used by this transducer.

Parameters:
ontology - an Ontology value.

getBinaryGrammarURL

public URL getBinaryGrammarURL()

setBinaryGrammarURL

@CreoleParameter(comment="The URL to the binary grammar file.",
                 suffixes="jape",
                 disjunction="grammar",
                 priority=100)
public void setBinaryGrammarURL(URL binaryGrammarURL)

controllerExecutionStarted

public void controllerExecutionStarted(Controller c)
                                throws ExecutionException
Description copied from interface: ControllerAwarePR
Called by a controller containing this PR when the controller begins executing. When this method is called, it is guaranteed that none of the PRs in this controller have yet been executed on this run.

Specified by:
controllerExecutionStarted in interface ControllerAwarePR
Parameters:
c - the Controller that is executing.
Throws:
ExecutionException - if an error occurs that requires the controller to abort its execution.

controllerExecutionFinished

public void controllerExecutionFinished(Controller c)
                                 throws ExecutionException
Description copied from interface: ControllerAwarePR
Called by a controller containing this PR when the controller's execution has completed successfully. When this method is called, it is guaranteed that there will be no more calls to the execute method of any of this controller's PRs in this run.

Specified by:
controllerExecutionFinished in interface ControllerAwarePR
Parameters:
c - the Controller that is executing.
Throws:
ExecutionException - if an error occurs that requires the controller to abort its execution.

controllerExecutionAborted

public void controllerExecutionAborted(Controller c,
                                       Throwable t)
                                throws ExecutionException
Description copied from interface: ControllerAwarePR
Called by a controller containing this PR when the controller's execution has been aborted by an exception thrown by one of the contained PR's execute methods, or by the controller itself. When this method is called, it is guaranteed that there will be no more calls to the execute method of any of this controller's PRs in this run.

Specified by:
controllerExecutionAborted in interface ControllerAwarePR
Parameters:
c - the Controller that is executing.
t - the Throwable that caused the controller to abort. This will be either an ExecutionException, a RuntimeException or an Error.
Throws:
ExecutionException - if an error occurs in this method that requires the controller to abort its execution. This method should not rethrow t, as the controller will do this after informing any other ControllerAware PRs it contains.