Skip navigation links
Stanford CoreNLP API
edu.stanford.nlp.ling

Class IndexedWord

    • Field Detail

      • NO_WORD

        public static final IndexedWord NO_WORD
        The identifier that points to no word.
    • 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(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)
    • Method Detail

      • backingLabel

        public CoreLabel backingLabel()
        TODO: would be nice to get rid of this. Only used in two places in RTE.
      • get

        public <VALUE> VALUE get(Class<? extends TypesafeMap.Key<VALUE>> key)
        Description copied from interface: TypesafeMap
        Returns the value associated with the given key or null if none is provided.
        Specified by:
        get in interface TypesafeMap
      • has

        public <VALUE> boolean has(Class<? extends TypesafeMap.Key<VALUE>> key)
        Description copied from interface: TypesafeMap
        Returns true if the map contains the given key. todo [cdm 2014]: This is synonymous with containsKey(), but used less, so we should just eliminate it.
        Specified by:
        has in interface TypesafeMap
      • set

        public <VALUE> VALUE set(Class<? extends TypesafeMap.Key<VALUE>> key,
                                 VALUE value)
        Description copied from interface: TypesafeMap
        Associates the given value with the given type for future calls to get. Returns the value removed or null if no value was present.
        Specified by:
        set in interface TypesafeMap
      • remove

        public <VALUE> VALUE remove(Class<? extends TypesafeMap.Key<VALUE>> key)
        Description copied from interface: TypesafeMap
        Removes the given key from the map, returning the value removed.
        Specified by:
        remove in interface TypesafeMap
      • keySet

        public Set<Class<?>> keySet()
        Description copied from interface: TypesafeMap
        Collection of keys currently held in this map. Some implementations may have the returned set be immutable.
        Specified by:
        keySet in interface TypesafeMap
      • size

        public int size()
        Description copied from interface: TypesafeMap
        Returns the number of keys in the map.
        Specified by:
        size in interface TypesafeMap
      • value

        public String value()
        Description copied from interface: Label
        Return a String representation of just the "main" value of this label.
        Specified by:
        value in interface Label
        Returns:
        the "value" of the label
      • setValue

        public void setValue(String value)
        Description copied from interface: Label
        Set the value for the label (if one is stored).
        Specified by:
        setValue in interface Label
        Parameters:
        value - - the value for the label
      • tag

        public String tag()
        Description copied from interface: HasTag
        Return the tag value of the label (or null if none).
        Specified by:
        tag in interface HasTag
        Returns:
        String the tag value for the label
      • setTag

        public void setTag(String tag)
        Description copied from interface: HasTag
        Set the tag value for the label (if one is stored).
        Specified by:
        setTag in interface HasTag
        Parameters:
        tag - The tag value for the label
      • word

        public String word()
        Description copied from interface: HasWord
        Return the word value of the label (or null if none).
        Specified by:
        word in interface HasWord
        Returns:
        String the word value for the label
      • setWord

        public void setWord(String word)
        Description copied from interface: HasWord
        Set the word value for the label (if one is stored).
        Specified by:
        setWord in interface HasWord
        Parameters:
        word - The word value for the label
      • lemma

        public String lemma()
        Description copied from interface: HasLemma
        Return the lemma value of the label (or null if none).
        Specified by:
        lemma in interface HasLemma
        Returns:
        String the lemma value for the label
      • setLemma

        public void setLemma(String lemma)
        Description copied from interface: HasLemma
        Set the lemma value for the label (if one is stored).
        Specified by:
        setLemma in interface HasLemma
        Parameters:
        lemma - The lemma value for the label
      • index

        public int index()
        Specified by:
        index in interface HasIndex
      • setIndex

        public void setIndex(int index)
        Specified by:
        setIndex in interface HasIndex
      • setSentIndex

        public void setSentIndex(int sentIndex)
        Specified by:
        setSentIndex in interface HasIndex
      • beginPosition

        public int beginPosition()
        Description copied from interface: HasOffset
        Return the beginning character offset of the label (or -1 if none).
        Specified by:
        beginPosition in interface HasOffset
        Returns:
        the beginning position for the label
      • endPosition

        public int endPosition()
        Description copied from interface: HasOffset
        Return the ending character offset of the label (or -1 if none).
        Specified by:
        endPosition in interface HasOffset
        Returns:
        the end position for the label
      • setBeginPosition

        public void setBeginPosition(int beginPos)
        Description copied from interface: HasOffset
        Set the beginning character offset for the label. Setting this key to "-1" can be used to indicate no valid value.
        Specified by:
        setBeginPosition in interface HasOffset
        Parameters:
        beginPos - The beginning position
      • setEndPosition

        public void setEndPosition(int endPos)
        Description copied from interface: HasOffset
        Set the ending character offset of the label (or -1 if none).
        Specified by:
        setEndPosition in interface HasOffset
        Parameters:
        endPos - The end character offset for the label
      • copyCount

        public int copyCount()
      • setCopyCount

        public void setCopyCount(int count)
      • toPrimes

        public String toPrimes()
      • 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 Object
      • hashCode

        public int hashCode()
        This hashCode uses only the docID, sentenceIndex, and index. See compareTo for more info.
        Overrides:
        hashCode in class Object
      • 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()
        Returns the value-tag of this label.
        Specified by:
        toString in interface Label
        Overrides:
        toString in class Object
        Returns:
        a text representation of the full label contents
      • setFromString

        public void setFromString(String labelStr)
        Set the contents of this label to this String representing the complete contents of the label. A class implementing label may throw an UnsupportedOperationException for this method (only). Typically, this method would do some appropriate decoding of the string in a way that sets multiple fields in an inverse of the toString() method.
        Specified by:
        setFromString in interface Label
        Parameters:
        labelStr - the String that translates into the content of the label
      • 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
        Returns:
        the LabelFactory for this kind of label

© 2002-2013 Stanford NLP Group