cosc575.p1
Class DiscreteAttribute

java.lang.Object
  extended by cosc575.p1.Attribute
      extended by cosc575.p1.DiscreteAttribute

public class DiscreteAttribute
extends Attribute

Stores the attribute information for data sets for machine learning. An attribute has a name, type, and domain. Types can be discrete, numeric, or nominal.


Field Summary
private  java.lang.Integer maxValue
          the number of values for discrete attributes
 
Fields inherited from class cosc575.p1.Attribute
name
 
Constructor Summary
DiscreteAttribute()
           
DiscreteAttribute(java.util.Scanner scanner)
          Explicit constructor.
DiscreteAttribute(java.lang.String name)
          Explicit constructor.
 
Method Summary
 void addValue(int value)
          Adds or sets a new discrete domain value to this attribute.
 int getSize()
          Gets the size of this attribute's domain.
static void main(java.lang.String[] args)
           
 boolean parse(java.util.Scanner scanner)
          Processes a single attribute declaration, consisting of the keyword, attribute name, and attribute type.
 java.lang.String toString()
          Returns a string representation of this attribute.
 boolean validValue(java.lang.Integer value)
          Returns whether the value is valid for a discrete attribute
 
Methods inherited from class cosc575.p1.Attribute
getName, setName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

maxValue

private java.lang.Integer maxValue
the number of values for discrete attributes

Constructor Detail

DiscreteAttribute

public DiscreteAttribute()

DiscreteAttribute

public DiscreteAttribute(java.lang.String name)
                  throws java.lang.Exception
Explicit constructor. Creates a discrete attribute of the specified name.

Parameters:
name - the name of this attribute
Throws:
java.lang.Exception

DiscreteAttribute

public DiscreteAttribute(java.util.Scanner scanner)
                  throws java.lang.Exception
Explicit constructor. Creates a data set populated with the tokens in the scanner.

Parameters:
scanner - a Scanner containing the data set's tokens
Throws:
java.lang.Exception - if an exception occurs
Method Detail

addValue

public void addValue(int value)
              throws java.lang.Exception
Adds or sets a new discrete domain value to this attribute.

Parameters:
value - the attribute's new domain value
Throws:
java.lang.Exception - if an exception occurs

getSize

public int getSize()
            throws java.lang.Exception
Gets the size of this attribute's domain.

Overrides:
getSize in class Attribute
Returns:
an int storing the size of the domain
Throws:
java.lang.Exception

parse

public boolean parse(java.util.Scanner scanner)
              throws java.lang.Exception
Processes a single attribute declaration, consisting of the keyword, attribute name, and attribute type.

Parameters:
scanner - a scanner containing the data set's tokens
Returns:
true while there are more attribute to process; false otherwise
Throws:
java.lang.Exception - if an exception occurs

toString

public java.lang.String toString()
Returns a string representation of this attribute.

Overrides:
toString in class Attribute
Returns:
a string representation of the names structure

validValue

public boolean validValue(java.lang.Integer value)
                   throws java.lang.Exception
Returns whether the value is valid for a discrete attribute

Parameters:
value - the value for testing
Returns:
true if the value is valid; false otherwise
Throws:
java.lang.Exception - if an exception occurs

main

public static void main(java.lang.String[] args)