| java.lang.Object weka.core.Attribute
Attribute | public class Attribute implements Copyable,Serializable(Code) | | Class for handling an attribute. Once an attribute has been created,
it can't be changed.
The following attribute types are supported:
- numeric:
This type of attribute represents a floating-point number.
- nominal:
This type of attribute represents a fixed set of nominal values.
- string:
This type of attribute represents a dynamically expanding set of
nominal values. Usually used in text classification.
- date:
This type of attribute represents a date, internally represented as
floating-point number storing the milliseconds since January 1,
1970, 00:00:00 GMT. The string representation of the date must be
ISO-8601 compliant, the default is yyyy-MM-dd'T'HH:mm:ss .
- relational:
This type of attribute can contain other attributes and is, e.g.,
used for representing Multi-Instance data. (Multi-Instance data
consists of a nominal attribute containing the bag-id, then a
relational attribute with all the attributes of the bag, and
finally the class attribute.)
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);
...
author: Eibe Frank (eibe@cs.waikato.ac.nz) version: $Revision: 1.44 $ |
Constructor Summary | |
public | Attribute(String attributeName) Constructor for a numeric attribute. | public | Attribute(String attributeName, ProtectedProperties metadata) Constructor for a numeric attribute, where metadata is supplied. | public | Attribute(String attributeName, String dateFormat) Constructor for a date attribute. | public | Attribute(String attributeName, String dateFormat, ProtectedProperties metadata) Constructor for a date attribute, where metadata is supplied. | public | Attribute(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 Parameters: attributeValues - a vector of strings denoting the attribute values. | public | Attribute(String attributeName, FastVector attributeValues, ProtectedProperties metadata) Constructor for nominal attributes and string attributes, where
metadata is supplied. | public | Attribute(String attributeName, Instances header) Constructor for relation-valued attributes. | public | Attribute(String attributeName, Instances header, ProtectedProperties metadata) Constructor for relation-valued attributes. | public | Attribute(String attributeName, int index) Constructor for a numeric attribute with a particular index. | public | Attribute(String attributeName, String dateFormat, int index) Constructor for date attributes with a particular index.
Parameters: attributeName - the name for the attribute Parameters: dateFormat - a string suitable for use withSimpleDateFormatter for parsing dates. | public | Attribute(String attributeName, FastVector attributeValues, int index) Constructor for nominal attributes and string attributes with
a particular index. | public | Attribute(String attributeName, Instances header, int index) Constructor for a relation-valued attribute with a particular index. |
Method Summary | |
public int | addRelation(Instances value) Adds a relation to a relation-valued attribute. | public 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. | 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. | final void | addValue(String value) Adds an attribute value. | public Object | copy() Produces a shallow copy of this attribute. | final public Attribute | copy(String newName) Produces a shallow copy of this attribute with a new name. | final void | delete(int index) Removes a value of a nominal, string, or relation-valued
attribute. | final public Enumeration | enumerateValues() Returns an enumeration of all the attribute's values if the
attribute is nominal, string, or relation-valued, null otherwise. | final public boolean | equals(Object other) Tests if given attribute is equal to this attribute. | final void | forceAddValue(String value) Adds an attribute value. | public String | formatDate(double date) Returns the given amount of milliseconds formatted according to the
current Date format. | final public String | getDateFormat() Returns the Date format pattern in case this attribute is of type DATE,
otherwise an empty string. | final public double | getLowerNumericBound() Returns the lower bound of a numeric attribute. | final public ProtectedProperties | getMetadata() Returns the properties supplied for this attribute. | final public double | getUpperNumericBound() Returns the upper bound of a numeric attribute. | final public boolean | hasZeropoint() Returns whether the attribute has a zeropoint and may be
added meaningfully. | final public int | index() Returns the index of this attribute. | final public int | indexOfValue(String value) Returns the index of a given attribute value. | final public boolean | isAveragable() Returns whether the attribute can be averaged meaningfully. | final public boolean | isDate() Tests if the attribute is a date type. | final public boolean | isInRange(double value) Determines whether a value lies within the bounds of the attribute. | final public boolean | isNominal() Test if the attribute is nominal. | final public boolean | isNumeric() Tests if the attribute is numeric. | final public boolean | isRegular() Returns whether the attribute values are equally spaced. | final public boolean | isRelationValued() Tests if the attribute is relation valued. | final public boolean | isString() Tests if the attribute is a string. | final public boolean | lowerNumericBoundIsOpen() Returns whether the lower numeric bound of the attribute is open. | public static void | main(String[] ops) Simple main method for testing this class. | final public String | name() Returns the attribute's name. | final public int | numValues() Returns the number of attribute values. | final public int | ordering() Returns the ordering of the attribute. | public double | parseDate(String string) Parses the given String as Date, according to the current format and
returns the corresponding amount of milliseconds. | final public Instances | relation() Returns the header info for a relation-valued attribute,
null if the attribute is not relation-valued. | final public Instances | relation(int valIndex) Returns a value of a relation-valued attribute. | final void | setIndex(int index) Sets the index of this attribute. | final void | setValue(int index, String string) Sets a value of a nominal attribute or string attribute. | final void | setValue(int index, Instances data) Sets a value of a relation-valued attribute. | public void | setWeight(double value) | final public String | toString() Returns a description of this attribute in ARFF format. | final public int | type() Returns the attribute's type as an integer. | final public boolean | upperNumericBoundIsOpen() Returns whether the upper numeric bound of the attribute is open. | final public String | value(int valIndex) Returns a value of a nominal or string attribute. | final public double | weight() Returns the attribute's weight. |
ARFF_ATTRIBUTE | final public static String ARFF_ATTRIBUTE(Code) | | The keyword used to denote the start of an arff attribute declaration
|
ARFF_ATTRIBUTE_DATE | final public static String ARFF_ATTRIBUTE_DATE(Code) | | The keyword used to denote a date attribute
|
ARFF_ATTRIBUTE_INTEGER | final public static String ARFF_ATTRIBUTE_INTEGER(Code) | | A keyword used to denote a numeric attribute
|
ARFF_ATTRIBUTE_NUMERIC | final public static String ARFF_ATTRIBUTE_NUMERIC(Code) | | A keyword used to denote a numeric attribute
|
ARFF_ATTRIBUTE_REAL | final public static String ARFF_ATTRIBUTE_REAL(Code) | | A keyword used to denote a numeric attribute
|
ARFF_ATTRIBUTE_RELATIONAL | final public static String ARFF_ATTRIBUTE_RELATIONAL(Code) | | The keyword used to denote a relation-valued attribute
|
ARFF_ATTRIBUTE_STRING | final public static String ARFF_ATTRIBUTE_STRING(Code) | | The keyword used to denote a string attribute
|
ARFF_END_SUBRELATION | final public static String ARFF_END_SUBRELATION(Code) | | The keyword used to denote the end of the declaration of a subrelation
|
DATE | final public static int DATE(Code) | | Constant set for attributes with date values.
|
NOMINAL | final public static int NOMINAL(Code) | | Constant set for nominal attributes.
|
NUMERIC | final public static int NUMERIC(Code) | | Constant set for numeric attributes.
|
ORDERING_MODULO | final public static int ORDERING_MODULO(Code) | | Constant set for modulo-ordered attributes.
|
ORDERING_ORDERED | final public static int ORDERING_ORDERED(Code) | | Constant set for ordered attributes.
|
ORDERING_SYMBOLIC | final public static int ORDERING_SYMBOLIC(Code) | | Constant set for symbolic attributes.
|
RELATIONAL | final public static int RELATIONAL(Code) | | Constant set for relation-valued attributes.
|
STRING | final public static int STRING(Code) | | Constant set for attributes with string values.
|
serialVersionUID | final static long serialVersionUID(Code) | | for serialization
|
Attribute | public Attribute(String attributeName)(Code) | | Constructor for a numeric attribute.
Parameters: attributeName - the name for the attribute |
Attribute | public Attribute(String attributeName, ProtectedProperties metadata)(Code) | | Constructor for a numeric attribute, where metadata is supplied.
Parameters: attributeName - the name for the attribute Parameters: metadata - the attribute's properties |
Attribute | public Attribute(String attributeName, String dateFormat)(Code) | | Constructor for a date attribute.
Parameters: attributeName - the name for the attribute Parameters: dateFormat - a string suitable for use withSimpleDateFormatter for parsing dates. |
Attribute | public Attribute(String attributeName, String dateFormat, ProtectedProperties metadata)(Code) | | Constructor for a date attribute, where metadata is supplied.
Parameters: attributeName - the name for the attribute Parameters: dateFormat - a string suitable for use withSimpleDateFormatter for parsing dates. Parameters: metadata - the attribute's properties |
Attribute | public Attribute(String attributeName, FastVector attributeValues)(Code) | | 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 Parameters: attributeValues - a vector of strings denoting the attribute values. Null if the attribute is a string attribute. |
Attribute | public Attribute(String attributeName, FastVector attributeValues, ProtectedProperties metadata)(Code) | | 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 Parameters: attributeValues - a vector of strings denoting the attribute values. Null if the attribute is a string attribute. Parameters: metadata - the attribute's properties |
Attribute | public Attribute(String attributeName, Instances header)(Code) | | Constructor for relation-valued attributes.
Parameters: attributeName - the name for the attribute Parameters: header - an Instances object specifying the header of the relation. |
Attribute | public Attribute(String attributeName, Instances header, ProtectedProperties metadata)(Code) | | Constructor for relation-valued attributes.
Parameters: attributeName - the name for the attribute Parameters: header - an Instances object specifying the header of the relation. Parameters: metadata - the attribute's properties |
Attribute | public Attribute(String attributeName, int index)(Code) | | Constructor for a numeric attribute with a particular index.
Parameters: attributeName - the name for the attribute Parameters: index - the attribute's index |
Attribute | public Attribute(String attributeName, String dateFormat, int index)(Code) | | Constructor for date attributes with a particular index.
Parameters: attributeName - the name for the attribute Parameters: dateFormat - a string suitable for use withSimpleDateFormatter for parsing dates. Null for a default formatstring. Parameters: index - the attribute's index |
Attribute | public Attribute(String attributeName, FastVector attributeValues, int index)(Code) | | Constructor for nominal attributes and string attributes with
a particular index.
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 Parameters: attributeValues - a vector of strings denoting the attribute values.Null if the attribute is a string attribute. Parameters: index - the attribute's index |
Attribute | public Attribute(String attributeName, Instances header, int index)(Code) | | Constructor for a relation-valued attribute with a particular index.
Parameters: attributeName - the name for the attribute Parameters: header - the header information for this attribute Parameters: index - the attribute's index |
addRelation | public int addRelation(Instances value)(Code) | | Adds a relation to a relation-valued attribute.
Parameters: value - The value to add the index assigned to the value, or -1 if the attribute is notof type Attribute.RELATIONAL |
addStringValue | public int addStringValue(String value)(Code) | | 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 the index assigned to the string, or -1 if the attribute is notof type Attribute.STRING |
addStringValue | public int addStringValue(Attribute src, int index)(Code) | | 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. Parameters: index - the index of the string value in the source attribute. the index assigned to the string, or -1 if the attribute is notof type Attribute.STRING |
addValue | final void addValue(String value)(Code) | | Adds an attribute value. Creates a fresh list of attribute
values before adding it.
Parameters: value - the attribute value |
copy | public Object copy()(Code) | | Produces a shallow copy of this attribute.
a copy of this attribute with the same index |
copy | final public Attribute copy(String newName)(Code) | | Produces a shallow copy of this attribute with a new name.
Parameters: newName - the name of the new attribute a copy of this attribute with the same index |
delete | final void delete(int index)(Code) | | Removes a value of a nominal, string, or relation-valued
attribute. Creates a fresh list of attribute values before
removing it.
Parameters: index - the value's index throws: IllegalArgumentException - if the attribute is not of the correct type |
enumerateValues | final public Enumeration enumerateValues()(Code) | | Returns an enumeration of all the attribute's values if the
attribute is nominal, string, or relation-valued, null otherwise.
enumeration of all the attribute's values |
equals | final public boolean equals(Object other)(Code) | | Tests if given attribute is equal to this attribute.
Parameters: other - the Object to be compared to this attribute true if the given attribute is equal to this attribute |
forceAddValue | final void forceAddValue(String value)(Code) | | Adds an attribute value.
Parameters: value - the attribute value |
formatDate | public String formatDate(double date)(Code) | | Returns the given amount of milliseconds formatted according to the
current Date format.
Parameters: date - the date, represented in milliseconds since January 1, 1970, 00:00:00 GMT, to return as string the formatted date |
getDateFormat | final public String getDateFormat()(Code) | | Returns the Date format pattern in case this attribute is of type DATE,
otherwise an empty string.
the date format pattern See Also: SimpleDateFormat |
getLowerNumericBound | final public double getLowerNumericBound()(Code) | | Returns the lower bound of a numeric attribute.
the lower bound of the specified numeric range |
getMetadata | final public ProtectedProperties getMetadata()(Code) | | Returns the properties supplied for this attribute.
metadata for this attribute |
getUpperNumericBound | final public double getUpperNumericBound()(Code) | | Returns the upper bound of a numeric attribute.
the upper bound of the specified numeric range |
hasZeropoint | final public boolean hasZeropoint()(Code) | | Returns whether the attribute has a zeropoint and may be
added meaningfully.
whether the attribute has a zeropoint or not |
index | final public int index()(Code) | | Returns the index of this attribute.
the index of this attribute |
indexOfValue | final public int indexOfValue(String value)(Code) | | 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 the index of the given attribute value if attributeis nominal or a string, -1 if it is not or the value can't be found |
isAveragable | final public boolean isAveragable()(Code) | | Returns whether the attribute can be averaged meaningfully.
whether the attribute can be averaged or not |
isDate | final public boolean isDate()(Code) | | Tests if the attribute is a date type.
true if the attribute is a date type |
isInRange | final public boolean isInRange(double value)(Code) | | Determines whether a value lies within the bounds of the attribute.
Parameters: value - the value to check whether the value is in range |
isNominal | final public boolean isNominal()(Code) | | Test if the attribute is nominal.
true if the attribute is nominal |
isNumeric | final public boolean isNumeric()(Code) | | Tests if the attribute is numeric.
true if the attribute is numeric |
isRegular | final public boolean isRegular()(Code) | | Returns whether the attribute values are equally spaced.
whether the attribute is regular or not |
isRelationValued | final public boolean isRelationValued()(Code) | | Tests if the attribute is relation valued.
true if the attribute is relation valued |
isString | final public boolean isString()(Code) | | Tests if the attribute is a string.
true if the attribute is a string |
lowerNumericBoundIsOpen | final public boolean lowerNumericBoundIsOpen()(Code) | | Returns whether the lower numeric bound of the attribute is open.
whether the lower numeric bound is open or not (closed) |
main | public static void main(String[] ops)(Code) | | Simple main method for testing this class.
Parameters: ops - the commandline options |
name | final public String name()(Code) | | Returns the attribute's name.
the attribute's name as a string |
numValues | final public int numValues()(Code) | | Returns the number of attribute values. Returns 0 for
attributes that are not either nominal, string, or
relation-valued.
the number of attribute values |
ordering | final public int ordering()(Code) | | 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.
the ordering type of the attribute |
parseDate | public double parseDate(String string) throws ParseException(Code) | | Parses the given String as Date, according to the current format and
returns the corresponding amount of milliseconds.
Parameters: string - the date to parse the date in milliseconds since January 1, 1970, 00:00:00 GMT throws: ParseException - if parsing fails |
relation | final public Instances relation()(Code) | | Returns the header info for a relation-valued attribute,
null if the attribute is not relation-valued.
the attribute's value as an Instances object |
relation | final public Instances relation(int valIndex)(Code) | | Returns a value of a relation-valued attribute. Returns
null if the attribute is not relation-valued.
Parameters: valIndex - the value's index the attribute's value as an Instances object |
setIndex | final void setIndex(int index)(Code) | | Sets the index of this attribute.
Parameters: index - the index of this attribute |
setValue | final void setValue(int index, String string)(Code) | | Sets a value of a nominal attribute or string attribute.
Creates a fresh list of attribute values before it is set.
Parameters: index - the value's index Parameters: string - the value throws: IllegalArgumentException - if the attribute is not nominal or string. |
setValue | final void setValue(int index, Instances data)(Code) | | Sets a value of a relation-valued attribute.
Creates a fresh list of attribute values before it is set.
Parameters: index - the value's index Parameters: data - the value throws: IllegalArgumentException - if the attribute is not relation-valued. |
setWeight | public void setWeight(double value)(Code) | | Sets the new attribute's weight
Parameters: value - the new weight |
toString | final public String toString()(Code) | | Returns a description of this attribute in ARFF format. Quotes
strings if they contain whitespace characters, or if they
are a question mark.
a description of this attribute as a string |
type | final public int type()(Code) | | Returns the attribute's type as an integer.
the attribute's type. |
upperNumericBoundIsOpen | final public boolean upperNumericBoundIsOpen()(Code) | | Returns whether the upper numeric bound of the attribute is open.
whether the upper numeric bound is open or not (closed) |
value | final public String value(int valIndex)(Code) | | Returns a value of a nominal or string attribute. Returns an
empty string if the attribute is neither a string nor a nominal
attribute.
Parameters: valIndex - the value's index the attribute's value as a string |
weight | final public double weight()(Code) | | Returns the attribute's weight.
the attribute's weight as a double |
|
|