Package elki.data
Class HierarchicalClassLabel
- java.lang.Object
-
- elki.data.ClassLabel
-
- elki.data.HierarchicalClassLabel
-
- All Implemented Interfaces:
java.lang.Comparable<ClassLabel>
public class HierarchicalClassLabel extends ClassLabel
A HierarchicalClassLabel is a ClassLabel to reflect a hierarchical structure of classes.- Since:
- 0.1
- Author:
- Arthur Zimek
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
HierarchicalClassLabel.Factory
Factory class.
-
Field Summary
Fields Modifier and Type Field Description static java.util.regex.Pattern
DEFAULT_SEPARATOR
The default separator pattern, a point ('.').static java.lang.String
DEFAULT_SEPARATOR_STRING
The default separator, a point ('.').private java.lang.Comparable<?>[]
levelwiseNames
Holds the names on the different levels.private java.util.regex.Pattern
separatorPattern
Holds the Pattern to separate different levels parsing input.private java.lang.String
separatorString
A String to separate different levels in a String representation of this HierarchicalClassLabel.static SimpleTypeInformation<HierarchicalClassLabel>
TYPE
Type information.
-
Constructor Summary
Constructors Constructor Description HierarchicalClassLabel(java.lang.String label)
Constructs a hierarchical class label from the given name.HierarchicalClassLabel(java.lang.String name, java.util.regex.Pattern regex, java.lang.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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(ClassLabel o)
Compares two HierarchicalClassLabels.int
depth()
The length of the hierarchy of names.java.lang.String
getNameAt(int level)
Returns the name at the given level as a String.java.lang.String
toString()
Returns a String representation of this HierarchicalClassLabel usingseparatorString
to separate levels.java.lang.String
toString(int level)
Create a String representation of this ClassLabel comprising only the firstlevel
levels.-
Methods inherited from class elki.data.ClassLabel
equals, hashCode
-
-
-
-
Field Detail
-
DEFAULT_SEPARATOR
public static final java.util.regex.Pattern DEFAULT_SEPARATOR
The default separator pattern, a point ('.').
-
DEFAULT_SEPARATOR_STRING
public static final java.lang.String DEFAULT_SEPARATOR_STRING
The default separator, a point ('.').- See Also:
- Constant Field Values
-
TYPE
public static final SimpleTypeInformation<HierarchicalClassLabel> TYPE
Type information.
-
separatorPattern
private java.util.regex.Pattern separatorPattern
Holds the Pattern to separate different levels parsing input.
-
separatorString
private java.lang.String separatorString
A String to separate different levels in a String representation of this HierarchicalClassLabel.
-
levelwiseNames
private java.lang.Comparable<?>[] levelwiseNames
Holds the names on the different levels.
-
-
Constructor Detail
-
HierarchicalClassLabel
public HierarchicalClassLabel(java.lang.String name, java.util.regex.Pattern regex, java.lang.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.- Parameters:
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 HierarchicalClassLabel
-
HierarchicalClassLabel
public HierarchicalClassLabel(java.lang.String label)
Constructs a hierarchical class label from the given name. Different levels are supposed to be separated by points ('.'), as defined byDEFAULT_SEPARATOR
. Also, in a String-representation of this HierarchicalClassLabel, different levels get separated by '.'.- Parameters:
label
- a String describing a hierarchical class label
-
-
Method Detail
-
compareTo
public int compareTo(ClassLabel o)
Compares two HierarchicalClassLabels. Names at higher levels are compared first. Names at a lower level are compared only if their parent-names are equal. Names at a level are tried to be compared as integer values. If this does not succeed, both names are compared as Strings.
-
depth
public int depth()
The length of the hierarchy of names.- Returns:
- length of the hierarchy of names
-
getNameAt
public java.lang.String getNameAt(int level)
Returns the name at the given level as a String.- Parameters:
level
- the level to return the name at- Returns:
- the name at the given level as a String
-
toString
public java.lang.String toString()
Returns a String representation of this HierarchicalClassLabel usingseparatorString
to separate levels.- Specified by:
toString
in classClassLabel
-
toString
public java.lang.String toString(int level)
Create a String representation of this ClassLabel comprising only the firstlevel
levels.- Parameters:
level
- the lowest level to include in the String representation.- Returns:
- a String representation of this ClassLabel comprising only the
first
level
levels
-
-