edu.stanford.nlp.ie
Class EntityCachingAbstractSequencePrior<IN extends CoreMap>

java.lang.Object
  extended by edu.stanford.nlp.ie.EntityCachingAbstractSequencePrior<IN>
All Implemented Interfaces:
SequenceListener, SequenceModel
Direct Known Subclasses:
AcquisitionsPrior, EmpiricalNERPrior, SeminarsPrior

public abstract class EntityCachingAbstractSequencePrior<IN extends CoreMap>
extends Object
implements SequenceModel, SequenceListener

This class keeps track of all labeled entities and updates the its list whenever the label at a point gets changed. This allows you to not have to regereate the list everytime, which can be quite inefficient.

Author:
Jenny Finkel

Field Summary
protected  int backgroundSymbol
           
protected  Index<String> classIndex
           
protected  List<IN> doc
           
protected  int numClasses
           
protected  int[] possibleValues
           
protected  int[] sequence
           
 
Constructor Summary
EntityCachingAbstractSequencePrior(String backgroundSymbol, Index<String> classIndex, List<IN> doc)
           
 
Method Summary
 boolean addingSingletonEntity(int[] sequence, int position)
           
 boolean appendingEntity(int[] sequence, int position)
           
 edu.stanford.nlp.ie.Entity extractEntity(int[] sequence, int position)
          extracts the entity starting at the given position and adds it to the entity list.
 double[] getConditionalDistribution(int[] sequence, int position)
           
 int getNumClasses()
          get the number of classes in the sequence model.
 int[] getPossibleValues(int position)
          0...leftWindow-1 etc are null, leftWindow...length+leftWindow-1 are words, length+leftWindow...length+leftWindow+rightWindow-1 are null;
 boolean joiningTwoEntities(int[] sequence, int position)
           
 int leftWindow()
          How many positions to the left a position is dependent on.
 int length()
           
 boolean matches(edu.stanford.nlp.ie.Entity entity, int position)
           
 boolean noChange(int[] sequence, int position)
           
 int[] otherOccurrences(edu.stanford.nlp.ie.Entity entity)
          finds other locations in the sequence where the sequence of words in this entity occurs.
 boolean prependingEntity(int[] sequence, int position)
           
 boolean removingBeginningOfEntity(int[] sequence, int position)
           
 boolean removingEndOfEntity(int[] sequence, int position)
           
 int rightWindow()
          How many positions to the right a position is dependent on.
 double scoreOf(int[] sequence, int pos)
          Computes the unnormalized log conditional distribution over values of the element at position pos in the sequence, conditioned on the values of the elements in all other positions of the provided sequence.
 double[] scoresOf(int[] sequence, int position)
          Computes the unnormalized log conditional distribution over values of the element at position pos in the sequence, conditioned on the values of the elements in all other positions of the provided sequence.
 void setInitialSequence(int[] initialSequence)
          Informs this sequence listener that the value of the whole sequence is initialized to sequence
 boolean splittingTwoEntities(int[] sequence, int position)
           
static int[] toArray(List<Integer> list)
           
 String toString()
           
 String toString(int pos)
           
 void updateSequenceElement(int[] sequence, int position, int oldVal)
          Informs this sequence listener that the value of the element at position pos has changed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface edu.stanford.nlp.sequences.SequenceModel
scoreOf
 

Field Detail

sequence

protected int[] sequence

backgroundSymbol

protected int backgroundSymbol

numClasses

protected int numClasses

possibleValues

protected int[] possibleValues

classIndex

protected Index<String> classIndex

doc

protected List<IN extends CoreMap> doc
Constructor Detail

EntityCachingAbstractSequencePrior

public EntityCachingAbstractSequencePrior(String backgroundSymbol,
                                          Index<String> classIndex,
                                          List<IN> doc)
Method Detail

leftWindow

public int leftWindow()
Description copied from interface: SequenceModel
How many positions to the left a position is dependent on.

Specified by:
leftWindow in interface SequenceModel
Returns:
the size of the left window used by this sequence model

rightWindow

public int rightWindow()
Description copied from interface: SequenceModel
How many positions to the right a position is dependent on.

Specified by:
rightWindow in interface SequenceModel
Returns:
the size of the right window used by this sequence model

getPossibleValues

public int[] getPossibleValues(int position)
Description copied from interface: SequenceModel
0...leftWindow-1 etc are null, leftWindow...length+leftWindow-1 are words, length+leftWindow...length+leftWindow+rightWindow-1 are null;

Specified by:
getPossibleValues in interface SequenceModel
Parameters:
position - the position
Returns:
the set of possible int values at this position, as an int array

scoreOf

public double scoreOf(int[] sequence,
                      int pos)
Description copied from interface: SequenceModel
Computes the unnormalized log conditional distribution over values of the element at position pos in the sequence, conditioned on the values of the elements in all other positions of the provided sequence.

Specified by:
scoreOf in interface SequenceModel
Parameters:
sequence - the sequence containing the rest of the values to condition on
pos - the position of the element to give a distribution for
Returns:
the log score of the token at the specified position in the sequence

length

public int length()
Specified by:
length in interface SequenceModel
Returns:
the length of the sequence

getNumClasses

public int getNumClasses()
get the number of classes in the sequence model.


getConditionalDistribution

public double[] getConditionalDistribution(int[] sequence,
                                           int position)

scoresOf

public double[] scoresOf(int[] sequence,
                         int position)
Description copied from interface: SequenceModel
Computes the unnormalized log conditional distribution over values of the element at position pos in the sequence, conditioned on the values of the elements in all other positions of the provided sequence.

Specified by:
scoresOf in interface SequenceModel
Parameters:
sequence - the sequence containing the rest of the values to condition on
position - the position of the element to give a distribution for
Returns:
the scores of the possible tokens at the specified position in the sequence

setInitialSequence

public void setInitialSequence(int[] initialSequence)
Description copied from interface: SequenceListener
Informs this sequence listener that the value of the whole sequence is initialized to sequence

Specified by:
setInitialSequence in interface SequenceListener

extractEntity

public edu.stanford.nlp.ie.Entity extractEntity(int[] sequence,
                                                int position)
extracts the entity starting at the given position and adds it to the entity list. returns the index of the last element in the entity (not index+1)


otherOccurrences

public int[] otherOccurrences(edu.stanford.nlp.ie.Entity entity)
finds other locations in the sequence where the sequence of words in this entity occurs.


toArray

public static int[] toArray(List<Integer> list)

matches

public boolean matches(edu.stanford.nlp.ie.Entity entity,
                       int position)

joiningTwoEntities

public boolean joiningTwoEntities(int[] sequence,
                                  int position)

splittingTwoEntities

public boolean splittingTwoEntities(int[] sequence,
                                    int position)

appendingEntity

public boolean appendingEntity(int[] sequence,
                               int position)

prependingEntity

public boolean prependingEntity(int[] sequence,
                                int position)

addingSingletonEntity

public boolean addingSingletonEntity(int[] sequence,
                                     int position)

removingEndOfEntity

public boolean removingEndOfEntity(int[] sequence,
                                   int position)

removingBeginningOfEntity

public boolean removingBeginningOfEntity(int[] sequence,
                                         int position)

noChange

public boolean noChange(int[] sequence,
                        int position)

updateSequenceElement

public void updateSequenceElement(int[] sequence,
                                  int position,
                                  int oldVal)
Description copied from interface: SequenceListener
Informs this sequence listener that the value of the element at position pos has changed. This allows this sequence model to update its internal model if desired.

Specified by:
updateSequenceElement in interface SequenceListener

toString

public String toString()
Overrides:
toString in class Object

toString

public String toString(int pos)


Stanford NLP Group