|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--weka.filters.Filter
An abstract class for instance filters: objects that take instances as input, carry out some transformation on the instance and then output the instance. The method implementations in this class assume that most of the work will be done in the methods overridden by subclasses.
A simple example of filter use. This example doesn't remove instances from the output queue until all instances have been input, so has higher memory consumption than an approach that uses output instances as they are made available:
Filter filter = ..some type of filter..
Instances instances = ..some instances..
for (int i = 0; i < data.numInstances(); i++) {
filter.input(data.instance(i));
}
filter.batchFinished();
Instances newData = filter.outputFormat();
Instance processed;
while ((processed = filter.output()) != null) {
newData.add(processed);
}
..do something with newData..
Constructor Summary | |
Filter()
|
Method Summary | |
static void |
batchFilterFile(Filter filter,
java.lang.String[] options)
Method for testing filters ability to process multiple batches. |
boolean |
batchFinished()
Signify that this batch of input to the filter is finished. |
static void |
filterFile(Filter filter,
java.lang.String[] options)
Method for testing filters. |
Instances |
getOutputFormat()
Gets the format of the output instances. |
boolean |
input(Instance instance)
Input an instance for filtering. |
boolean |
inputFormat(Instances instanceInfo)
Deprecated. use setInputFormat(Instances) instead. |
boolean |
isOutputFormatDefined()
Returns whether the output format is ready to be collected |
static void |
main(java.lang.String[] args)
Main method for testing this class. |
int |
numPendingOutput()
Returns the number of instances pending output |
Instance |
output()
Output an instance after filtering and remove from the output queue. |
Instances |
outputFormat()
Deprecated. use getOutputFormat() instead. |
Instance |
outputPeek()
Output an instance after filtering but do not remove from the output queue. |
boolean |
setInputFormat(Instances instanceInfo)
Sets the format of the input instances. |
static Instances |
useFilter(Instances data,
Filter filter)
Filters an entire set of instances through a filter and returns the new set. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Filter()
Method Detail |
public boolean inputFormat(Instances instanceInfo) throws java.lang.Exception
setInputFormat(Instances)
instead.
java.lang.Exception
public boolean setInputFormat(Instances instanceInfo) throws java.lang.Exception
super.setInputFormat(Instances)
instanceInfo
- an Instances object containing the input instance
structure (any instances contained in the object are ignored - only the
structure is required).
java.lang.Exception
- if the inputFormat can't be set successfullypublic Instances outputFormat()
getOutputFormat()
instead.
public Instances getOutputFormat()
java.lang.NullPointerException
- if no input structure has been
defined (or the output format hasn't been determined yet)public boolean input(Instance instance) throws java.lang.Exception
instance
- the input instance
java.lang.NullPointerException
- if the input format has not been
defined.
java.lang.Exception
- if the input instance was not of the correct
format or if there was a problem with the filtering.public boolean batchFinished() throws java.lang.Exception
java.lang.NullPointerException
- if no input structure has been defined,
java.lang.Exception
- if there was a problem finishing the batch.public Instance output()
java.lang.NullPointerException
- if no output structure has been definedpublic Instance outputPeek()
java.lang.NullPointerException
- if no input structure has been definedpublic int numPendingOutput()
java.lang.NullPointerException
- if no input structure has been definedpublic boolean isOutputFormatDefined()
public static Instances useFilter(Instances data, Filter filter) throws java.lang.Exception
data
- the data to be filteredfilter
- the filter to be used
java.lang.Exception
- if the filter can't be used successfullypublic static void filterFile(Filter filter, java.lang.String[] options) throws java.lang.Exception
java.lang.Exception
- if something goes wrong or the user requests help on
command optionspublic static void batchFilterFile(Filter filter, java.lang.String[] options) throws java.lang.Exception
java.lang.Exception
- if something goes wrong or the user requests help on
command optionspublic static void main(java.lang.String[] args)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright (c) 2003 David Lindsay, Computer Learning Research Centre, Dept. Computer Science, Royal Holloway, University of London