Skip navigation links
edu.stanford.nlp.ling

Class IndexedWord

    • Field Summary

      Fields 
      Modifier and Type Field and Description
      static IndexedWord NO_WORD
      The identifier that points to no word.
    • Constructor Summary

      Constructors 
      Constructor and Description
      IndexedWord()
      Default constructor; uses CoreLabel default constructor
      IndexedWord(CoreLabel w)
      Construct an IndexedWord from a CoreLabel just as for a CoreMap.
      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(java.lang.String docID, int sentenceIndex, int index)
      Constructor for setting docID, sentenceIndex, and index without any other annotations.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      CoreLabel backingLabel()
      TODO: would be nice to get rid of this.
      int beginPosition()
      Return the beginning character offset of the label (or -1 if none).
      int compareTo(IndexedWord w)
      NOTE: This compareTo is based on and made to be compatible with the one from IndexedFeatureLabel.
      <VALUE> boolean containsKey(java.lang.Class<? extends TypesafeMap.Key<VALUE>> key)
      Returns true if contains the given key.
      int copyCount() 
      java.lang.String docID() 
      int endPosition()
      Return the ending character offset of the label (or -1 if none).
      boolean equals(java.lang.Object o)
      This .equals is dependent only on docID, sentenceIndex, and index.
      static LabelFactory factory() 
      <VALUE> VALUE get(java.lang.Class<? extends TypesafeMap.Key<VALUE>> key)
      Returns the value associated with the given key or null if none is provided.
      <KEY extends TypesafeMap.Key<java.lang.String>>
      java.lang.String
      getString(java.lang.Class<KEY> key) 
      <VALUE> boolean has(java.lang.Class<? extends TypesafeMap.Key<VALUE>> key)
      Returns true if the map contains the given key.
      int hashCode()
      This hashCode uses only the docID, sentenceIndex, and index.
      int index() 
      java.util.Set<java.lang.Class<?>> keySet()
      Collection of keys currently held in this map.
      LabelFactory labelFactory()
      Returns a factory that makes labels of the exact same type as this one.
      java.lang.String lemma()
      Return the lemma value of the label (or null if none).
      IndexedWord makeCopy(int count) 
      java.lang.String ner() 
      java.lang.String originalText() 
      <VALUE> VALUE remove(java.lang.Class<? extends TypesafeMap.Key<VALUE>> key)
      Removes the given key from the map, returning the value removed.
      int sentIndex() 
      <VALUE> VALUE set(java.lang.Class<? extends TypesafeMap.Key<VALUE>> key, VALUE value)
      Associates the given value with the given type for future calls to get.
      void setBeginPosition(int beginPos)
      Set the beginning character offset for the label.
      void setCopyCount(int count) 
      void setDocID(java.lang.String docID) 
      void setEndPosition(int endPos)
      Set the ending character offset of the label (or -1 if none).
      void setFromString(java.lang.String labelStr)
      Set the contents of this label to this String representing the complete contents of the label.
      void setIndex(int index) 
      void setLemma(java.lang.String lemma)
      Set the lemma value for the label (if one is stored).
      void setNER(java.lang.String ner) 
      void setOriginalText(java.lang.String originalText) 
      void setSentIndex(int sentIndex) 
      void setTag(java.lang.String tag)
      Set the tag value for the label (if one is stored).
      void setValue(java.lang.String value)
      Set the value for the label (if one is stored).
      void setWord(java.lang.String word)
      Set the word value for the label (if one is stored).
      int size()
      Returns the number of keys in the map.
      java.lang.String tag()
      Return the tag value of the label (or null if none).
      java.lang.String toPrimes() 
      java.lang.String toString()
      Returns the value-tag of this label.
      java.lang.String toString(CoreLabel.OutputFormat format) 
      java.lang.String value()
      Return a String representation of just the "main" value of this label.
      java.lang.String word()
      Return the word value of the label (or null if none).
      • 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.
    • 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(java.lang.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(java.lang.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(java.lang.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
      • containsKey

        public <VALUE> boolean containsKey(java.lang.Class<? extends TypesafeMap.Key<VALUE>> key)
        Description copied from interface: TypesafeMap
        Returns true if contains the given key.
        Specified by:
        containsKey in interface TypesafeMap
      • set

        public <VALUE> VALUE set(java.lang.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(java.lang.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 java.util.Set<java.lang.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 java.lang.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(java.lang.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 java.lang.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(java.lang.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 java.lang.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(java.lang.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 java.lang.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(java.lang.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
      • docID

        public java.lang.String docID()
        Specified by:
        docID in interface HasIndex
      • setDocID

        public void setDocID(java.lang.String docID)
        Specified by:
        setDocID in interface HasIndex
      • 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 java.lang.String toPrimes()
      • equals

        public boolean equals(java.lang.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 java.lang.Object
      • hashCode

        public int hashCode()
        This hashCode uses only the docID, sentenceIndex, and index. See compareTo for more info.
        Overrides:
        hashCode in class java.lang.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 java.lang.Comparable<IndexedWord>
        Parameters:
        w - The IndexedWord to compare with
        Returns:
        Whether this is less than w or not in the ordering
      • toString

        public java.lang.String toString()
        Returns the value-tag of this label.
        Specified by:
        toString in interface Label
        Overrides:
        toString in class java.lang.Object
        Returns:
        a text representation of the full label contents
      • setFromString

        public void setFromString(java.lang.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

Stanford NLP Group