Package edu.stanford.nlp.ling
Class StringLabel
- java.lang.Object
-
- edu.stanford.nlp.ling.ValueLabel
-
- edu.stanford.nlp.ling.StringLabel
-
- All Implemented Interfaces:
HasOffset,Label,Serializable,Comparable<ValueLabel>
- Direct Known Subclasses:
CategoryWordTag,NegraLabel,Tag,Word
public class StringLabel extends ValueLabel implements HasOffset
AStringLabelobject acts as a Label by containing a single String, which it sets or returns in response to requests. The hashCode() and compareTo() methods for this class assume that this string value is non-null. equals() is correctly implemented- Version:
- 2000/12/20
- Author:
- Christopher Manning
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description StringLabel()Create a newStringLabelwith a null content (i.e., str).StringLabel(Label label)Create a newStringLabelwith thevalue()of another label as its label.StringLabel(String str)Create a newStringLabelwith the given content.StringLabel(String str, int beginPosition, int endPosition)Create a newStringLabelwith the given content.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intbeginPosition()Return the beginning char offset of the label (or -1 if none).intendPosition()Return the ending char offset of the label (or -1 if none).static LabelFactoryfactory()Return a factory for this kind of label.LabelFactorylabelFactory()Return a factory for this kind of label (i.e.,StringLabel).voidsetBeginPosition(int beginPosition)Set the beginning character offset for the label.voidsetEndPosition(int endPosition)Set the ending character offset of the label (or -1 if none).voidsetFromString(String str)Set the label from a String.voidsetValue(String value)Set the value for the label.StringtoString()Return a string representation of the label.Stringvalue()Return the word value of the label (or null if none).-
Methods inherited from class edu.stanford.nlp.ling.ValueLabel
compareTo, equals, hashCode
-
-
-
-
Constructor Detail
-
StringLabel
public StringLabel()
Create a newStringLabelwith a null content (i.e., str).
-
StringLabel
public StringLabel(String str)
Create a newStringLabelwith the given content.- Parameters:
str- The new label's content
-
StringLabel
public StringLabel(String str, int beginPosition, int endPosition)
Create a newStringLabelwith the given content.- Parameters:
str- The new label's contentbeginPosition- Start offset in original textendPosition- End offset in original text
-
StringLabel
public StringLabel(Label label)
Create a newStringLabelwith thevalue()of another label as its label.- Parameters:
label- The other label
-
-
Method Detail
-
value
public String value()
Return the word value of the label (or null if none).- Specified by:
valuein interfaceLabel- Overrides:
valuein classValueLabel- Returns:
- String the word value for the label
-
setValue
public void setValue(String value)
Set the value for the label.- Specified by:
setValuein interfaceLabel- Overrides:
setValuein classValueLabel- Parameters:
value- The value for the label
-
setFromString
public void setFromString(String str)
Set the label from a String.- Specified by:
setFromStringin interfaceLabel- Overrides:
setFromStringin classValueLabel- Parameters:
str- The str for the label
-
toString
public String toString()
Description copied from class:ValueLabelReturn a string representation of the label. This will just be thevalue()if it is non-null, and the empty string otherwise.- Specified by:
toStringin interfaceLabel- Overrides:
toStringin classValueLabel- Returns:
- The string representation
-
labelFactory
public LabelFactory labelFactory()
Return a factory for this kind of label (i.e.,StringLabel). The factory returned is always the same one (a singleton).- Specified by:
labelFactoryin interfaceLabel- Specified by:
labelFactoryin classValueLabel- Returns:
- The label factory
-
factory
public static LabelFactory factory()
Return a factory for this kind of label.- Returns:
- The label factory
-
beginPosition
public int beginPosition()
Description copied from interface:HasOffsetReturn the beginning char offset of the label (or -1 if none). Note that these are currently measured in terms of UTF-16 char offsets, not codepoints, so that when non-BMP Unicode characters are present, such a character will add 2 to the position. On the other hand, these values will work with String#substring() and you can then calculate the number of codepoints in a substring.- Specified by:
beginPositionin interfaceHasOffset- Returns:
- the beginning position for the label
-
endPosition
public int endPosition()
Description copied from interface:HasOffsetReturn the ending char offset of the label (or -1 if none). As usual in Java, this is the offset of the char after this token. Note that these are currently measured in terms of UTF-16 char offsets, not codepoints, so that when non-BMP Unicode characters are present, such a character will add 2 to the position. On the other hand, these values will work with String#substring() and you can then calculate the number of codepoints in a substring.- Specified by:
endPositionin interfaceHasOffset- Returns:
- the end position for the label
-
setBeginPosition
public void setBeginPosition(int beginPosition)
Description copied from interface:HasOffsetSet the beginning character offset for the label. Setting this key to "-1" can be used to indicate no valid value.- Specified by:
setBeginPositionin interfaceHasOffset- Parameters:
beginPosition- The beginning position
-
setEndPosition
public void setEndPosition(int endPosition)
Description copied from interface:HasOffsetSet the ending character offset of the label (or -1 if none).- Specified by:
setEndPositionin interfaceHasOffset- Parameters:
endPosition- The end character offset for the label
-
-