public class HierarchicalClassLabel extends ClassLabel
Modifier and Type | Class and Description |
---|---|
static class |
HierarchicalClassLabel.Factory
Factory class.
|
Modifier and Type | Field and Description |
---|---|
static Pattern |
DEFAULT_SEPARATOR
The default separator pattern, a point ('.').
|
static String |
DEFAULT_SEPARATOR_STRING
The default separator, a point ('.').
|
private Comparable<?>[] |
levelwiseNames
Holds the names on the different levels.
|
private Pattern |
separatorPattern
Holds the Pattern to separate different levels parsing input.
|
private String |
separatorString
A String to separate different levels in a String representation of this
HierarchicalClassLabel.
|
static SimpleTypeInformation<HierarchicalClassLabel> |
TYPE
Type information.
|
Constructor and Description |
---|
HierarchicalClassLabel(String label)
Constructs a hierarchical class label from the given name.
|
HierarchicalClassLabel(String name,
Pattern regex,
String separator)
Constructs a hierarchical class label from the given name, using the given
Pattern to match separators of different levels in the given name, and
setting the given separator-String to separate different levels in String
representations of this HierarchicalClassLabel.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(ClassLabel o)
Compares two HierarchicalClassLabels.
|
int |
depth()
The length of the hierarchy of names.
|
String |
getNameAt(int level)
Returns the name at the given level as a String.
|
String |
toString()
Returns a String representation of this HierarchicalClassLabel using
separatorString to separate levels. |
String |
toString(int level)
Provides a String representation of this ClassLabel comprising only the
first
level levels. |
equals, hashCode
public static final Pattern DEFAULT_SEPARATOR
public static final String DEFAULT_SEPARATOR_STRING
public static final SimpleTypeInformation<HierarchicalClassLabel> TYPE
private Pattern separatorPattern
private String separatorString
private Comparable<?>[] levelwiseNames
public HierarchicalClassLabel(String name, Pattern regex, String separator)
name
- a String describing a hierarchical class labelregex
- a Pattern to match separators of different levels in the given
nameseparator
- a separator String to separate different levels in the
String-representation of this HierarchicalClassLabelpublic HierarchicalClassLabel(String label)
DEFAULT_SEPARATOR
. Also, in a
String-representation of this HierarchicalClassLabel, different levels get
separated by '.'.label
- a String describing a hierarchical class labelpublic int compareTo(ClassLabel o)
public int depth()
public String getNameAt(int level)
level
- the level to return the name atpublic String toString()
separatorString
to separate levels.
Any ClassLabel requires a method to represent the label as a String. If
ClassLabel a.equals((ClassLabel) b)
, then also
a.toString().equals(b.toString())
should hold.
toString
in class ClassLabel
public String toString(int level)
level
levels.level
- the lowest level to include in the String representation.level
levels