edu.stanford.nlp.ling
Class MapLabel

java.lang.Object
  extended by edu.stanford.nlp.ling.AbstractLabel
      extended by edu.stanford.nlp.ling.MapLabel
All Implemented Interfaces:
HasCategory, HasTag, HasWord, Label, java.io.Serializable, java.lang.Comparable

public class MapLabel
extends AbstractLabel
implements HasCategory, HasWord, HasTag, java.io.Serializable

A MapLabel object contains a Map, which in turn may contain arbitrary key-value pairs. The primary value (corresponding to the string in a StringLabel, and representing a category in a parse tree) is stored in the map under the key CATEGORY_KEY.

For convenience, this class also contains standardized keys for storing head words, head tags, and integer indexes in the map, under the keys HEAD_WORD_KEY, HEAD_TAG_KEY, and INDEX_KEY, respectively. It also provides methods for getting and setting the category, head word, head tag, and index.

See Also:
Serialized Form

Field Summary
static java.lang.String ARG
          The standard key for a propbank label which is of type Argument
static java.lang.String CATEGORY_FUNCTIONAL_TAG_KEY
          The standard key for storing category with functional tags.
static java.lang.String CATEGORY_KEY
          The standard key for storing a category (value) in the map.
static java.lang.String HEAD_TAG_KEY
          The standard key for storing a head tag in the map.
static java.lang.String HEAD_WORD_KEY
          The standard key for storing a head word in the map.
static java.lang.String INDEX_KEY
          The standard key for storing an integer index in the map.
static java.lang.String MARKING
          Another key used for propbank - to signify core arg nodes or predicate nodes
static java.lang.String SEMANTIC_HEAD_POS_KEY
          The standard key for Semantic Head Word POS which is a String
static java.lang.String SEMANTIC_HEAD_WORD_KEY
          The standard key for Semantic Head Word which is a String
 
Constructor Summary
MapLabel()
          Create a new MapLabel with null value.
MapLabel(Label label)
          Create a new MapLabel with the value of another Label as its value.
MapLabel(java.lang.String str)
          Create a new MapLabel with the given value.
 
Method Summary
 java.lang.String category()
          Return the category of the label (or null if none), which is stored in the map under the key CATEGORY_KEY.
 boolean equals(java.lang.Object o)
          Equality for Labels is defined in the first instance as equality of their String value().
static LabelFactory factory()
          Return a factory for MapLabels.
 java.lang.Object get(java.lang.Object key)
          Returns the value to which the map contained in this label maps the specified key.
 java.lang.String getSemanticTag()
          Returns the semantic head pos of the phrase if it exists, and null otherwise
 java.lang.String getSemanticWord()
          Returns the semantic head of the phrase if it exists, and null otherwise
 int index()
          Return the index of the label (or -1 if none), which is stored in the map under the key INDEX_KEY.
 LabelFactory labelFactory()
          Return a factory for MapLabels.
static void main(java.lang.String[] args)
          For testing only.
 java.util.Map map()
          Return the Map contained in this label.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Associates the specified value with the specified key in the map contained in this label.
 void setCategory(java.lang.String category)
          Set the category for the label by storing it in the map under the key CATEGORY_KEY.
 void setFromString(java.lang.String str)
          Set value for the label from a String by storing it in the map under the key CATEGORY_KEY.
 int setIndex(int index)
          Set the index for the label by storing it in the contained map under the key INDEX_KEY.
 void setMap(java.util.Map map)
          Set the Map contained in this label to the supplied Map.
 void setSemanticTag(java.lang.String hTag)
          Set the semantic head pos of the phrase
 void setSemanticWord(java.lang.String hWord)
          Set the semantic head of the phrase
 void setTag(java.lang.String tag)
          Set the head tag for the label by storing it in the map under the key HEAD_TAG_KEY.
 void setValue(java.lang.String value)
          Set the value for the label by storing it in the map under the key CATEGORY_KEY.
 void setWord(java.lang.String word)
          Set the head word for the label by storing it in the map under the key HEAD_WORD_KEY.
 java.lang.String tag()
          Return the head tag of the label (or null if none), which is stored in the map under the key HEAD_TAG_KEY.
 java.lang.String toString()
          Return a String containing the value (and index, if any) of this label.
 java.lang.String toString(java.lang.String format)
          Returns a formatted string representing this label.
 java.lang.String value()
          Return the value of the label (or null if none), which is stored in the map under the key CATEGORY_KEY.
 java.lang.String word()
          Return the head word of the label (or null if none), which is stored in the map under the key HEAD_WORD_KEY.
 
Methods inherited from class edu.stanford.nlp.ling.AbstractLabel
compareTo, hashCode
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

CATEGORY_KEY

public static final java.lang.String CATEGORY_KEY
The standard key for storing a category (value) in the map.

See Also:
Constant Field Values

HEAD_WORD_KEY

public static final java.lang.String HEAD_WORD_KEY
The standard key for storing a head word in the map.

See Also:
Constant Field Values

HEAD_TAG_KEY

public static final java.lang.String HEAD_TAG_KEY
The standard key for storing a head tag in the map.

See Also:
Constant Field Values

INDEX_KEY

public static final java.lang.String INDEX_KEY
The standard key for storing an integer index in the map.

See Also:
Constant Field Values

ARG

public static final java.lang.String ARG
The standard key for a propbank label which is of type Argument

See Also:
Constant Field Values

MARKING

public static final java.lang.String MARKING
Another key used for propbank - to signify core arg nodes or predicate nodes

See Also:
Constant Field Values

SEMANTIC_HEAD_WORD_KEY

public static final java.lang.String SEMANTIC_HEAD_WORD_KEY
The standard key for Semantic Head Word which is a String

See Also:
Constant Field Values

SEMANTIC_HEAD_POS_KEY

public static final java.lang.String SEMANTIC_HEAD_POS_KEY
The standard key for Semantic Head Word POS which is a String

See Also:
Constant Field Values

CATEGORY_FUNCTIONAL_TAG_KEY

public static final java.lang.String CATEGORY_FUNCTIONAL_TAG_KEY
The standard key for storing category with functional tags.

See Also:
Constant Field Values
Constructor Detail

MapLabel

public MapLabel()
Create a new MapLabel with null value.


MapLabel

public MapLabel(java.lang.String str)
Create a new MapLabel with the given value.

Parameters:
str - the value of the new label

MapLabel

public MapLabel(Label label)
Create a new MapLabel with the value of another Label as its value.

If the argument label is a MapLabel, the new label is identical to the argument label (but does not share storage).

If the argument label is a CategoryWordTag, the category, word, and tag are stored in the map of the new label under the map keys CATEGORY_KEY, HEAD_WORD_KEY, and HEAD_TAG_KEY, respectively.

Parameters:
label - the other label
Method Detail

equals

public boolean equals(java.lang.Object o)
Description copied from class: AbstractLabel
Equality for Labels is defined in the first instance as equality of their String value(). Now rewritten to correctly enforce the contract of equals in Object. Equality for a Label is determined simply by String equality of its value(). Subclasses should not redefine this to include other aspects of the Label, or the contract for equals() is broken.

Overrides:
equals in class AbstractLabel
Parameters:
o - the object against which equality is to be checked
Returns:
true if this and obj are equal

value

public java.lang.String value()
Return the value of the label (or null if none), which is stored in the map under the key CATEGORY_KEY.

Specified by:
value in interface Label
Overrides:
value in class AbstractLabel
Returns:
the value for the label

setValue

public void setValue(java.lang.String value)
Set the value for the label by storing it in the map under the key CATEGORY_KEY.

Specified by:
setValue in interface Label
Overrides:
setValue in class AbstractLabel
Parameters:
value - the value for the label

setFromString

public void setFromString(java.lang.String str)
Set value for the label from a String by storing it in the map under the key CATEGORY_KEY.

Specified by:
setFromString in interface Label
Overrides:
setFromString in class AbstractLabel
Parameters:
str - the string value for the label

category

public java.lang.String category()
Return the category of the label (or null if none), which is stored in the map under the key CATEGORY_KEY.

Specified by:
category in interface HasCategory
Returns:
the category for the label

setCategory

public void setCategory(java.lang.String category)
Set the category for the label by storing it in the map under the key CATEGORY_KEY.

Specified by:
setCategory in interface HasCategory
Parameters:
category - the category for the label

word

public java.lang.String word()
Return the head word of the label (or null if none), which is stored in the map under the key HEAD_WORD_KEY.

Specified by:
word in interface HasWord
Returns:
the head word for the label

getSemanticWord

public java.lang.String getSemanticWord()
Returns the semantic head of the phrase if it exists, and null otherwise


setSemanticWord

public void setSemanticWord(java.lang.String hWord)
Set the semantic head of the phrase


getSemanticTag

public java.lang.String getSemanticTag()
Returns the semantic head pos of the phrase if it exists, and null otherwise


setSemanticTag

public void setSemanticTag(java.lang.String hTag)
Set the semantic head pos of the phrase


setWord

public void setWord(java.lang.String word)
Set the head word for the label by storing it in the map under the key HEAD_WORD_KEY.

Specified by:
setWord in interface HasWord
Parameters:
word - the head word for the label

tag

public java.lang.String tag()
Return the head tag of the label (or null if none), which is stored in the map under the key HEAD_TAG_KEY.

Specified by:
tag in interface HasTag
Returns:
the head tag for the label

setTag

public void setTag(java.lang.String tag)
Set the head tag for the label by storing it in the map under the key HEAD_TAG_KEY.

Specified by:
setTag in interface HasTag
Parameters:
tag - the head tag for the label

map

public java.util.Map map()
Return the Map contained in this label.

Returns:
the Map contained in this label

setMap

public void setMap(java.util.Map map)
Set the Map contained in this label to the supplied Map.

Parameters:
map - the new Map for this label

index

public int index()
Return the index of the label (or -1 if none), which is stored in the map under the key INDEX_KEY.

Returns:
the index for the label

setIndex

public int setIndex(int index)
Set the index for the label by storing it in the contained map under the key INDEX_KEY. Returns the old index (or -1 if none).

Returns:
the old index for the label (or -1 if none).

get

public java.lang.Object get(java.lang.Object key)
Returns the value to which the map contained in this label maps the specified key. Returns null if the map contains no mapping for this key. (Analogous to Map.get(Object key).)

Parameters:
key - key whose associated value is to be returned.
Returns:
the value to which the map contained in this label maps the specified key, or null if the map contains no mapping for this key.

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Associates the specified value with the specified key in the map contained in this label. (Analogous to Map.put(Object key, Object value).) If the map previously contained a mapping for this key, the old value is replaced by the specified value.

Parameters:
key - key with which the specified value is to be associated.
value - value to be associated with the specified key.
Returns:
previous value associated with specified key, or null if there was no mapping for key.

labelFactory

public LabelFactory labelFactory()
Return a factory for MapLabels. The factory returned is always the same one (a singleton).

Specified by:
labelFactory in interface Label
Specified by:
labelFactory in class AbstractLabel
Returns:
the label factory

factory

public static LabelFactory factory()
Return a factory for MapLabels. The factory returned is always the same one (a singleton).

Returns:
the label factory

toString

public java.lang.String toString()
Return a String containing the value (and index, if any) of this label. This is equivalent to toString("value-index").

Specified by:
toString in interface Label
Overrides:
toString in class AbstractLabel
Returns:
the string representation

toString

public java.lang.String toString(java.lang.String format)
Returns a formatted string representing this label. The desired format is passed in as a String. Currently supported formats include:


main

public static void main(java.lang.String[] args)
For testing only.