Class ExampleBag

java.lang.Object
   |
   +----ExampleBag

public class ExampleBag
extends Object

Constructor Index

 o ExampleBag()
This constructor creates an empty collection of examples.

Method Index

 o add(Example)
 o bagWithFeature(int, String)
 o bagWithoutFeature(int, String)
 o chooseFeature()
This should choose a feature that is useful for predicting a category.
 o getCategories()
 o getChosenFeature()
Precondition
chooseFeature() has been called.
 o getChosenFeaturePosition()
Precondition
chooseFeature() has been called.
 o main(String[])
 o numDifferent()
 o numWithFeature(int, String)
 o numWithoutFeature(int, String)
 o read(String)
This method reads a list of examples from the specified file and stores the examples in this collection.
 o size()

Constructors

 o ExampleBag
 public ExampleBag()
This constructor creates an empty collection of examples.

Methods

 o read
 public void read(String fileName) throws IOException
This method reads a list of examples from the specified file and stores the examples in this collection.

Parameters:
fileName - the name of the specified file.
Precondition:
The specified file exists consisting of one example per line. Each example is represented as a series of strings separated by at least one space. The first string is the example's category if it is known. If it is not none, the string "?" is used. The remaining strings are the example's features.
Postcondition:
This object contains the examples in the specified file.
Throws: IOException
thrown if file cannot be open for reading.
 o size
 public int size()
Returns:
the number of examples in the collection
 o add
 public void add(Example ex)
Parameters:
the - new example to be added
Postcondition:
The given example is added to the collection.
 o getCategories
 public StringBag getCategories()
Returns:
the collection of categories. The same category can be repeated in the collection.
 o numDifferent
 public int numDifferent()
Returns:
the number of different categories.
 o numWithFeature
 public int numWithFeature(int featureNum,
                           String featureValue)
Parameters:
featureNum - specified position ranges from 0 to size - 1
featureValue - the string value of the feature
Returns:
the number of examples with specified value at specified position
 o numWithoutFeature
 public int numWithoutFeature(int featureNum,
                              String featureValue)
Parameters:
featureNum - specified position ranges from 0 to size - 1
featureValue - the string value of the feature
Returns:
the number of examples without specified value at specified position
 o bagWithFeature
 public ExampleBag bagWithFeature(int featureNum,
                                  String featureValue)
Parameters:
featureNum - specified position ranges from 0 to size - 1
featureValue - the string value of the feature
Returns:
a collection of examples with specified value at specified position
 o bagWithoutFeature
 public ExampleBag bagWithoutFeature(int featureNum,
                                     String featureValue)
Parameters:
featureNum - specified position ranges from 0 to size - 1
featureValue - the string value of the feature
Returns:
a collection of examples without specified value at specified position
 o chooseFeature
 public void chooseFeature()
This should choose a feature that is useful for predicting a category. However, for now, it simply chooses a feature at random, which may not be useful at all.
Postcondition:
Feature is selected and getChosenFeature() and getChosenFeaturePosition() are defined.

 o getChosenFeature
 public String getChosenFeature()
Precondition
chooseFeature() has been called.

Returns:
the chosen feature
 o getChosenFeaturePosition
 public int getChosenFeaturePosition()
Precondition
chooseFeature() has been called.

Returns:
the position in the examples of the chosen feature
 o main
 public static void main(String args[])