public abstract class Filter extends java.lang.Object implements java.io.Serializable, CapabilitiesHandler, RevisionHandler
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 and Description |
---|
Filter() |
Modifier and Type | Method and Description |
---|---|
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.
|
Capabilities |
getCapabilities()
Returns the Capabilities of this filter.
|
Capabilities |
getCapabilities(Instances data)
Returns the Capabilities of this filter, customized based on the data.
|
Instances |
getOutputFormat()
Gets the format of the output instances.
|
java.lang.String |
getRevision()
Returns the revision string.
|
boolean |
input(Instance instance)
Input an instance for filtering.
|
boolean |
isFirstBatchDone()
Returns true if the first batch of instances got processed.
|
boolean |
isNewBatch()
Returns true if the a new batch was started, either a new instance of the
filter was created or the batchFinished() method got called.
|
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.
|
static Filter[] |
makeCopies(Filter model,
int num)
Creates a given number of deep copies of the given filter using
serialization.
|
static Filter |
makeCopy(Filter model)
Creates a deep copy of the given filter using serialization.
|
int |
numPendingOutput()
Returns the number of instances pending output
|
Instance |
output()
Output an instance after filtering and remove from the output queue.
|
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.
|
java.lang.String |
toString()
Returns a description of the filter, by default only the classname.
|
static Instances |
useFilter(Instances data,
Filter filter)
Filters an entire set of instances through a filter and returns
the new set.
|
static java.lang.String |
wekaStaticWrapper(Sourcable filter,
java.lang.String className,
Instances input,
Instances output)
generates source code from the filter
|
public boolean isNewBatch()
m_NewBatch
,
batchFinished()
public boolean isFirstBatchDone()
m_FirstBatchDone
,
batchFinished()
public Capabilities getCapabilities()
getCapabilities
in interface CapabilitiesHandler
Capabilities
public java.lang.String getRevision()
getRevision
in interface RevisionHandler
public Capabilities getCapabilities(Instances data)
data
- the data to use for customizationgetCapabilities()
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 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 instancejava.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 Filter makeCopy(Filter model) throws java.lang.Exception
model
- the filter to copyjava.lang.Exception
- if an error occurspublic static Filter[] makeCopies(Filter model, int num) throws java.lang.Exception
model
- the filter to copynum
- the number of filter copies to create.java.lang.Exception
- if an error occurspublic static Instances useFilter(Instances data, Filter filter) throws java.lang.Exception
data
- the data to be filteredfilter
- the filter to be usedjava.lang.Exception
- if the filter can't be used successfullypublic java.lang.String toString()
toString
in class java.lang.Object
public static java.lang.String wekaStaticWrapper(Sourcable filter, java.lang.String className, Instances input, Instances output) throws java.lang.Exception
filter
- the filter to output as sourceclassName
- the name of the generated classinput
- the input data the header is generated foroutput
- the output data the header is generated forjava.lang.Exception
- if source code cannot be generatedpublic static void filterFile(Filter filter, java.lang.String[] options) throws java.lang.Exception
filter
- the filter to useoptions
- should contain the following arguments: 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
filter
- the filter to useoptions
- should contain the following arguments: java.lang.Exception
- if something goes wrong or the user requests help on
command optionspublic static void main(java.lang.String[] args)
args
- should contain arguments to the filter: use -h for help