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

java.lang.Object
  extended by edu.stanford.nlp.ie.EntityCachingAbstractSequencePriorBIO<IN>
All Implemented Interfaces:
SequenceListener, SequenceModel
Direct Known Subclasses:
EmpiricalNERPriorBIO

public abstract class EntityCachingAbstractSequencePriorBIO<IN extends CoreMap>
extends java.lang.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:
Mengqiu Wang

Field Summary
protected  int backgroundSymbol
           
protected  Index<java.lang.String> classIndex
           
protected  int numClasses
           
protected  int[] possibleValues
           
protected  int[] sequence
           
protected  Index<java.lang.String> tagIndex
           
 
Constructor Summary
EntityCachingAbstractSequencePriorBIO(java.lang.String backgroundSymbol, Index<java.lang.String> classIndex, Index<java.lang.String> tagIndex, java.util.List<IN> doc)
           
 
Method Summary
 edu.stanford.nlp.ie.EntityBIO extractEntity(int[] sequence, int position, java.lang.String tag)
          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;
 int leftWindow()
          How many positions to the left a position is dependent on.
 int length()
           
 boolean matches(edu.stanford.nlp.ie.EntityBIO entity, int position)
           
 int[] otherOccurrences(edu.stanford.nlp.ie.EntityBIO entity)
          finds other locations in the sequence where the sequence of words in this entity occurs.
 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
static int[] toArray(java.util.List<java.lang.Integer> list)
           
 java.lang.String toString()
           
 java.lang.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<java.lang.String> classIndex

tagIndex

protected Index<java.lang.String> tagIndex
Constructor Detail

EntityCachingAbstractSequencePriorBIO

public EntityCachingAbstractSequencePriorBIO(java.lang.String backgroundSymbol,
                                             Index<java.lang.String> classIndex,
                                             Index<java.lang.String> tagIndex,
                                             java.util.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.EntityBIO extractEntity(int[] sequence,
                                                   int position,
                                                   java.lang.String tag)
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.EntityBIO entity)
finds other locations in the sequence where the sequence of words in this entity occurs.


toArray

public static int[] toArray(java.util.List<java.lang.Integer> list)

matches

public boolean matches(edu.stanford.nlp.ie.EntityBIO entity,
                       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 java.lang.String toString()
Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(int pos)


Stanford NLP Group