public class CoreLabel extends ArrayCoreMap implements AbstractCoreLabel, HasCategory
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 java.util.Map<java.lang.String,java.lang.Class<? extends CoreLabel.GenericAnnotation>> |
genericKeys |
static java.util.Map<java.lang.Class<? extends CoreLabel.GenericAnnotation>,java.lang.String> |
genericValues |
static java.lang.String |
TAG_SEPARATOR
Tag separator to use by default
|
listener| Constructor and Description |
|---|
CoreLabel()
Default constructor, calls super()
|
CoreLabel(java.lang.Class[] keys,
java.lang.String[] values)
This constructor attempts uses preparsed Class keys.
|
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(java.lang.String[] keys,
java.lang.String[] values)
This constructor attempts to parse the String keys
into Class keys.
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
after()
Return the whitespace String after the word.
|
java.lang.String |
before() |
int |
beginPosition()
Return the beginning char offset of the label (or -1 if none).
|
java.lang.String |
category()
Return the category value of the label (or null if none).
|
java.lang.String |
docID() |
int |
endPosition()
Return the ending char offset of the label (or -1 if none).
|
static LabelFactory |
factory()
Return a factory for this kind of label
|
<KEY extends TypesafeMap.Key<java.lang.String>> |
getString(java.lang.Class<KEY> key)
Return a non-null String value for a key.
|
<KEY extends TypesafeMap.Key<java.lang.String>> |
getString(java.lang.Class<KEY> key,
java.lang.String def) |
int |
index() |
java.lang.Boolean |
isMWT()
Get value of IsMultiWordToken
|
java.lang.Boolean |
isMWTFirst()
Get value of IsFirstWordOfMWT
|
java.lang.Boolean |
isNewline()
Get value of IsNewlineAnnotation
|
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).
|
java.lang.String |
ner()
Return the named entity class of the label (or null if none).
|
java.util.Map<java.lang.String,java.lang.Double> |
nerConfidence()
Return the map of confidences
|
java.lang.String |
originalText()
Return the String which is the original character sequence of the token.
|
static java.lang.Class[] |
parseStringKeys(java.lang.String[] keys) |
int |
sentIndex() |
void |
setAfter(java.lang.String after)
Set the whitespace String after the word.
|
void |
setBefore(java.lang.String before)
Set the whitespace String before the word.
|
void |
setBeginPosition(int beginPos)
Set the beginning character offset for the label.
|
void |
setCategory(java.lang.String category)
Set the category value for the label (if one is stored).
|
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 |
setIsMWT(boolean isMWT)
Set value of IsMultiWordToken
|
void |
setIsMWTFirst(boolean isFirstMWT)
Set value of IsFirstWordOfMWT
|
void |
setIsNewline(boolean isNewline)
Set value of IsNewlineAnnotation
|
void |
setLemma(java.lang.String lemma)
Set the lemma value for the label (if one is stored).
|
void |
setNER(java.lang.String ner)
Set the named entity class of the label.
|
void |
setOriginalText(java.lang.String originalText)
Set the String which is the original character sequence of the token.
|
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.
|
java.lang.String |
tag()
Return the tag value of the label (or null if none).
|
java.lang.String |
toString()
Prints a full dump of a CoreMap.
|
java.lang.String |
toString(CoreLabel.OutputFormat format)
Returns a formatted string representing this label.
|
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).
|
static CoreLabel |
wordFromString(java.lang.String word)
This is provided as a simple way to make a CoreLabel for a word from a String.
|
compact, containsKey, equals, get, hashCode, keySet, keySetNotNull, prettyLog, remove, set, setCapacity, size, toShorterString, toShortString, toShortStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitcontainsKey, get, keySet, remove, set, sizepublic static final java.util.Map<java.lang.String,java.lang.Class<? extends CoreLabel.GenericAnnotation>> genericKeys
public static final java.util.Map<java.lang.Class<? extends CoreLabel.GenericAnnotation>,java.lang.String> genericValues
public static final java.lang.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)
HasWord is copied.label - Basis for this labelpublic CoreLabel(java.lang.String[] keys,
java.lang.String[] values)
CoreAnnotations.keys - Array of Strings that are class namesvalues - Array of values (as String)public CoreLabel(java.lang.Class[] keys,
java.lang.String[] values)
keys - Array of key classesvalues - Array of values (as String)public static CoreLabel wordFromString(java.lang.String word)
word - The word string to make a CoreLabel forpublic static java.lang.Class[] parseStringKeys(java.lang.String[] keys)
public static LabelFactory factory()
public LabelFactory labelFactory()
null if no appropriate factory is known.labelFactory in interface Labelpublic <KEY extends TypesafeMap.Key<java.lang.String>> java.lang.String getString(java.lang.Class<KEY> key)
getString in interface AbstractCoreLabelKEY - A key type with a String valuekey - The key to return the value of.null
and the String value of the key otherwisepublic <KEY extends TypesafeMap.Key<java.lang.String>> java.lang.String getString(java.lang.Class<KEY> key, java.lang.String def)
getString in interface AbstractCoreLabelpublic void setFromString(java.lang.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 LabellabelStr - the String that translates into the content of the
labelpublic final void setValue(java.lang.String value)
public final java.lang.String value()
public void setWord(java.lang.String word)
public java.lang.String word()
public void setTag(java.lang.String tag)
public java.lang.String tag()
public void setCategory(java.lang.String category)
setCategory in interface HasCategorycategory - The category value for the labelpublic java.lang.String category()
category in interface HasCategorypublic void setAfter(java.lang.String after)
setAfter in interface HasContextafter - The whitespace String after the wordpublic java.lang.String after()
after in interface HasContextpublic void setBefore(java.lang.String before)
setBefore in interface HasContextbefore - the whitespace String before the wordpublic java.lang.String before()
before in interface HasContextpublic void setOriginalText(java.lang.String originalText)
setOriginalText in interface HasContextsetOriginalText in interface HasOriginalTextoriginalText - The original character sequence of the tokenpublic java.lang.String originalText()
originalText in interface HasContextoriginalText in interface HasOriginalTextpublic java.lang.String ner()
public void setNER(java.lang.String ner)
public java.util.Map<java.lang.String,java.lang.Double> nerConfidence()
public java.lang.String lemma()
public void setLemma(java.lang.String lemma)
public java.lang.Boolean isNewline()
public void setIsNewline(boolean isNewline)
public java.lang.Boolean isMWT()
public java.lang.Boolean isMWTFirst()
public void setIsMWT(boolean isMWT)
public void setIsMWTFirst(boolean isFirstMWT)
public void setSentIndex(int sentIndex)
setSentIndex in interface HasIndexpublic int beginPosition()
beginPosition in interface HasOffsetpublic int endPosition()
endPosition in interface HasOffsetpublic void setBeginPosition(int beginPos)
setBeginPosition in interface HasOffsetbeginPos - The beginning positionpublic void setEndPosition(int endPos)
setEndPosition in interface HasOffsetendPos - The end character offset for the labelpublic java.lang.String toString()
ArrayCoreMaptoString in interface LabeltoString in class ArrayCoreMappublic java.lang.String toString(CoreLabel.OutputFormat format)
String.
Currently supported formats include:
CATEGORY_KEY)INDEX_KEY,
respectively, and prints them with a hyphen in betweenMap is printed in alphabetical order of keys.