public abstract class Filter extends java.lang.Object implements java.io.Serializable, CapabilitiesHandler, RevisionHandler, OptionHandler, CapabilitiesIgnorer, CommandlineRunnable
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.
|
java.lang.String |
debugTipText()
Returns the tip text for this property
|
java.lang.String |
doNotCheckCapabilitiesTipText()
Returns the tip text for this property
|
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 |
getCopyOfInputFormat()
Gets a copy of just the structure of the input format instances.
|
boolean |
getDebug()
Get whether debugging is turned on.
|
boolean |
getDoNotCheckCapabilities()
Get whether capabilities checking is turned off.
|
java.lang.String[] |
getOptions()
Gets the current settings of the filter.
|
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
|
java.util.Enumeration<Option> |
listOptions()
Returns an enumeration describing the available options.
|
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.
|
boolean |
mayRemoveInstanceAfterFirstBatchDone()
Default implementation returns false.
|
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.
|
void |
postExecution()
Perform any teardown stuff that might need to happen after execution.
|
void |
preExecution()
Perform any setup stuff that might need to happen before commandline
execution.
|
void |
run(java.lang.Object toRun,
java.lang.String[] options)
Execute the supplied object.
|
static void |
runFilter(Filter filter,
java.lang.String[] options)
runs the filter instance with the given options.
|
void |
setDebug(boolean debug)
Set debugging mode.
|
void |
setDoNotCheckCapabilities(boolean doNotCheckCapabilities)
Set whether not to check capabilities.
|
boolean |
setInputFormat(Instances instanceInfo)
Sets the format of the input instances.
|
void |
setOptions(java.lang.String[] options)
Parses a given list of options.
|
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
|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
makeCopy
public boolean isNewBatch()
m_NewBatch
,
batchFinished()
public boolean isFirstBatchDone()
m_FirstBatchDone
,
batchFinished()
public boolean mayRemoveInstanceAfterFirstBatchDone()
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 Instances getCopyOfInputFormat()
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 runFilter(Filter filter, java.lang.String[] options)
filter
- the filter to runoptions
- the commandline optionspublic java.util.Enumeration<Option> listOptions()
listOptions
in interface OptionHandler
public void setOptions(java.lang.String[] options) throws java.lang.Exception
-D
If set, filter is run in debug mode and may output additional info to the
console.
-do-not-check-capabilities
If set, filter capabilities are not checked before filter is built (use
with caution).
setOptions
in interface OptionHandler
options
- the list of options as an array of stringsjava.lang.Exception
- if an option is not supportedpublic java.lang.String[] getOptions()
getOptions
in interface OptionHandler
public void setDebug(boolean debug)
debug
- true if debug output should be printedpublic boolean getDebug()
public java.lang.String debugTipText()
public void setDoNotCheckCapabilities(boolean doNotCheckCapabilities)
setDoNotCheckCapabilities
in interface CapabilitiesIgnorer
doNotCheckCapabilities
- true if capabilities are not to be checked.public boolean getDoNotCheckCapabilities()
getDoNotCheckCapabilities
in interface CapabilitiesIgnorer
public java.lang.String doNotCheckCapabilitiesTipText()
public void preExecution() throws java.lang.Exception
preExecution
in interface CommandlineRunnable
java.lang.Exception
- if a problem occurs during setuppublic void run(java.lang.Object toRun, java.lang.String[] options) throws java.lang.Exception
run
in interface CommandlineRunnable
toRun
- the object to executeoptions
- any options to pass to the objectjava.lang.Exception
- if the object is not of the expected type.public void postExecution() throws java.lang.Exception
postExecution
in interface CommandlineRunnable
java.lang.Exception
- if a problem occurs during teardownpublic static void main(java.lang.String[] args)
args
- should contain arguments to the filter: use -h for help