All Packages  Class Hierarchy  This Package  Previous  Next  Index  WEKA's home

Class weka.core.Attribute

java.lang.Object
    |
    +----weka.core.Attribute

public class Attribute
extends java.lang.Object
implements Copyable, java.io.Serializable
Class for handling an attribute. Once an attribute has been created, it can't be changed.

Three attribute types are supported:

Typical usage (code from the main() method of this class):

...
// 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);
...

Version:
$Revision: 1.29 $
Author:
Eibe Frank (eibe@cs.waikato.ac.nz)

Variable Index

 o DATE
Constant set for attributes with date values.
 o NOMINAL
Constant set for nominal attributes.
 o NUMERIC
Constant set for numeric attributes.
 o ORDERING_MODULO
Constant set for modulo-ordered attributes.
 o ORDERING_ORDERED
Constant set for ordered attributes.
 o ORDERING_SYMBOLIC
Constant set for symbolic attributes.
 o STRING
Constant set for attributes with string values.

Constructor Index

 o Attribute(String)
Constructor for a numeric attribute.
 o Attribute(String, FastVector)
Constructor for nominal attributes and string attributes.
 o Attribute(String, FastVector, ProtectedProperties)
Constructor for nominal attributes and string attributes, where metadata is supplied.
 o Attribute(String, ProtectedProperties)
Constructor for a numeric attribute, where metadata is supplied.
 o Attribute(String, String)
Constructor for a date attribute.
 o Attribute(String, String, ProtectedProperties)
Constructor for a date attribute, where metadata is supplied.

Method Index

 o addStringValue(Attribute, int)
Adds a string value to the list of valid strings for attributes of type STRING and returns the index of the string.
 o addStringValue(String)
Adds a string value to the list of valid strings for attributes of type STRING and returns the index of the string.
 o copy()
Produces a shallow copy of this attribute.
 o enumerateValues()
Returns an enumeration of all the attribute's values if the attribute is nominal or a string, null otherwise.
 o equals(Object)
Tests if given attribute is equal to this attribute.
 o formatDate(double)
 
 o getLowerNumericBound()
Returns the lower bound of a numeric attribute.
 o getMetadata()
Returns the properties supplied for this attribute.
 o getUpperNumericBound()
Returns the upper bound of a numeric attribute.
 o hasZeropoint()
Returns whether the attribute has a zeropoint and may be added meaningfully.
 o index()
Returns the index of this attribute.
 o indexOfValue(String)
Returns the index of a given attribute value.
 o isAveragable()
Returns whether the attribute can be averaged meaningfully.
 o isDate()
Tests if the attribute is a date type.
 o isInRange(double)
Determines whether a value lies within the bounds of the attribute.
 o isNominal()
Test if the attribute is nominal.
 o isNumeric()
Tests if the attribute is numeric.
 o isRegular()
Returns whether the attribute values are equally spaced.
 o isString()
Tests if the attribute is a string.
 o lowerNumericBoundIsOpen()
Returns whether the lower numeric bound of the attribute is open.
 o main(String[])
Simple main method for testing this class.
 o name()
Returns the attribute's name.
 o numValues()
Returns the number of attribute values.
 o ordering()
Returns the ordering of the attribute.
 o parseDate(String)
 
 o toString()
Returns a description of this attribute in ARFF format.
 o type()
Returns the attribute's type as an integer.
 o upperNumericBoundIsOpen()
Returns whether the upper numeric bound of the attribute is open.
 o value(int)
Returns a value of a nominal or string attribute.
 o weight()
Returns the attribute's weight.

Field Detail

 o NUMERIC
public static final int NUMERIC
          Constant set for numeric attributes.
 o NOMINAL
public static final int NOMINAL
          Constant set for nominal attributes.
 o STRING
public static final int STRING
          Constant set for attributes with string values.
 o DATE
public static final int DATE
          Constant set for attributes with date values.
 o ORDERING_SYMBOLIC
public static final int ORDERING_SYMBOLIC
          Constant set for symbolic attributes.
 o ORDERING_ORDERED
public static final int ORDERING_ORDERED
          Constant set for ordered attributes.
 o ORDERING_MODULO
public static final int ORDERING_MODULO
          Constant set for modulo-ordered attributes.

Constructor Detail

 o Attribute
public Attribute(java.lang.String attributeName)
          Constructor for a numeric attribute.
Parameters:
attributeName - the name for the attribute
 o Attribute
public Attribute(java.lang.String attributeName,
                 ProtectedProperties metadata)
          Constructor for a numeric attribute, where metadata is supplied.
Parameters:
attributeName - the name for the attribute
metadata - the attribute's properties
 o Attribute
public Attribute(java.lang.String attributeName,
                 java.lang.String dateFormat)
          Constructor for a date attribute.
Parameters:
attributeName - the name for the attribute
dateFormat - a string suitable for use with SimpleDateFormatter for parsing dates.
 o Attribute
public Attribute(java.lang.String attributeName,
                 java.lang.String dateFormat,
                 ProtectedProperties metadata)
          Constructor for a date attribute, where metadata is supplied.
Parameters:
attributeName - the name for the attribute
dateFormat - a string suitable for use with SimpleDateFormatter for parsing dates.
metadata - the attribute's properties
 o Attribute
public Attribute(java.lang.String attributeName,
                 FastVector attributeValues)
          Constructor for nominal attributes and string attributes. If a null vector of attribute values is passed to the method, the attribute is assumed to be a string.
Parameters:
attributeName - the name for the attribute
attributeValues - a vector of strings denoting the attribute values. Null if the attribute is a string attribute.
 o Attribute
public Attribute(java.lang.String attributeName,
                 FastVector attributeValues,
                 ProtectedProperties metadata)
          Constructor for nominal attributes and string attributes, where metadata is supplied. If a null vector of attribute values is passed to the method, the attribute is assumed to be a string.
Parameters:
attributeName - the name for the attribute
attributeValues - a vector of strings denoting the attribute values. Null if the attribute is a string attribute.
metadata - the attribute's properties

Method Detail

 o copy
public java.lang.Object copy()
          Produces a shallow copy of this attribute.
Returns:
a copy of this attribute with the same index
 o enumerateValues
public final java.util.Enumeration enumerateValues()
          Returns an enumeration of all the attribute's values if the attribute is nominal or a string, null otherwise.
Returns:
enumeration of all the attribute's values
 o equals
public final boolean equals(java.lang.Object other)
          Tests if given attribute is equal to this attribute.
Parameters:
other - the Object to be compared to this attribute
Returns:
true if the given attribute is equal to this attribute
Overrides:
equals in class java.lang.Object
 o index
public final int index()
          Returns the index of this attribute.
Returns:
the index of this attribute
 o indexOfValue
public final int indexOfValue(java.lang.String value)
          Returns the index of a given attribute value. (The index of the first occurence of this value.)
Parameters:
value - the value for which the index is to be returned
Returns:
the index of the given attribute value if attribute is nominal or a string, -1 if it is numeric or the value can't be found
 o isNominal
public final boolean isNominal()
          Test if the attribute is nominal.
Returns:
true if the attribute is nominal
 o isNumeric
public final boolean isNumeric()
          Tests if the attribute is numeric.
Returns:
true if the attribute is numeric
 o isString
public final boolean isString()
          Tests if the attribute is a string.
Returns:
true if the attribute is a string
 o isDate
public final boolean isDate()
          Tests if the attribute is a date type.
Returns:
true if the attribute is a date type
 o name
public final java.lang.String name()
          Returns the attribute's name.
Returns:
the attribute's name as a string
 o numValues
public final int numValues()
          Returns the number of attribute values. Returns 0 for numeric attributes.
Returns:
the number of attribute values
 o toString
public final java.lang.String toString()
          Returns a description of this attribute in ARFF format. Quotes strings if they contain whitespace characters, or if they are a question mark.
Returns:
a description of this attribute as a string
Overrides:
toString in class java.lang.Object
 o type
public final int type()
          Returns the attribute's type as an integer.
Returns:
the attribute's type.
 o value
public final java.lang.String value(int valIndex)
          Returns a value of a nominal or string attribute. Returns an empty string if the attribute is neither nominal nor a string attribute.
Parameters:
valIndex - the value's index
Returns:
the attribute's value as a string
 o addStringValue
public 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.
Parameters:
value - The string value to add
Returns:
the index assigned to the string, or -1 if the attribute is not of type Attribute.STRING
 o addStringValue
public 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. This method is more efficient than addStringValue(String) for long strings.
Parameters:
src - The Attribute containing the string value to add.
int - index the index of the string value in the source attribute.
Returns:
the index assigned to the string, or -1 if the attribute is not of type Attribute.STRING
 o formatDate
public java.lang.String formatDate(double date)
 o parseDate
public double parseDate(java.lang.String string) throws java.text.ParseException
 o getMetadata
public final ProtectedProperties getMetadata()
          Returns the properties supplied for this attribute.
Returns:
metadata for this attribute
 o ordering
public final int ordering()
          Returns the ordering of the attribute. One of the following: ORDERING_SYMBOLIC - attribute values should be treated as symbols. ORDERING_ORDERED - attribute values have a global ordering. ORDERING_MODULO - attribute values have an ordering which wraps.
Returns:
the ordering type of the attribute
 o isRegular
public final boolean isRegular()
          Returns whether the attribute values are equally spaced.
Returns:
whether the attribute is regular or not
 o isAveragable
public final boolean isAveragable()
          Returns whether the attribute can be averaged meaningfully.
Returns:
whether the attribute can be averaged or not
 o hasZeropoint
public final boolean hasZeropoint()
          Returns whether the attribute has a zeropoint and may be added meaningfully.
Returns:
whether the attribute has a zeropoint or not
 o weight
public final double weight()
          Returns the attribute's weight.
Returns:
the attribute's weight as a double
 o getLowerNumericBound
public final double getLowerNumericBound()
          Returns the lower bound of a numeric attribute.
Returns:
the lower bound of the specified numeric range
 o lowerNumericBoundIsOpen
public final boolean lowerNumericBoundIsOpen()
          Returns whether the lower numeric bound of the attribute is open.
Returns:
whether the lower numeric bound is open or not (closed)
 o getUpperNumericBound
public final double getUpperNumericBound()
          Returns the upper bound of a numeric attribute.
Returns:
the upper bound of the specified numeric range
 o upperNumericBoundIsOpen
public final boolean upperNumericBoundIsOpen()
          Returns whether the upper numeric bound of the attribute is open.
Returns:
whether the upper numeric bound is open or not (closed)
 o isInRange
public final boolean isInRange(double value)
          Determines whether a value lies within the bounds of the attribute.
Returns:
whether the value is in range
 o main
public static void main(java.lang.String ops[])
          Simple main method for testing this class.

All Packages  Class Hierarchy  This Package  Previous  Next  Index  WEKA's home