gate.jape
Class SinglePhaseTransducer

java.lang.Object
  extended by gate.jape.Transducer
      extended by gate.jape.SinglePhaseTransducer
All Implemented Interfaces:
JapeConstants, Benchmarkable, Serializable

public class SinglePhaseTransducer
extends Transducer
implements JapeConstants, Serializable

Represents a complete CPSL grammar, with a phase name, options and rule set (accessible by name and by sequence). Implements a transduce method taking a Document as input. Constructs from String or File.

See Also:
Serialized Form

Nested Class Summary
protected static class SinglePhaseTransducer.SearchState
           
 
Field Summary
protected  List<FSMInstance> activeFSMInstances
          A list of FSM instances that haven't blocked yet, used during matching.
protected  boolean finishedAlready
          Whether the finish method has been called or not.
protected  FSM fsm
           
 Set input
          Defines the types of input annotations that this transducer reads.
protected static org.apache.log4j.Logger log
           
protected  int ruleApplicationStyle
          Type of rule application (constants defined in JapeConstants).
protected  PrioritisedRuleList rules
          The list of rules in this transducer.
 
Fields inherited from class gate.jape.Transducer
actionContext, benchmarkFeatures, benchmarkID, enableDebugging, interrupted, name, ontology
 
Fields inherited from interface gate.jape.JapeConstants
ALL_STYLE, APPELT_STYLE, BRILL_STYLE, DEFAULT_PRIORITY, FIRST_STYLE, INDENT_PADDING, KLEENE_PLUS, KLEENE_QUERY, KLEENE_STAR, MULTI_SPAN_BINDING, NO_BINDING, NO_KLEENE_OP, ONCE_STYLE, SINGLE_SPAN_BINDING
 
Constructor Summary
SinglePhaseTransducer(String name)
          Construction from name.
 
Method Summary
 void addInput(String ident)
          Adds a new type of input annotations used by this transducer.
 void addProgressListener(ProgressListener l)
           
 void addRule(Rule rule)
          Add a rule.
 void cleanUp()
          Clean up (delete action class files, for e.g.).
protected  FSM createFSM()
           
 void finish()
          Finish: replace dynamic data structures with Java arrays; called after parsing.
protected  void fireProcessFinished()
           
protected  void fireProgressChanged(int e)
          This property affects the Appelt style of rules application.
protected  boolean fireRule(List<FSMInstance> acceptingFSMInstances, SinglePhaseTransducer.SearchState state, long lastNodeOff, SimpleSortedSet offsets, AnnotationSet inputAS, AnnotationSet outputAS, Document doc, SimpleSortedSet annotationsByOffset)
          Fire the rule that matched.
 String generateControllerEventBlocksCode(String started, String finished, String aborted, String javaimports)
           
 ControllerEventBlocksAction getControllerEventBlocksActionClass()
          This returns any compiled controller event blocks action class that may exist at the time of calling or null.
 FSM getFSM()
           
 String getOption(String name)
          Get the value for a particular option.
protected  Annotation getRightMostAnnotation(Collection<Annotation> annots)
          Return the annotation with the right-most end node
 int getRuleApplicationStyle()
           
 PrioritisedRuleList getRules()
           
 boolean hasInput(String ident)
          Checks if this Phase has the annotation type as input.
 boolean isInputRestricted()
          Check if there is a restriction on the input annotation types for this SPT, i.e. if there were annotation types specified for the "Input:" declaration of this phase.
 void removeProgressListener(ProgressListener l)
           
 void runControllerExecutionAbortedBlock(ActionContext ac, Controller c, Throwable t, Ontology o)
           
 void runControllerExecutionFinishedBlock(ActionContext ac, Controller c, Ontology o)
           
 void runControllerExecutionStartedBlock(ActionContext ac, Controller c, Ontology o)
           
 void setControllerEventBlocks(String started, String finished, String aborted, String javaimports)
           
 void setOption(String name, String setting)
          Add an option setting.
 void setRuleApplicationStyle(int style)
          Set the type of rule application (types defined in JapeConstants).
 String toString()
          A string representation of this object.
 String toString(String pad)
          A string representation of this object.
 void transduce(Document doc, AnnotationSet inputAS, AnnotationSet outputAS)
          Transduce a document using the annotation set provided and the current rule application style.
 
Methods inherited from class gate.jape.Transducer
addStatusListener, fireStatusChanged, getBaseURL, getBenchmarkId, getName, getOntology, interrupt, isDebugMode, isEnableDebugging, isInterrupted, isMatchGroupMode, removeStatusListener, setActionContext, setBaseURL, setBenchmarkId, setDebugMode, setEnableDebugging, setMatchGroupMode, setOntology
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

protected static final org.apache.log4j.Logger log

ruleApplicationStyle

protected int ruleApplicationStyle
Type of rule application (constants defined in JapeConstants).


rules

protected PrioritisedRuleList rules
The list of rules in this transducer. Ordered by priority and addition sequence (which will be file position if they come from a file).


fsm

protected FSM fsm

activeFSMInstances

protected List<FSMInstance> activeFSMInstances
A list of FSM instances that haven't blocked yet, used during matching.


finishedAlready

protected boolean finishedAlready
Whether the finish method has been called or not.


input

public Set input
Defines the types of input annotations that this transducer reads. If this set is empty the transducer will read all the annotations otherwise it will only "see" the annotations of types found in this list ignoring all other types of annotations.

Constructor Detail

SinglePhaseTransducer

public SinglePhaseTransducer(String name)
Construction from name.

Method Detail

setRuleApplicationStyle

public void setRuleApplicationStyle(int style)
Set the type of rule application (types defined in JapeConstants).


getFSM

public FSM getFSM()

addRule

public void addRule(Rule rule)
Add a rule.


setOption

public void setOption(String name,
                      String setting)
Add an option setting. If this option is set already, the new value overwrites the previous one.


getOption

public String getOption(String name)
Get the value for a particular option.


finish

public void finish()
Finish: replace dynamic data structures with Java arrays; called after parsing.

Specified by:
finish in class Transducer

createFSM

protected FSM createFSM()

transduce

public void transduce(Document doc,
                      AnnotationSet inputAS,
                      AnnotationSet outputAS)
               throws JapeException,
                      ExecutionException
Transduce a document using the annotation set provided and the current rule application style.

Specified by:
transduce in class Transducer
Throws:
JapeException
ExecutionException

getRightMostAnnotation

protected Annotation getRightMostAnnotation(Collection<Annotation> annots)
Return the annotation with the right-most end node

Parameters:
annots -
Returns:

fireRule

protected boolean fireRule(List<FSMInstance> acceptingFSMInstances,
                           SinglePhaseTransducer.SearchState state,
                           long lastNodeOff,
                           SimpleSortedSet offsets,
                           AnnotationSet inputAS,
                           AnnotationSet outputAS,
                           Document doc,
                           SimpleSortedSet annotationsByOffset)
                    throws JapeException,
                           ExecutionException
Fire the rule that matched.

Returns:
true if processing should keep going, false otherwise.
Throws:
JapeException
ExecutionException

cleanUp

public void cleanUp()
Clean up (delete action class files, for e.g.).

Specified by:
cleanUp in class Transducer

toString

public String toString()
A string representation of this object.

Overrides:
toString in class Object

toString

public String toString(String pad)
A string representation of this object.

Specified by:
toString in class Transducer

getRules

public PrioritisedRuleList getRules()

addInput

public void addInput(String ident)
Adds a new type of input annotations used by this transducer. If the list of input types is empty this transducer will parse all the annotations in the document otherwise the types not found in the input list will be completely ignored! To be used with caution!


hasInput

public boolean hasInput(String ident)
Checks if this Phase has the annotation type as input. This is the case if either no input annotation types were specified, in which case all annotation types will be used, or if the annotation type was specified.

Parameters:
ident - the type of an annotation to be checked
Returns:
true if the annotation type will be used in this phase

isInputRestricted

public boolean isInputRestricted()
Check if there is a restriction on the input annotation types for this SPT, i.e. if there were annotation types specified for the "Input:" declaration of this phase.

Returns:
true if only certain annotation types are considered in this phase, false if all are considered.

removeProgressListener

public void removeProgressListener(ProgressListener l)
Overrides:
removeProgressListener in class Transducer

addProgressListener

public void addProgressListener(ProgressListener l)
Overrides:
addProgressListener in class Transducer

fireProgressChanged

protected void fireProgressChanged(int e)
Description copied from class: Transducer
This property affects the Appelt style of rules application. If true then the longest match will be fired otherwise the shortest will be used. By default it is true.

Overrides:
fireProgressChanged in class Transducer

fireProcessFinished

protected void fireProcessFinished()
Overrides:
fireProcessFinished in class Transducer

getRuleApplicationStyle

public int getRuleApplicationStyle()

setControllerEventBlocks

public void setControllerEventBlocks(String started,
                                     String finished,
                                     String aborted,
                                     String javaimports)

generateControllerEventBlocksCode

public String generateControllerEventBlocksCode(String started,
                                                String finished,
                                                String aborted,
                                                String javaimports)

runControllerExecutionStartedBlock

public void runControllerExecutionStartedBlock(ActionContext ac,
                                               Controller c,
                                               Ontology o)
                                        throws ExecutionException
Throws:
ExecutionException

runControllerExecutionFinishedBlock

public void runControllerExecutionFinishedBlock(ActionContext ac,
                                                Controller c,
                                                Ontology o)
                                         throws ExecutionException
Throws:
ExecutionException

runControllerExecutionAbortedBlock

public void runControllerExecutionAbortedBlock(ActionContext ac,
                                               Controller c,
                                               Throwable t,
                                               Ontology o)
                                        throws ExecutionException
Throws:
ExecutionException

getControllerEventBlocksActionClass

public ControllerEventBlocksAction getControllerEventBlocksActionClass()
This returns any compiled controller event blocks action class that may exist at the time of calling or null. This is mainly needed for alternate implementations of JAPE that are based on the core JAPE classes and want to support controller event blocks too.

Returns:
an object that represents the compiled event blocks or null