|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectweka.core.Attribute
Class for handling an attribute. Once an attribute has been created, it can't be changed.
Three attribute types are supported:
...
// Create numeric attributes "length" and "weight"
Attribute length = new Attribute("length");
Attribute weight = new Attribute("weight");
// Create vector to hold nominal values "first", "second", "third"
FastVector my_nominal_values = new FastVector(3);
my_nominal_values.addElement("first");
my_nominal_values.addElement("second");
my_nominal_values.addElement("third");
// Create nominal attribute "position"
Attribute position = new Attribute("position", my_nominal_values);
...
Field Summary | |
(package private) static java.lang.String |
ARFF_ATTRIBUTE
The keyword used to denote the start of an arff attribute declaration |
(package private) static java.lang.String |
ARFF_ATTRIBUTE_DATE
The keyword used to denote a date attribute |
(package private) static java.lang.String |
ARFF_ATTRIBUTE_INTEGER
A keyword used to denote a numeric attribute |
(package private) static java.lang.String |
ARFF_ATTRIBUTE_NUMERIC
A keyword used to denote a numeric attribute |
(package private) static java.lang.String |
ARFF_ATTRIBUTE_REAL
A keyword used to denote a numeric attribute |
(package private) static java.lang.String |
ARFF_ATTRIBUTE_STRING
The keyword used to denote a string attribute |
static int |
DATE
Constant set for attributes with date values. |
private java.text.SimpleDateFormat |
m_DateFormat
Date format specification for date attributes |
private java.util.Hashtable |
m_Hashtable
Mapping of values to indices (if nominal or string). |
private boolean |
m_HasZeropoint
Whether the attribute has a zeropoint. |
private int |
m_Index
The attribute's index. |
private boolean |
m_IsAveragable
Whether the attribute is averagable. |
private boolean |
m_IsRegular
Whether the attribute is regular. |
private double |
m_LowerBound
The attribute's lower numeric bound. |
private boolean |
m_LowerBoundIsOpen
Whether the lower bound is open. |
private ProtectedProperties |
m_Metadata
The attribute's metadata. |
private java.lang.String |
m_Name
The attribute's name. |
private int |
m_Ordering
The attribute's ordering. |
private int |
m_Type
The attribute's type. |
private double |
m_UpperBound
The attribute's upper numeric bound. |
private boolean |
m_UpperBoundIsOpen
Whether the upper bound is open |
private FastVector |
m_Values
The attribute's values (if nominal or string). |
private double |
m_Weight
The attribute's weight. |
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 |
STRING
Constant set for attributes with string values. |
private static int |
STRING_COMPRESS_THRESHOLD
Strings longer than this will be stored compressed. |
Constructor Summary | |
|
Attribute(java.lang.String attributeName)
Constructor for a numeric attribute. |
|
Attribute(java.lang.String attributeName,
FastVector attributeValues)
Constructor for nominal attributes and string attributes. |
(package private) |
Attribute(java.lang.String attributeName,
FastVector attributeValues,
int index)
Constructor for nominal attributes and string attributes with a particular index. |
|
Attribute(java.lang.String attributeName,
FastVector attributeValues,
ProtectedProperties metadata)
Constructor for nominal attributes and string attributes, where metadata is supplied. |
(package private) |
Attribute(java.lang.String attributeName,
int index)
Constructor for a numeric attribute with a particular index. |
|
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. |
(package private) |
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. |
Method Summary | |
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. |
(package private) void |
addValue(java.lang.String value)
Adds an attribute value. |
java.lang.Object |
copy()
Produces a shallow copy of this attribute. |
(package private) Attribute |
copy(java.lang.String newName)
Produces a shallow copy of this attribute with a new name. |
(package private) void |
delete(int index)
Removes a value of a nominal or string attribute. |
java.util.Enumeration |
enumerateValues()
Returns an enumeration of all the attribute's values if the attribute is nominal or a string, null otherwise. |
boolean |
equals(java.lang.Object other)
Tests if given attribute is equal to this attribute. |
(package private) void |
forceAddValue(java.lang.String value)
Adds an attribute value. |
java.lang.String |
formatDate(double date)
|
double |
getLowerNumericBound()
Returns the lower bound of a numeric attribute. |
ProtectedProperties |
getMetadata()
Returns the properties supplied for this attribute. |
double |
getUpperNumericBound()
Returns the upper bound of a numeric attribute. |
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 |
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)
|
(package private) void |
setIndex(int index)
Sets the index of this attribute. |
private void |
setMetadata(ProtectedProperties metadata)
Sets the metadata for the attribute. |
private void |
setNumericRange(java.lang.String rangeString)
Sets the numeric range based on a string. |
(package private) void |
setValue(int index,
java.lang.String string)
Sets a value of a nominal attribute or string attribute. |
java.lang.String |
toString()
Returns a description of this attribute in ARFF format. |
int |
type()
Returns the attribute's type as an integer. |
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. |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int NUMERIC
public static final int NOMINAL
public static final int STRING
public static final int DATE
public static final int ORDERING_SYMBOLIC
public static final int ORDERING_ORDERED
public static final int ORDERING_MODULO
static java.lang.String ARFF_ATTRIBUTE
static java.lang.String ARFF_ATTRIBUTE_INTEGER
static java.lang.String ARFF_ATTRIBUTE_REAL
static java.lang.String ARFF_ATTRIBUTE_NUMERIC
static java.lang.String ARFF_ATTRIBUTE_STRING
static java.lang.String ARFF_ATTRIBUTE_DATE
private static final int STRING_COMPRESS_THRESHOLD
private java.lang.String m_Name
private int m_Type
private FastVector m_Values
private java.util.Hashtable m_Hashtable
private java.text.SimpleDateFormat m_DateFormat
private int m_Index
private ProtectedProperties m_Metadata
private int m_Ordering
private boolean m_IsRegular
private boolean m_IsAveragable
private boolean m_HasZeropoint
private double m_Weight
private double m_LowerBound
private boolean m_LowerBoundIsOpen
private double m_UpperBound
private boolean m_UpperBoundIsOpen
Constructor Detail |
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, 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, FastVector 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, FastVector 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 propertiesAttribute(java.lang.String attributeName, int index)
attributeName
- the name for the attributeindex
- the attribute's indexAttribute(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 indexAttribute(java.lang.String attributeName, FastVector 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 indexMethod Detail |
public java.lang.Object copy()
copy
in interface Copyable
public final java.util.Enumeration enumerateValues()
public final boolean equals(java.lang.Object other)
other
- the Object to be compared to this attribute
public final int index()
public final int indexOfValue(java.lang.String value)
value
- the value for which the index is to be returned
public final boolean isNominal()
public final boolean isNumeric()
public final boolean isString()
public final boolean isDate()
public final java.lang.String name()
public final int numValues()
public final java.lang.String toString()
public final int type()
public final java.lang.String value(int valIndex)
valIndex
- the value's index
public int addStringValue(java.lang.String value)
value
- The string value to add
public int addStringValue(Attribute src, int index)
src
- The Attribute containing the string value to add.
final void addValue(java.lang.String value)
value
- the attribute valuefinal Attribute copy(java.lang.String newName)
newName
- the name of the new attribute
final void delete(int index)
index
- the value's index
java.lang.IllegalArgumentException
- if the attribute is not nominalfinal void forceAddValue(java.lang.String value)
value
- the attribute valuefinal void setIndex(int index)
final void setValue(int index, java.lang.String string)
index
- the value's indexstring
- the value
java.lang.IllegalArgumentException
- if the attribute is not nominal or
string.public java.lang.String formatDate(double date)
public double parseDate(java.lang.String string) throws java.text.ParseException
java.text.ParseException
public final ProtectedProperties getMetadata()
public final int ordering()
public final boolean isRegular()
public final boolean isAveragable()
public final boolean hasZeropoint()
public final double weight()
public final double getLowerNumericBound()
public final boolean lowerNumericBoundIsOpen()
public final double getUpperNumericBound()
public final boolean upperNumericBoundIsOpen()
public final boolean isInRange(double value)
private void setMetadata(ProtectedProperties metadata)
metadata
- the metadata
java.lang.IllegalArgumentException
- if the properties are not consistentprivate void setNumericRange(java.lang.String rangeString)
rangeString
- the string to parse as the attribute's numeric range
java.lang.IllegalArgumentException
- if the range is not validpublic static void main(java.lang.String[] ops)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |