|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectweka.filters.Filter
public abstract class 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,
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,
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. |
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(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. |
static void |
runFilter(Filter filter,
String[] options)
runs the filter instance with the given options. |
boolean |
setInputFormat(Instances instanceInfo)
Sets the format of the input instances. |
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 String |
wekaStaticWrapper(Sourcable filter,
String className,
Instances input,
Instances output)
generates source code from the filter |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Filter()
Method Detail |
---|
public boolean isNewBatch()
m_NewBatch
,
batchFinished()
public boolean isFirstBatchDone()
m_FirstBatchDone
,
batchFinished()
public boolean mayRemoveInstanceAfterFirstBatchDone()
public Capabilities getCapabilities()
getCapabilities
in interface CapabilitiesHandler
Capabilities
public String getRevision()
getRevision
in interface RevisionHandler
public Capabilities getCapabilities(Instances data)
data
- the data to use for customization
getCapabilities()
public boolean setInputFormat(Instances instanceInfo) throws 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).
Exception
- if the inputFormat can't be set successfullypublic Instances getOutputFormat()
NullPointerException
- if no input structure has been
defined (or the output format hasn't been determined yet)public boolean input(Instance instance) throws Exception
instance
- the input instance
NullPointerException
- if the input format has not been
defined.
Exception
- if the input instance was not of the correct
format or if there was a problem with the filtering.public boolean batchFinished() throws Exception
NullPointerException
- if no input structure has been defined,
Exception
- if there was a problem finishing the batch.public Instance output()
NullPointerException
- if no output structure has been definedpublic Instance outputPeek()
NullPointerException
- if no input structure has been definedpublic int numPendingOutput()
NullPointerException
- if no input structure has been definedpublic boolean isOutputFormatDefined()
public static Filter makeCopy(Filter model) throws Exception
model
- the filter to copy
Exception
- if an error occurspublic static Filter[] makeCopies(Filter model, int num) throws Exception
model
- the filter to copynum
- the number of filter copies to create.
Exception
- if an error occurspublic static Instances useFilter(Instances data, Filter filter) throws Exception
data
- the data to be filteredfilter
- the filter to be used
Exception
- if the filter can't be used successfullypublic String toString()
toString
in class Object
public static String wekaStaticWrapper(Sourcable filter, String className, Instances input, Instances output) throws 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 for
Exception
- if source code cannot be generatedpublic static void filterFile(Filter filter, String[] options) throws Exception
filter
- the filter to useoptions
- should contain the following arguments: Exception
- if something goes wrong or the user requests help on
command optionspublic static void batchFilterFile(Filter filter, String[] options) throws Exception
filter
- the filter to useoptions
- should contain the following arguments: Exception
- if something goes wrong or the user requests help on
command optionspublic static void runFilter(Filter filter, String[] options)
filter
- the filter to runoptions
- the commandline optionspublic static void main(String[] args)
args
- should contain arguments to the filter: use -h for help
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |