public abstract class SimpleStreamFilter extends SimpleFilter implements StreamableFilter
true
.SomeFilter
on a
dataset that is loaded from filename
.
import weka.core.*; import weka.filters.*; import java.io.*; ... SomeFilter filter = new SomeFilter(); // set necessary options for the filter Instances data = new Instances( new BufferedReader( new FileReader(filename))); Instances filteredData = Filter.useFilter(data, filter);Implementation:
public static void main(String[] args) { runFilter(new <Filtername>(), args); }Example implementation:
import weka.core.*; import weka.core.Capabilities.*; import weka.filters.*; import java.util.Random; public class SimpleStream extends SimpleStreamFilter { public String globalInfo() { return "A simple stream filter that adds an attribute 'bla' at the end containing a random number."; } public Capabilities getCapabilities() { Capabilities result = super.getCapabilities(); result.enableAllAttributes(); result.enableAllClasses(); result.enable(Capability.NO_CLASS); // filter doesn't need class to be set return result; } protected Instances determineOutputFormat(Instances inputFormat) { Instances result = new Instances(inputFormat, 0); result.insertAttributeAt(new Attribute("bla"), result.numAttributes()); return result; } protected Instance process(Instance inst) { double[] values = new double[inst.numAttributes() + 1]; for (int n = 0; n < inst.numAttributes(); n++) values[n] = inst.value(n); values[values.length - 1] = new Random().nextInt(); Instance result = new DenseInstance(1, values); return result; } public static void main(String[] args) { runFilter(new SimpleStream(), args); } }Options:
SimpleBatchFilter
,
input(Instance)
,
batchFinished()
,
Filter.m_FirstBatchDone
,
Serialized FormConstructor and Description |
---|
SimpleStreamFilter() |
Modifier and Type | Method and Description |
---|---|
boolean |
batchFinished()
Signify that this batch of input to the filter is finished.
|
boolean |
input(Instance instance)
Input an instance for filtering.
|
globalInfo, setInputFormat
batchFilterFile, debugTipText, doNotCheckCapabilitiesTipText, filterFile, getCapabilities, getCapabilities, getCopyOfInputFormat, getDebug, getDoNotCheckCapabilities, getOptions, getOutputFormat, getRevision, isFirstBatchDone, isNewBatch, isOutputFormatDefined, listOptions, main, makeCopies, makeCopy, mayRemoveInstanceAfterFirstBatchDone, numPendingOutput, output, outputPeek, postExecution, preExecution, run, runFilter, setDebug, setDoNotCheckCapabilities, setOptions, toString, useFilter, wekaStaticWrapper
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
makeCopy
public boolean input(Instance instance) throws java.lang.Exception
public boolean batchFinished() throws java.lang.Exception
batchFinished
in class Filter
java.lang.IllegalStateException
- if no input format has been set.java.lang.NullPointerException
- if no input structure has been defined,java.lang.Exception
- if there was a problem finishing the batch.