edu.stanford.nlp.ling
Class IndexedWord

java.lang.Object
  extended by edu.stanford.nlp.util.ArrayCoreMap
      extended by edu.stanford.nlp.ling.CoreLabel
          extended by edu.stanford.nlp.ling.IndexedWord
All Implemented Interfaces:
HasCategory, HasContext, HasIndex, HasOffset, HasTag, HasWord, Label, CoreMap, PrettyLoggable, TypesafeMap<CoreMap>, Serializable, Comparable<IndexedWord>

public class IndexedWord
extends CoreLabel
implements Comparable<IndexedWord>

This class is mainly for use with RTE in terms of the methods it provides, but on a more general level, it provides a CoreLabel that uses its DocIDAnnotation, SentenceIndexAnnotation, and IndexAnnotation to implement Comparable/compareTo, hashCode, and equals. This means no other annotations, including the identity of the word, are taken into account when using these methods.

Author:
rafferty
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class edu.stanford.nlp.ling.CoreLabel
CoreLabel.GenericAnnotation<T>
 
Nested classes/interfaces inherited from interface edu.stanford.nlp.util.TypesafeMap
TypesafeMap.Key<BASE,VALUE>
 
Field Summary
static String COMPLETE_FORMAT
           
static IndexedWord NO_WORD
          The identifier that points to no word.
static String VALUE_FORMAT
           
static String WORD_FORMAT
          Various printing options for toString
static String WORD_TAG_FORMAT
           
static String WORD_TAG_INDEX_FORMAT
           
 
Fields inherited from class edu.stanford.nlp.ling.CoreLabel
genericKeys, genericValues, TAG_SEPARATOR
 
Constructor Summary
IndexedWord()
          Default constructor; uses CoreLabel default constructor
IndexedWord(CoreLabel w)
          Construct an IndexedWord from a CoreLabel just as for a CoreMap.
IndexedWord(CoreMap w)
          Copy Constructor - relies on CoreLabel copy constructor
IndexedWord(CyclicCoreLabel w)
          Copy Constructor - relies on CoreLabel copy constructor It will set the value, and if the word is not set otherwise, set the word to the value.
IndexedWord(Label w)
          Copy Constructor - relies on CoreLabel copy constructor It will set the value, and if the word is not set otherwise, set the word to the value.
IndexedWord(String docID, int sentenceIndex, int index)
          Constructor for setting docID, sentenceIndex, and index without any other annotations.
IndexedWord(String docID, int sentenceIndex, int index, CoreLabel label)
          Copies the given label and then sets the docID, sentenceIndex, and Index; if these differ from those in label, the parameters will be used (not the label values).
 
Method Summary
 int compareTo(IndexedWord w)
          NOTE: This compareTo is based on and made to be compatible with the one from IndexedFeatureLabel.
 boolean equals(Object o)
          This .equals is dependent only on docID, sentenceIndex, and index.
static LabelFactory factory()
           
 int hashCode()
          This hashcode uses only the docID, sentenceIndex, and index See compareTo for more info
 LabelFactory labelFactory()
          Returns a factory that makes labels of the exact same type as this one.
static void setPrintFormat(String printFormat)
           
 String toString()
          Computes the toString based on whatever the printFormat is currently set as.
 String toString(String format)
          Prints the toString in the form of format.
 
Methods inherited from class edu.stanford.nlp.ling.CoreLabel
after, before, beginPosition, category, docID, endPosition, getString, index, lemma, ner, originalText, sentIndex, setAfter, setBefore, setBeginPosition, setCategory, setDocID, setEndPosition, setFromString, setIndex, setLemma, setNER, setOriginalText, setSentIndex, setTag, setValue, setWord, tag, value, word
 
Methods inherited from class edu.stanford.nlp.util.ArrayCoreMap
compact, containsKey, get, has, keySet, prettyLog, remove, set, setCapacity, size, toShorterString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

NO_WORD

public static final IndexedWord NO_WORD
The identifier that points to no word.


WORD_FORMAT

public static final String WORD_FORMAT
Various printing options for toString

See Also:
Constant Field Values

WORD_TAG_FORMAT

public static final String WORD_TAG_FORMAT
See Also:
Constant Field Values

WORD_TAG_INDEX_FORMAT

public static final String WORD_TAG_INDEX_FORMAT
See Also:
Constant Field Values

VALUE_FORMAT

public static final String VALUE_FORMAT
See Also:
Constant Field Values

COMPLETE_FORMAT

public static final String COMPLETE_FORMAT
See Also:
Constant Field Values
Constructor Detail

IndexedWord

public IndexedWord()
Default constructor; uses CoreLabel default constructor


IndexedWord

public IndexedWord(Label w)
Copy Constructor - relies on CoreLabel copy constructor It will set the value, and if the word is not set otherwise, set the word to the value.

Parameters:
w - A Label to initialize this IndexedWord from

IndexedWord

public IndexedWord(CoreLabel w)
Construct an IndexedWord from a CoreLabel just as for a CoreMap. Implementation note: this is a the same as the constructor that takes a CoreMap, but is needed to ensure unique most specific type inference for selecting a constructor at compile-time.

Parameters:
w - A Label to initialize this IndexedWord from

IndexedWord

public IndexedWord(CoreMap w)
Copy Constructor - relies on CoreLabel copy constructor

Parameters:
w - A Label to initialize this IndexedWord from

IndexedWord

public IndexedWord(CyclicCoreLabel w)
Copy Constructor - relies on CoreLabel copy constructor It will set the value, and if the word is not set otherwise, set the word to the value.

Parameters:
w - A Label to initialize this IndexedWord from

IndexedWord

public IndexedWord(String docID,
                   int sentenceIndex,
                   int index)
Constructor for setting docID, sentenceIndex, and index without any other annotations.

Parameters:
docID - The document ID (arbitrary string)
sentenceIndex - The sentence number in the document (normally 0-based)
index - The index of the word in the sentence (normally 0-based)

IndexedWord

public IndexedWord(String docID,
                   int sentenceIndex,
                   int index,
                   CoreLabel label)
Copies the given label and then sets the docID, sentenceIndex, and Index; if these differ from those in label, the parameters will be used (not the label values).

Parameters:
docID - The document ID (arbitrary string)
sentenceIndex - The sentence number in the document (normally 0-based)
index - The index of the word in the sentence (normally 0-based)
label - The CoreLabel to initialize all other fields from.
Method Detail

equals

public boolean equals(Object o)
This .equals is dependent only on docID, sentenceIndex, and index. It doesn't consider the actual word value, but assumes that it is validly represented by token position. All IndexedWords that lack these fields will be regarded as equal.

Overrides:
equals in class ArrayCoreMap

hashCode

public int hashCode()
This hashcode uses only the docID, sentenceIndex, and index See compareTo for more info

Overrides:
hashCode in class ArrayCoreMap

compareTo

public int compareTo(IndexedWord w)
NOTE: This compareTo is based on and made to be compatible with the one from IndexedFeatureLabel. You must have a DocIDAnnotation, SentenceIndexAnnotation, and IndexAnnotation for this to make sense and be guaranteed to work properly. Currently, it won't error out and will try to return something sensible if these are not defined, but that really isn't proper usage! This compareTo method is based not by value elements like the word(), but on passage position. It puts NO_WORD elements first, and then orders by document, sentence, and word index. If these do not differ, it returns equal.

Specified by:
compareTo in interface Comparable<IndexedWord>
Parameters:
w - The IndexedWord to compare with
Returns:
Whether this is less than w or not in the ordering

toString

public String toString()
Computes the toString based on whatever the printFormat is currently set as.

Specified by:
toString in interface Label
Overrides:
toString in class ArrayCoreMap
Returns:
a text representation of the full label contents

setPrintFormat

public static void setPrintFormat(String printFormat)

toString

public String toString(String format)
Prints the toString in the form of format.

Parameters:
format - One of the constants defined for this class. (You must use one of these constants, because the Strings are compared by ==.)
Returns:
A printed representation

factory

public static LabelFactory factory()

labelFactory

public LabelFactory labelFactory()
Returns a factory that makes labels of the exact same type as this one. May return null if no appropriate factory is known.

Specified by:
labelFactory in interface Label
Overrides:
labelFactory in class CoreLabel
Returns:
the LabelFactory for this kind of label


Stanford NLP Group