cosc575.p1
Class NominalAttribute

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

public class NominalAttribute
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
(package private)  java.util.ArrayList<java.lang.String> domain
          a list of strings for the domain of nominal attributes
(package private)  boolean sorted
          a Boolean indicating whether the nominal domain is sorted
 
Fields inherited from class cosc575.p1.Attribute
name
 
Constructor Summary
NominalAttribute()
           
NominalAttribute(java.util.Scanner scanner)
          Explicit constructor.
NominalAttribute(java.lang.String name)
          Explicit constructor.
 
Method Summary
 void addValue(java.lang.String value)
          Adds a new nominal domain value to this attribute.
 java.util.ArrayList<java.lang.String> getDomain()
          Returns the attribute's domain, which an array of values for nominal attributes.
 int getIndex(java.lang.String value)
          Returns the index of the specified value index for the attribute.
 int getSize()
          Gets the size of this attribute's domain.
 java.lang.String getValue(int index)
          Returns the value of this attribute at the specified index.
static void main(java.lang.String[] args)
           
private  boolean parse(java.util.Scanner scanner)
          Processes a nominal attibute declaration.
 java.lang.String toString()
          Returns a string representation of this attribute.
 boolean validValue(java.lang.String value)
          Returns whether the value is valid for a nominal 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

domain

java.util.ArrayList<java.lang.String> domain
a list of strings for the domain of nominal attributes


sorted

boolean sorted
a Boolean indicating whether the nominal domain is sorted

Constructor Detail

NominalAttribute

public NominalAttribute()

NominalAttribute

public NominalAttribute(java.lang.String name)
                 throws java.lang.Exception
Explicit constructor. Creates an empty data set of the specified name.

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

NominalAttribute

public NominalAttribute(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(java.lang.String value)
              throws java.lang.Exception
Adds a new nominal 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

getDomain

public java.util.ArrayList<java.lang.String> getDomain()
Returns the attribute's domain, which an array of values for nominal attributes.

Returns:
the attribute's domain

getValue

public java.lang.String getValue(int index)
                          throws java.lang.Exception
Returns the value of this attribute at the specified index.

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

getIndex

public int getIndex(java.lang.String value)
             throws java.lang.Exception
Returns the index of the specified value index for the attribute.

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

parse

private boolean parse(java.util.Scanner scanner)
               throws java.lang.Exception
Processes a nominal attibute declaration.

Parameters:
scanner - a scanner containing the data set's tokens
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 this attribute

validValue

public boolean validValue(java.lang.String value)
                   throws java.lang.Exception
Returns whether the value is valid for a nominal 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)