|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--weka.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 | |
static int |
NOMINAL
Constant set for nominal attributes. |
static int |
NUMERIC
Constant set for numeric attributes. |
static int |
STRING
Constant set for attributes with string values. |
Constructor Summary | |
Attribute(String attributeName)
Constructor for a numeric attribute. |
|
Attribute(String attributeName,
FastVector attributeValues)
Constructor for nominal attributes and string attributes. |
|
Attribute(String attributeName,
FastVector attributeValues,
int index)
Constructor for nominal attributes and string attributes with a particular index. |
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(String value)
Adds a string value to the list of valid strings for attributes of type STRING and returns the index of the string. |
Object |
copy()
Produces a shallow copy of this attribute. |
Enumeration |
enumerateValues()
Returns an enumeration of all the attribute's values if the attribute is nominal or a string, null otherwise. |
boolean |
equals(Object other)
Tests if given attribute is equal to this attribute. |
int |
hashCode()
|
int |
index()
Returns the index of this attribute. |
int |
indexOfValue(String value)
Returns the index of a given attribute value. |
boolean |
isNominal()
Test if the attribute is nominal. |
boolean |
isNumeric()
Tests if the attribute is numeric. |
boolean |
isString()
Tests if the attribute is a string. |
static void |
main(String[] ops)
Simple main method for testing this class. |
String |
name()
Returns the attribute's name. |
int |
numValues()
Returns the number of attribute values. |
String |
toString()
Returns a description of this attribute in ARFF format. |
int |
type()
Returns the attribute's type as an integer. |
String |
value(int valIndex)
Returns a value of a nominal or string attribute. |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int NUMERIC
public static final int NOMINAL
public static final int STRING
Constructor Detail |
public Attribute(String attributeName)
attributeName
- the name for the attributepublic Attribute(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(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 Object copy()
copy
in interface Copyable
public final Enumeration enumerateValues()
public final int hashCode()
hashCode
in class Object
public final boolean equals(Object other)
equals
in class Object
other
- the Object to be compared to this attribute
public final int index()
public final int indexOfValue(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 String name()
public final int numValues()
public final String toString()
toString
in class Object
public final int type()
public final String value(int valIndex)
valIndex
- the value's index
public int addStringValue(String value)
value
- The string value to add
public int addStringValue(Attribute src, int index)
src
- The Attribute containing the string value to add.
public static void main(String[] ops)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |