public class Attribute extends java.lang.Object implements Copyable, java.io.Serializable, RevisionHandler
The following attribute types are supported:
yyyy-MM-dd'T'HH:mm:ss
.
...
// Create numeric attributes "length" and "weight"
Attribute length = new Attribute("length");
Attribute weight = new Attribute("weight");
// Create list to hold nominal values "first", "second", "third"
List
my_nominal_values.add("first");
my_nominal_values.add("second");
my_nominal_values.add("third");
// Create nominal attribute "position"
Attribute position = new Attribute("position", my_nominal_values);
...
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ARFF_ATTRIBUTE
The keyword used to denote the start of an arff attribute declaration
|
static java.lang.String |
ARFF_ATTRIBUTE_DATE
The keyword used to denote a date attribute
|
static java.lang.String |
ARFF_ATTRIBUTE_INTEGER
A keyword used to denote a numeric attribute
|
static java.lang.String |
ARFF_ATTRIBUTE_NUMERIC
A keyword used to denote a numeric attribute
|
static java.lang.String |
ARFF_ATTRIBUTE_REAL
A keyword used to denote a numeric attribute
|
static java.lang.String |
ARFF_ATTRIBUTE_RELATIONAL
The keyword used to denote a relation-valued attribute
|
static java.lang.String |
ARFF_ATTRIBUTE_STRING
The keyword used to denote a string attribute
|
static java.lang.String |
ARFF_END_SUBRELATION
The keyword used to denote the end of the declaration of a subrelation
|
static int |
DATE
Constant set for attributes with date values.
|
static int |
NOMINAL
Constant set for nominal attributes.
|
static int |
NUMERIC
Constant set for numeric attributes.
|
static int |
ORDERING_MODULO
Constant set for modulo-ordered attributes.
|
static int |
ORDERING_ORDERED
Constant set for ordered attributes.
|
static int |
ORDERING_SYMBOLIC
Constant set for symbolic attributes.
|
static int |
RELATIONAL
Constant set for relation-valued attributes.
|
static int |
STRING
Constant set for attributes with string values.
|
Constructor and Description |
---|
Attribute(java.lang.String attributeName)
Constructor for a numeric attribute.
|
Attribute(java.lang.String attributeName,
boolean createStringAttribute)
Constructor for a numeric or string attribute.
|
Attribute(java.lang.String attributeName,
boolean createStringAttribute,
ProtectedProperties metadata)
Constructor for a numeric or string attribute, where metadata is supplied.
|
Attribute(java.lang.String attributeName,
Instances header)
Constructor for relation-valued attributes.
|
Attribute(java.lang.String attributeName,
Instances header,
int index)
Constructor for a relation-valued attribute with a particular index.
|
Attribute(java.lang.String attributeName,
Instances header,
ProtectedProperties metadata)
Constructor for relation-valued attributes.
|
Attribute(java.lang.String attributeName,
int index)
Constructor for a numeric attribute with a particular index.
|
Attribute(java.lang.String attributeName,
java.util.List<java.lang.String> attributeValues)
Constructor for nominal attributes and string attributes.
|
Attribute(java.lang.String attributeName,
java.util.List<java.lang.String> attributeValues,
int index)
Constructor for nominal attributes and string attributes with a particular
index.
|
Attribute(java.lang.String attributeName,
java.util.List<java.lang.String> attributeValues,
ProtectedProperties metadata)
Constructor for nominal attributes and string attributes, where metadata is
supplied.
|
Attribute(java.lang.String attributeName,
ProtectedProperties metadata)
Constructor for a numeric attribute, where metadata is supplied.
|
Attribute(java.lang.String attributeName,
java.lang.String dateFormat)
Constructor for a date attribute.
|
Attribute(java.lang.String attributeName,
java.lang.String dateFormat,
int index)
Constructor for date attributes with a particular index.
|
Attribute(java.lang.String attributeName,
java.lang.String dateFormat,
ProtectedProperties metadata)
Constructor for a date attribute, where metadata is supplied.
|
Modifier and Type | Method and Description |
---|---|
int |
addRelation(Instances value)
Adds a relation to a relation-valued attribute.
|
int |
addStringValue(Attribute src,
int index)
Adds a string value to the list of valid strings for attributes of type
STRING and returns the index of the string.
|
int |
addStringValue(java.lang.String value)
Adds a string value to the list of valid strings for attributes of type
STRING and returns the index of the string.
|
java.lang.Object |
copy()
Produces a shallow copy of this attribute.
|
Attribute |
copy(java.lang.String newName)
Produces a shallow copy of this attribute with a new name.
|
java.util.Enumeration<java.lang.Object> |
enumerateValues()
Returns an enumeration of all the attribute's values if the attribute is
nominal, string, or relation-valued, null otherwise.
|
boolean |
equals(java.lang.Object other)
Tests if given attribute is equal to this attribute.
|
java.lang.String |
equalsMsg(java.lang.Object other)
Tests if given attribute is equal to this attribute.
|
java.lang.String |
formatDate(double date)
Returns the given amount of milliseconds formatted according to the current
Date format.
|
java.lang.String |
getDateFormat()
Returns the Date format pattern in case this attribute is of type DATE,
otherwise an empty string.
|
double |
getLowerNumericBound()
Returns the lower bound of a numeric attribute.
|
ProtectedProperties |
getMetadata()
Returns the properties supplied for this attribute.
|
java.lang.String |
getRevision()
Returns the revision string.
|
double |
getUpperNumericBound()
Returns the upper bound of a numeric attribute.
|
int |
hashCode()
Returns a hash code for this attribute based on its name.
|
boolean |
hasZeropoint()
Returns whether the attribute has a zeropoint and may be added
meaningfully.
|
int |
index()
Returns the index of this attribute.
|
int |
indexOfValue(java.lang.String value)
Returns the index of a given attribute value.
|
boolean |
isAveragable()
Returns whether the attribute can be averaged meaningfully.
|
boolean |
isDate()
Tests if the attribute is a date type.
|
boolean |
isInRange(double value)
Determines whether a value lies within the bounds of the attribute.
|
boolean |
isNominal()
Test if the attribute is nominal.
|
boolean |
isNumeric()
Tests if the attribute is numeric.
|
boolean |
isRegular()
Returns whether the attribute values are equally spaced.
|
boolean |
isRelationValued()
Tests if the attribute is relation valued.
|
boolean |
isString()
Tests if the attribute is a string.
|
boolean |
lowerNumericBoundIsOpen()
Returns whether the lower numeric bound of the attribute is open.
|
static void |
main(java.lang.String[] ops)
Simple main method for testing this class.
|
java.lang.String |
name()
Returns the attribute's name.
|
int |
numValues()
Returns the number of attribute values.
|
int |
ordering()
Returns the ordering of the attribute.
|
double |
parseDate(java.lang.String string)
Parses the given String as Date, according to the current format and
returns the corresponding amount of milliseconds.
|
Instances |
relation()
Returns the header info for a relation-valued attribute, null if the
attribute is not relation-valued.
|
Instances |
relation(int valIndex)
Returns a value of a relation-valued attribute.
|
void |
setStringValue(java.lang.String value)
Clear the map and list of values and set them to contain just the supplied
value
|
void |
setWeight(double value)
Sets the new attribute's weight.
|
java.lang.String |
toString()
Returns a description of this attribute in ARFF format.
|
int |
type()
Returns the attribute's type as an integer.
|
static java.lang.String |
typeToString(Attribute att)
Returns a string representation of the attribute type.
|
static java.lang.String |
typeToString(int type)
Returns a string representation of the attribute type.
|
static java.lang.String |
typeToStringShort(Attribute att)
Returns a short string representation of the attribute type.
|
static java.lang.String |
typeToStringShort(int type)
Returns a short string representation of the attribute type.
|
boolean |
upperNumericBoundIsOpen()
Returns whether the upper numeric bound of the attribute is open.
|
java.lang.String |
value(int valIndex)
Returns a value of a nominal or string attribute.
|
double |
weight()
Returns the attribute's weight.
|
public static final int NUMERIC
public static final int NOMINAL
public static final int STRING
public static final int DATE
public static final int RELATIONAL
public static final int ORDERING_SYMBOLIC
public static final int ORDERING_ORDERED
public static final int ORDERING_MODULO
public static final java.lang.String ARFF_ATTRIBUTE
public static final java.lang.String ARFF_ATTRIBUTE_INTEGER
public static final java.lang.String ARFF_ATTRIBUTE_REAL
public static final java.lang.String ARFF_ATTRIBUTE_NUMERIC
public static final java.lang.String ARFF_ATTRIBUTE_STRING
public static final java.lang.String ARFF_ATTRIBUTE_DATE
public static final java.lang.String ARFF_ATTRIBUTE_RELATIONAL
public static final java.lang.String ARFF_END_SUBRELATION
public Attribute(java.lang.String attributeName)
attributeName
- the name for the attributepublic Attribute(java.lang.String attributeName, ProtectedProperties metadata)
attributeName
- the name for the attributemetadata
- the attribute's propertiespublic Attribute(java.lang.String attributeName, boolean createStringAttribute)
attributeName
- the name for the attributecreateStringAttribute
- if true, a string attribute will be created, otherwise a numeric one.public Attribute(java.lang.String attributeName, boolean createStringAttribute, ProtectedProperties metadata)
attributeName
- the name for the attributecreateStringAttribute
- if true, a string attribute will be created, otherwise a numeric one.metadata
- the attribute's propertiespublic Attribute(java.lang.String attributeName, java.lang.String dateFormat)
attributeName
- the name for the attributedateFormat
- a string suitable for use with SimpleDateFormatter for
parsing dates.public Attribute(java.lang.String attributeName, java.lang.String dateFormat, ProtectedProperties metadata)
attributeName
- the name for the attributedateFormat
- a string suitable for use with SimpleDateFormatter for
parsing dates.metadata
- the attribute's propertiespublic Attribute(java.lang.String attributeName, java.util.List<java.lang.String> attributeValues)
attributeName
- the name for the attributeattributeValues
- a vector of strings denoting the attribute values.
Null if the attribute is a string attribute.public Attribute(java.lang.String attributeName, java.util.List<java.lang.String> attributeValues, ProtectedProperties metadata)
attributeName
- the name for the attributeattributeValues
- a vector of strings denoting the attribute values.
Null if the attribute is a string attribute.metadata
- the attribute's propertiespublic Attribute(java.lang.String attributeName, Instances header)
attributeName
- the name for the attributeheader
- an Instances object specifying the header of the relation.public Attribute(java.lang.String attributeName, Instances header, ProtectedProperties metadata)
attributeName
- the name for the attributeheader
- an Instances object specifying the header of the relation.metadata
- the attribute's propertiespublic Attribute(java.lang.String attributeName, int index)
attributeName
- the name for the attributeindex
- the attribute's indexpublic Attribute(java.lang.String attributeName, java.lang.String dateFormat, int index)
attributeName
- the name for the attributedateFormat
- a string suitable for use with SimpleDateFormatter for
parsing dates. Null for a default format string.index
- the attribute's indexpublic Attribute(java.lang.String attributeName, java.util.List<java.lang.String> attributeValues, int index)
attributeName
- the name for the attributeattributeValues
- a vector of strings denoting the attribute values.
Null if the attribute is a string attribute.index
- the attribute's indexpublic Attribute(java.lang.String attributeName, Instances header, int index)
attributeName
- the name for the attributeheader
- the header information for this attributeindex
- the attribute's indexpublic java.lang.Object copy()
public final java.util.Enumeration<java.lang.Object> enumerateValues()
public final boolean equals(java.lang.Object other)
equals
in class java.lang.Object
other
- the Object to be compared to this attributepublic final int hashCode()
hashCode
in class java.lang.Object
public final java.lang.String equalsMsg(java.lang.Object other)
other
- the Object to be compared to this attributepublic static java.lang.String typeToString(Attribute att)
att
- the attribute to return the type string forpublic static java.lang.String typeToString(int type)
type
- the type of the attributepublic static java.lang.String typeToStringShort(Attribute att)
att
- the attribute to return the type string forpublic static java.lang.String typeToStringShort(int type)
type
- the type of the attributepublic final int index()
public final int indexOfValue(java.lang.String value)
value
- the value for which the index is to be returnedpublic final boolean isNominal()
public final boolean isNumeric()
public final boolean isRelationValued()
public final boolean isString()
public final boolean isDate()
public final java.lang.String name()
public final int numValues()
public final java.lang.String toString()
toString
in class java.lang.Object
public final int type()
public final java.lang.String getDateFormat()
SimpleDateFormat
public final java.lang.String value(int valIndex)
valIndex
- the value's indexpublic final Instances relation()
public final Instances relation(int valIndex)
valIndex
- the value's indexpublic int addStringValue(java.lang.String value)
value
- The string value to addpublic void setStringValue(java.lang.String value)
value
- the current (and only) value of this String attribute. If null
then just the map is cleared.public int addStringValue(Attribute src, int index)
src
- The Attribute containing the string value to add.index
- the index of the string value in the source attribute.public int addRelation(Instances value)
value
- The value to addpublic final Attribute copy(java.lang.String newName)
newName
- the name of the new attributepublic java.lang.String formatDate(double date)
date
- the date, represented in milliseconds since January 1, 1970,
00:00:00 GMT, to return as stringpublic double parseDate(java.lang.String string) throws java.text.ParseException
string
- the date to parsejava.text.ParseException
- if parsing failspublic final ProtectedProperties getMetadata()
public final int ordering()
public final boolean isRegular()
public final boolean isAveragable()
public final boolean hasZeropoint()
public final double weight()
public void setWeight(double value)
value
- the new weightpublic final double getLowerNumericBound()
public final boolean lowerNumericBoundIsOpen()
public final double getUpperNumericBound()
public final boolean upperNumericBoundIsOpen()
public final boolean isInRange(double value)
value
- the value to checkpublic java.lang.String getRevision()
getRevision
in interface RevisionHandler
public static void main(java.lang.String[] ops)
ops
- the commandline options