public class CoreLabel extends ArrayCoreMap implements AbstractCoreLabel, HasWord, HasTag, HasCategory, HasLemma, HasContext, HasIndex, HasOffset
A CoreLabel is a Map from keys (which are Class objects) to values, whose type is determined by the key. That is, it is a heterogeneous typesafe Map (see Josh Bloch, Effective Java, 2nd edition).
The CoreLabel class in particular bridges the gap between old-style JavaNLP
Labels and the new CoreMap infrastructure. Instances of this class can be
used (almost) anywhere that the now-defunct FeatureLabel family could be
used. This data structure is backed by an ArrayCoreMap
.
Modifier and Type | Class and Description |
---|---|
static interface |
CoreLabel.GenericAnnotation<T>
Class that all "generic" annotations extend.
|
static class |
CoreLabel.OutputFormat |
TypesafeMap.Key<VALUE>
Modifier and Type | Field and Description |
---|---|
static CoreLabel.OutputFormat |
DEFAULT_FORMAT |
static Map<String,Class<? extends CoreLabel.GenericAnnotation>> |
genericKeys |
static Map<Class<? extends CoreLabel.GenericAnnotation>,String> |
genericValues |
static String |
TAG_SEPARATOR
Tag separator to use by default
|
Constructor and Description |
---|
CoreLabel()
Default constructor, calls super()
|
CoreLabel(CoreLabel label)
Returns a new CoreLabel instance based on the contents of the given
CoreLabel.
|
CoreLabel(CoreMap label)
Returns a new CoreLabel instance based on the contents of the given
CoreMap.
|
CoreLabel(int capacity)
Initializes this CoreLabel, pre-allocating arrays to hold
up to capacity key,value pairs.
|
CoreLabel(Label label)
Returns a new CoreLabel instance based on the contents of the given
label.
|
CoreLabel(String[] keys,
String[] values)
This constructor attempts to parse the String keys
into Class keys.
|
Modifier and Type | Method and Description |
---|---|
String |
after()
Return the whitespace String after the word.
|
String |
before() |
int |
beginPosition()
Return the beginning character offset of the label (or -1 if none).
|
String |
category()
Return the category value of the label (or null if none).
|
int |
copyCount() |
String |
docID() |
int |
endPosition()
Return the ending character offset of the label (or -1 if none).
|
static LabelFactory |
factory()
Return a factory for this kind of label
|
<KEY extends TypesafeMap.Key<String>> |
getString(Class<KEY> key)
Return a non-null String value for a key.
|
int |
index() |
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).
|
String |
ner()
Return the named entity class of the label (or null if none).
|
String |
originalText()
Return the String which is the original character sequence of the token.
|
int |
sentIndex() |
void |
setAfter(String after)
Set the whitespace String after the word.
|
void |
setBefore(String before)
Set the whitespace String before the word.
|
void |
setBeginPosition(int beginPos)
Set the beginning character offset for the label.
|
void |
setCategory(String category)
Set the category value for the label (if one is stored).
|
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)
Set the String which is the original character sequence of the token.
|
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.
|
String |
tag()
Return the tag value of the label (or null if none).
|
String |
toPrimes() |
String |
toString()
Prints a full dump of a CoreMap.
|
String |
toString(CoreLabel.OutputFormat format)
Returns a formatted string representing this label.
|
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).
|
compact, containsKey, equals, get, has, hashCode, keySet, prettyLog, remove, set, setCapacity, size, toShorterString, toShortString, toShortString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
containsKey, get, has, keySet, remove, set, size
public static final Map<String,Class<? extends CoreLabel.GenericAnnotation>> genericKeys
public static final Map<Class<? extends CoreLabel.GenericAnnotation>,String> genericValues
public static final String TAG_SEPARATOR
public static final CoreLabel.OutputFormat DEFAULT_FORMAT
public CoreLabel()
public CoreLabel(int capacity)
capacity
- Initial capacity of object in key,value pairspublic CoreLabel(CoreLabel label)
label
- The CoreLabel to copypublic CoreLabel(CoreMap label)
label
- The CoreMap to copypublic CoreLabel(Label label)
label
- Basis for this labelpublic CoreLabel(String[] keys, String[] values)
CoreAnnotations
.keys
- Array of Strings that are class namesvalues
- Array of values (as String)public static LabelFactory factory()
public LabelFactory labelFactory()
null
if no appropriate factory is known.labelFactory
in interface Label
public <KEY extends TypesafeMap.Key<String>> String getString(Class<KEY> key)
getString
in interface AbstractCoreLabel
KEY
- A key type with a String valuekey
- The key to return the value of.null
and the String value of the key otherwisepublic 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 final void setValue(String value)
public final String value()
public void setWord(String word)
public String word()
public void setTag(String tag)
public String tag()
public void setCategory(String category)
setCategory
in interface HasCategory
category
- The category value for the labelpublic String category()
category
in interface HasCategory
public void setAfter(String after)
setAfter
in interface HasContext
after
- The whitespace String after the wordpublic String after()
after
in interface HasContext
public void setBefore(String before)
setBefore
in interface HasContext
before
- the whitespace String before the wordpublic String before()
before
in interface HasContext
public void setOriginalText(String originalText)
setOriginalText
in interface AbstractCoreLabel
setOriginalText
in interface HasContext
originalText
- The original character sequence of the tokenpublic String originalText()
originalText
in interface AbstractCoreLabel
originalText
in interface HasContext
public String ner()
ner
in interface AbstractCoreLabel
public void setNER(String ner)
setNER
in interface AbstractCoreLabel
public String lemma()
public void setLemma(String lemma)
public void setSentIndex(int sentIndex)
setSentIndex
in interface HasIndex
public int beginPosition()
beginPosition
in interface HasOffset
public int endPosition()
endPosition
in interface HasOffset
public void setBeginPosition(int beginPos)
setBeginPosition
in interface HasOffset
beginPos
- The beginning positionpublic void setEndPosition(int endPos)
setEndPosition
in interface HasOffset
endPos
- The end character offset for the labelpublic int copyCount()
public void setCopyCount(int count)
public String toString()
ArrayCoreMap
toString
in interface Label
toString
in class ArrayCoreMap
public String toString(CoreLabel.OutputFormat format)
String
.
Currently supported formats include:
CATEGORY_KEY
)INDEX_KEY
,
respectively, and prints them with a hyphen in betweenpublic String toPrimes()