Parsing Engine

danbikel.parser
Class EventCountsConsumer

java.lang.Object
  extended by danbikel.parser.EventCountsConsumer
All Implemented Interfaces:
Consumer, Runnable, Remote

public class EventCountsConsumer
extends Object
implements Consumer, Runnable

An implementation of the Consumer interface (part of the Switchboard framework) for counting events (TrainerEvent instances) produced as part of the E-step of the EM algorithm (Inside-Outside). Each NumberedObject consumed by this consumer is expected to contain a CountsTable containing the expected counts of TrainerEvent instances.


Field Summary
static int defaultWriteInterval
          The default writing interval for this consumer.
 
Constructor Summary
EventCountsConsumer()
          Constructs a new event counts consumer.
EventCountsConsumer(boolean asynchronousWrite)
          Constructs a new event counts consumer.
EventCountsConsumer(boolean asynchronousWrite, boolean strictWriteInterval)
          Constructs a new event counts consumer.
 
Method Summary
 void consume(NumberedObject obj)
          Tells this consumer to consume the specified object that has been processed by one of the switchboard's clients.
 void consumeForDumper(NumberedObject obj)
          A helper method used by consume(NumberedObject) to perform consumption of objects that are periodicially written to an output file by a separate “dumper” thread.
 void dontUseCountThreshold()
          Indicates not to use the count threshold specified by Settings.countThreshold.
 int getWriteInterval()
          Gets the write interval for this consumer.
 void newFile(String inputFilename, String outputFilename)
          Indicates that the consumer is about to be consuming objects from the specified input file.
 void processingComplete(String inputFilename, String outputFilename)
          Indicates that there are no more sentences whose event counts are to be consumed.
 void run()
          Allows this object to used as a “dumper” thread for periodically writing consumed objects to an output file.
 void setWriteInterval(int writeInterval)
          Sets the write interval for this consumer.
 void useCountThreshold()
          Indicates to use the count threshold specified by Settings.countThreshold, which means that events below that threshold will be removed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultWriteInterval

public static final int defaultWriteInterval
The default writing interval for this consumer.

See Also:
Constant Field Values
Constructor Detail

EventCountsConsumer

public EventCountsConsumer()
Constructs a new event counts consumer. Writing out consumed event counts to the output file will occur asynchronously (that is, in parallel) with the consumption of new event counts. Writing to the output file will occur periodicially, occurring sometime after aggregate event counts have been collected from at least getWriteInterval() sentences.


EventCountsConsumer

public EventCountsConsumer(boolean asynchronousWrite)
Constructs a new event counts consumer. If the value of the asynchronousWrite parameter is true, then event counts will be aggregated in an internal CountsTable, and after event counts have been aggregated from at least getWriteInterval() sentences, the events and their aggregate counts will be passed off to a separate thread for appending to the current output file. This appending will happen in parallel with the consumption of new events in a freshly-cleared CountsTable.

Parameters:
asynchronousWrite - indicates whether or not to append event counts to the output file asynchronously (that is, in parallel) with the consumption of new event counts

EventCountsConsumer

public EventCountsConsumer(boolean asynchronousWrite,
                           boolean strictWriteInterval)
Constructs a new event counts consumer. If the value of the asynchronousWrite parameter is true, then event counts will be aggregated in an internal CountsTable, and at periodic intervals, the aggregated event counts will be passed off to a separate thread for appending to the current output file. This appending will happen in parallel with the consumption of new events in a freshly-cleared CountsTable. The interval between writing to the output file is determined by the value of getWriteInterval(). If asynchronousWrite is true and the strictWriteInterval parameter is true, then it is guaranteed that the internal counts table will contain aggregate counts from exactly getWriteInterval() sentences before being handed off to the output thread. If the strictWriteInterval parameter is false, then the internal counts table will contain events from at least getWriteInterval() sentences. If the asynchronousWrite parameter is false then the value of the strictWriteInterval parameter will be ignored.

Parameters:
asynchronousWrite - indicates whether or not to append event counts to the output file asynchronously (that is, in parallel) with the consumption of new event counts
strictWriteInterval - if asynchronousWrite is true and this parameter is true, then it is guaranteed that the internal counts table will contain aggregate counts from exactly getWriteInterval() sentences before being handed off to the output thread; if this parameter is false, then the internal counts table will contain events from at least getWriteInterval() sentences; if the asynchronousWrite parameter is false then the value of this parameter will be ignored
Method Detail

getWriteInterval

public int getWriteInterval()
Gets the write interval for this consumer.


setWriteInterval

public void setWriteInterval(int writeInterval)
Sets the write interval for this consumer.


useCountThreshold

public void useCountThreshold()
Indicates to use the count threshold specified by Settings.countThreshold, which means that events below that threshold will be removed.


dontUseCountThreshold

public void dontUseCountThreshold()
Indicates not to use the count threshold specified by Settings.countThreshold.


newFile

public void newFile(String inputFilename,
                    String outputFilename)
Description copied from interface: Consumer
Indicates that the consumer is about to be consuming objects from the specified input file. The name of the output filename is also a parameter, in case the consumer needs to create an output file when this method is invoked.

Specified by:
newFile in interface Consumer
Parameters:
inputFilename - the name of the input file for which object processing has commenced
outputFilename - the name of the (optional) output file to be created from the specified input file

consume

public void consume(NumberedObject obj)
Description copied from interface: Consumer
Tells this consumer to consume the specified object that has been processed by one of the switchboard's clients.

Specified by:
consume in interface Consumer
Parameters:
obj - the processed switchboard object to be consumed by this consumer instance

consumeForDumper

public void consumeForDumper(NumberedObject obj)
A helper method used by consume(NumberedObject) to perform consumption of objects that are periodicially written to an output file by a separate “dumper” thread. This method is only used if the asynchronousWrite argument to one of the constructors is true.

Parameters:
obj - the object to be consumed

processingComplete

public void processingComplete(String inputFilename,
                               String outputFilename)
Indicates that there are no more sentences whose event counts are to be consumed. If this consumer was constructed to have asynchronous writing, then any remaining aggregate counts in the internal CountsTable will be appended to the output file before this method exits.

Specified by:
processingComplete in interface Consumer
Parameters:
inputFilename - the input file for which event counts have been consumed
outputFilename - the output file for consumed event counts

run

public void run()
Allows this object to used as a “dumper” thread for periodically writing consumed objects to an output file. A dumper thread is only created when the asynchronousWrite argument of the constructors that take such an argument is true, or if the default constructor is used. A dumper thread is created by newFile(String, String).

Specified by:
run in interface Runnable
See Also:
EventCountsConsumer(), EventCountsConsumer(boolean), EventCountsConsumer(boolean,boolean), newFile(String,String)

Parsing Engine

Author: Dan Bikel.