public class IndexedWord extends Object implements AbstractCoreLabel, Comparable<IndexedWord>
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.
CoreLabel
.
This avoids breaking the equals()
and
hashCode()
contract and also avoids expensive copying
when used to represent the same data as the original
CoreLabel
.
TypesafeMap.Key<VALUE>
Modifier and Type | Field and Description |
---|---|
static IndexedWord |
NO_WORD
The identifier that points to no word.
|
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(String docID,
int sentenceIndex,
int index)
Constructor for setting docID, sentenceIndex, and
index without any other annotations.
|
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(Class<? extends TypesafeMap.Key<VALUE>> key)
Returns true if contains the given key.
|
int |
copyCount() |
String |
docID() |
int |
endPosition()
Return the ending character offset of the label (or -1 if none).
|
boolean |
equals(Object o)
This .equals is dependent only on docID, sentenceIndex, and index.
|
static LabelFactory |
factory() |
<VALUE> VALUE |
get(Class<? extends TypesafeMap.Key<VALUE>> key)
Returns the value associated with the given key or null if
none is provided.
|
<KEY extends TypesafeMap.Key<String>> |
getString(Class<KEY> key) |
<VALUE> boolean |
has(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() |
Set<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.
|
String |
lemma()
Return the lemma value of the label (or null if none).
|
IndexedWord |
makeCopy(int count) |
String |
ner() |
String |
originalText() |
<VALUE> VALUE |
remove(Class<? extends TypesafeMap.Key<VALUE>> key)
Removes the given key from the map, returning the value removed.
|
int |
sentIndex() |
<VALUE> VALUE |
set(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(String docID) |
void |
setEndPosition(int endPos)
Set the ending character offset of the label (or -1 if none).
|
void |
setFromString(String labelStr)
Set the contents of this label to this
String
representing the
complete contents of the label. |
void |
setIndex(int index) |
void |
setLemma(String lemma)
Set the lemma value for the label (if one is stored).
|
void |
setNER(String ner) |
void |
setOriginalText(String originalText) |
void |
setSentIndex(int sentIndex) |
void |
setTag(String tag)
Set the tag value for the label (if one is stored).
|
void |
setValue(String value)
Set the value for the label (if one is stored).
|
void |
setWord(String word)
Set the word value for the label (if one is stored).
|
int |
size()
Returns the number of keys in the map.
|
String |
tag()
Return the tag value of the label (or null if none).
|
String |
toPrimes() |
String |
toString()
Returns the value-tag of this label.
|
String |
toString(CoreLabel.OutputFormat format) |
String |
value()
Return a String representation of just the "main" value of this label.
|
String |
word()
Return the word value of the label (or null if none).
|
public static final IndexedWord NO_WORD
public IndexedWord()
CoreLabel
default constructorpublic IndexedWord(Label w)
CoreLabel
copy constructor
It will set the value, and if the word is not set otherwise, set
the word to the value.w
- A Label to initialize this IndexedWord frompublic IndexedWord(CoreLabel w)
w
- A Label to initialize this IndexedWord frompublic IndexedWord(String docID, int sentenceIndex, int index)
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)public IndexedWord makeCopy(int count)
public CoreLabel backingLabel()
public <VALUE> VALUE get(Class<? extends TypesafeMap.Key<VALUE>> key)
TypesafeMap
get
in interface TypesafeMap
public <VALUE> boolean has(Class<? extends TypesafeMap.Key<VALUE>> key)
TypesafeMap
has
in interface TypesafeMap
public <VALUE> boolean containsKey(Class<? extends TypesafeMap.Key<VALUE>> key)
TypesafeMap
containsKey
in interface TypesafeMap
public <VALUE> VALUE set(Class<? extends TypesafeMap.Key<VALUE>> key, VALUE value)
TypesafeMap
set
in interface TypesafeMap
public <KEY extends TypesafeMap.Key<String>> String getString(Class<KEY> key)
getString
in interface AbstractCoreLabel
public <VALUE> VALUE remove(Class<? extends TypesafeMap.Key<VALUE>> key)
TypesafeMap
remove
in interface TypesafeMap
public Set<Class<?>> keySet()
TypesafeMap
keySet
in interface TypesafeMap
public int size()
TypesafeMap
size
in interface TypesafeMap
public String value()
Label
public void setValue(String value)
Label
public String tag()
HasTag
public void setTag(String tag)
HasTag
public String word()
HasWord
public void setWord(String word)
HasWord
public String lemma()
HasLemma
public void setLemma(String lemma)
HasLemma
public String ner()
ner
in interface AbstractCoreLabel
public void setNER(String ner)
setNER
in interface AbstractCoreLabel
public void setSentIndex(int sentIndex)
setSentIndex
in interface HasIndex
public String originalText()
originalText
in interface AbstractCoreLabel
public void setOriginalText(String originalText)
setOriginalText
in interface AbstractCoreLabel
public int beginPosition()
HasOffset
beginPosition
in interface HasOffset
public int endPosition()
HasOffset
endPosition
in interface HasOffset
public void setBeginPosition(int beginPos)
HasOffset
setBeginPosition
in interface HasOffset
beginPos
- The beginning positionpublic void setEndPosition(int endPos)
HasOffset
setEndPosition
in interface HasOffset
endPos
- The end character offset for the labelpublic int copyCount()
public void setCopyCount(int count)
public String toPrimes()
public boolean equals(Object o)
public int hashCode()
public int compareTo(IndexedWord w)
compareTo
in interface Comparable<IndexedWord>
w
- The IndexedWord to compare withpublic String toString()
public String toString(CoreLabel.OutputFormat format)
public void setFromString(String labelStr)
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.setFromString
in interface Label
labelStr
- the String that translates into the content of the
labelpublic static LabelFactory factory()
public LabelFactory labelFactory()
null
if no appropriate factory is known.labelFactory
in interface Label