Class ExampleBag
java.lang.Object
|
+----ExampleBag
- public class ExampleBag
- extends Object
-
ExampleBag()
- This constructor creates an empty collection of examples.
-
add(Example)
-
-
bagWithFeature(int, String)
-
-
bagWithoutFeature(int, String)
-
-
chooseFeature()
- This should choose a feature that is useful for predicting a category.
-
getCategories()
-
-
getChosenFeature()
-
- Precondition
-
chooseFeature() has been called.
-
getChosenFeaturePosition()
-
- Precondition
-
chooseFeature() has been called.
-
main(String[])
-
-
numDifferent()
-
-
numWithFeature(int, String)
-
-
numWithoutFeature(int, String)
-
-
read(String)
- This method reads a list of examples from the specified file and
stores the examples in this collection.
-
size()
-
ExampleBag
public ExampleBag()
- This constructor creates an empty collection of examples.
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.
size
public int size()
- Returns:
- the number of examples in the collection
add
public void add(Example ex)
- Parameters:
- the - new example to be added
- Postcondition:
- The given example is added to the
collection.
getCategories
public StringBag getCategories()
- Returns:
- the collection of categories. The same category can be
repeated in the collection.
numDifferent
public int numDifferent()
- Returns:
- the number of different categories.
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
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
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
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
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.
getChosenFeature
public String getChosenFeature()
-
- Precondition
-
chooseFeature() has been called.
- Returns:
- the chosen feature
getChosenFeaturePosition
public int getChosenFeaturePosition()
-
- Precondition
-
chooseFeature() has been called.
- Returns:
- the position in the examples of the chosen feature
main
public static void main(String args[])