shared
Class NominalAttrInfo

java.lang.Object
  |
  +--shared.AttrInfo
        |
        +--shared.NominalAttrInfo

public class NominalAttrInfo
extends AttrInfo

The NominalAttrInfo class allows giving the different values that the attribute may obtain.


Fields inherited from class shared.AttrInfo
attrName, attrType, boundedReal, internalDisjunction, linearNominal, nominal, real, treeStructured, unknown, UNKNOWN_VAL_STR, userInternalDisjunction, userLinearNominal, userNominal, userReal, userTreeStructured
 
Constructor Summary
NominalAttrInfo(java.lang.String aName, int sizeHint)
          Constructor.
NominalAttrInfo(java.lang.String aName, java.util.LinkedList attrVals)
          Constructor.
 
Method Summary
 java.lang.String attrValue_to_string(AttrValue val)
          Converts the given AttrValue to the corresponding String representation of the nominal attribute value.
 boolean can_cast_to_nominal()
          Checks if this AttrInfo subclass can be cast to a NominalAttrInfo class.
 NominalAttrInfo cast_to_nominal()
          Casts this AttrInfo subclass to a NominalAttrInfo class.
 void check_in_range(AttrValue val)
          Checks if the specified value is within the range for this attribute.
 java.lang.Object clone()
          Cloning function for this NominalAttrInfo class.
 void display_attr_values()
          Displays the attribute values in names file format.
 void display_attr_values(java.io.Writer stream, boolean protectChars)
          Displays the attribute values in names file format.
 boolean equal_value(AttrValue val1, AttrValue val2)
          Returns TRUE if given AttrValues are equivalent.
 void fix_values(boolean shouldFix)
          Fixes the values for this attribute so new values will be added automatically.
 int get_nominal_val(AttrValue av)
          Returns the nominal value stored in the specified AttrValue.
 java.lang.String get_value(int i)
          Returns the ith attribute value stored in this NominalAttrInfo's possible value set.
 boolean is_fixed()
          Checks if this attribute's possible value set is fixed.
 boolean is_unknown(AttrValue nominalValue)
          Returns TRUE if given AttrValue is unknown.
 int num_values()
          Returns number of possible values that the attribute has.
 AttrValue read_attr_value(java.io.BufferedReader stream, boolean isTest, FileSchema f)
          Reads in an attribute value from the specified BufferedReader.
 AttrValue read_attr_value(java.io.StreamTokenizer stream, boolean isTest, FileSchema f)
          Reads in an attribute value from the specified StreamTokenizer.
 void set_nominal_string(AttrValue av, java.lang.String str, boolean suppress)
          Sets the representation of the given AttrValue using a String as input.
 void set_nominal_val(AttrValue av, int val)
          Sets the integer representation of the given AttrValue.
 void set_unknown(AttrValue val)
          Sets the given AttrValue specified to be unknown.
 
Methods inherited from class shared.AttrInfo
attr_type_to_string, can_cast_to_real, cast_to_real, display_attr_values, equal_shallow, get_ignore, get_real_val, is_linear, name, protect_chars, set_ignore, set_real_val, type
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NominalAttrInfo

public NominalAttrInfo(java.lang.String aName,
                       java.util.LinkedList attrVals)
Constructor.
Parameters:
aName - The name for this attribute.
attrVals - The possible values for this attribute.

NominalAttrInfo

public NominalAttrInfo(java.lang.String aName,
                       int sizeHint)
Constructor.
Parameters:
aName - The name of this attribute.
sizeHint - Currently ignored.
Method Detail

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Cloning function for this NominalAttrInfo class.
Overrides:
clone in class AttrInfo
Returns:
The clone of this object.
Throws:
java.lang.CloneNotSupportedException - if the cloning process for NominalAttrInfo data members encounters an Exception.

fix_values

public void fix_values(boolean shouldFix)
Fixes the values for this attribute so new values will be added automatically. Alternately call with FALSE to unfix the values for this attribute.
Parameters:
shouldFix - TRUE if the values should be fixed, FALSE if the values should be unfixed.

display_attr_values

public void display_attr_values()
Displays the attribute values in names file format.
Overrides:
display_attr_values in class AttrInfo

check_in_range

public void check_in_range(AttrValue val)
Checks if the specified value is within the range for this attribute. Causes fatal_error if the given value is not a valid nominal value for this NominalAttrInfo. Otherwise does nothing for NominalAttrInfo. Assumes that value stored in the specified AttrValue is an integer, since this NominalAttrInfo uses integers to represent values.
Overrides:
check_in_range in class AttrInfo
Parameters:
val - The value to be checked.

attrValue_to_string

public java.lang.String attrValue_to_string(AttrValue val)
Converts the given AttrValue to the corresponding String representation of the nominal attribute value. "?" will be returned for UNKNOWN_NOMINAL_VAL. Assumes that value stored in val is an integer, since this NominalAttrInfo class uses integers to represent nominal values.
Overrides:
attrValue_to_string in class AttrInfo
Parameters:
val - The value to convert to a string.
Returns:
The String representation of the given value.

get_nominal_val

public int get_nominal_val(AttrValue av)
Returns the nominal value stored in the specified AttrValue. Returns a fatal error message if the value is not a nominal value.
Overrides:
get_nominal_val in class AttrInfo
Parameters:
av - The AttrValue containing the value required.
Returns:
The value stored in the AttrValue specified.

set_unknown

public void set_unknown(AttrValue val)
Sets the given AttrValue specified to be unknown.
Overrides:
set_unknown in class AttrInfo
Parameters:
val - The value to be set to unknown.

is_unknown

public boolean is_unknown(AttrValue nominalValue)
Returns TRUE if given AttrValue is unknown. Assumes that given AttrValue is of the type described by the instance of NominalAttrInfo calling this function.
Overrides:
is_unknown in class AttrInfo
Parameters:
nominalValue - The AttrValue being checked for unknown value.
Returns:
TRUE if the value is unknown, FALSE otherwise.

set_nominal_string

public void set_nominal_string(AttrValue av,
                               java.lang.String str,
                               boolean suppress)
Sets the representation of the given AttrValue using a String as input. If the attribute does not have a fised value set(fixedValueSet = TRUE), new values may be added.
Overrides:
set_nominal_string in class AttrInfo
Parameters:
av - The AttrValue where the new value will be stored.
str - The String representing the new value.
suppress - If the suppress parameter is TRUE, any unrecognized values will become unknowns if fixedValueSet is set FALSE.

set_nominal_val

public void set_nominal_val(AttrValue av,
                            int val)
Sets the integer representation of the given AttrValue.
Overrides:
set_nominal_val in class AttrInfo
Parameters:
av - The AttrValue storing the new value.
val - The new value to be stored.

is_fixed

public boolean is_fixed()
Checks if this attribute's possible value set is fixed.
Returns:
TRUE if the value set is fixed, FALSE otherwise.

num_values

public int num_values()
Returns number of possible values that the attribute has.
Returns:
The number of possible values.

get_value

public java.lang.String get_value(int i)
Returns the ith attribute value stored in this NominalAttrInfo's possible value set.
Parameters:
i - The index value of the value queried.
Returns:
A String value representing the value stored in the specified position of the possible values set.

can_cast_to_nominal

public boolean can_cast_to_nominal()
Checks if this AttrInfo subclass can be cast to a NominalAttrInfo class.
Overrides:
can_cast_to_nominal in class AttrInfo
Returns:
Always returns TRUE for the NominalAttrInfo class.

cast_to_nominal

public NominalAttrInfo cast_to_nominal()
Casts this AttrInfo subclass to a NominalAttrInfo class.
Overrides:
cast_to_nominal in class AttrInfo
Returns:
A reference to this NominalAttrInfo object.

read_attr_value

public AttrValue read_attr_value(java.io.BufferedReader stream,
                                 boolean isTest,
                                 FileSchema f)
Reads in an attribute value from the specified BufferedReader. Attribute value to be read assumed to match AttrInfo. Although this function may potentially modify this NominalAttrInfo because it may add a new nominal value if fixedValueSet is FALSE. If the ignore flag is set, we read specially so that real values can be properly ignored. Then we always set an unknown value.
Overrides:
read_attr_value in class AttrInfo
Parameters:
stream - The BufferedReader containing the file to be read.
isTest - TRUE if this value is for a test Instance, FALSE otherwise.
f - The FileSchema for the file being read from.
Returns:
The attribute value read.

read_attr_value

public AttrValue read_attr_value(java.io.StreamTokenizer stream,
                                 boolean isTest,
                                 FileSchema f)
Reads in an attribute value from the specified StreamTokenizer. Attribute value to be read assumed to match AttrInfo. Although this function may potentially modify this NominalAttrInfo because it may add a new nominal value if fixedValueSet is FALSE. If the ignore flag is set, we read specially so that real values can be properly ignored. Then we always set an unknown value.
Parameters:
stream - The StreamTokenizer containing the file to be read.
isTest - TRUE if this value is for a test Instance, FALSE otherwise.
f - The FileSchema for the file being read from.
Returns:
The attribute value read.

equal_value

public boolean equal_value(AttrValue val1,
                           AttrValue val2)
Returns TRUE if given AttrValues are equivalent. Assumes that given AttrValues are both of the type described by the NominalAttrInfo object calling this function.
Overrides:
equal_value in class AttrInfo
Parameters:
val1 - An AttrValue to be compared.
val2 - An AttrValue to be compared.
Returns:
TRUE if the AttrValues are equal, FALSE otherwise.

display_attr_values

public void display_attr_values(java.io.Writer stream,
                                boolean protectChars)
Displays the attribute values in names file format. ProtectChars forces quoting of special characters (now only periods).
Overrides:
display_attr_values in class AttrInfo
Parameters:
stream - Writer to which the display will be written.
protectChars - True if "\" and "." are to be protected by "\" characters, false otherwise.