/** * Main method for testing this class. * * @param argv should contain arguments to the filter: use -h for help */ public static void main(String[] argv) { runFilter(new RemoveRange(), argv); } }
/** * Input an instance for filtering. Filter requires all training instances be * read before producing output. * * @param instance the input instance * @return true if the filtered instance may now be collected with output(). * @throws IllegalStateException if no input structure has been defined */ @Override public boolean input(Instance instance) { if (getInputFormat() == null) { throw new IllegalStateException("No input instance format defined"); } if (m_NewBatch) { resetQueue(); m_NewBatch = false; } if (isFirstBatchDone()) { push(instance); return true; } else { bufferInput(instance); return false; } }
/** * Gets the current settings of the filter. * * @return an array of strings suitable for passing to setOptions. */ @Override public String[] getOptions() { Vector<String> options = new Vector<String>(); if (getInvertSelection()) { options.add("-V"); } options.add("-R"); options.add(getInstancesIndices()); return options.toArray(new String[0]); }
String range = Utils.getOption('p',options); System.out.println("Selecting Range "+range+""); RemoveRange remove = new RemoveRange(); remove.setInstancesIndices(range); remove.setInvertSelection(true); remove.setInputFormat(allInstances); allInstances = Filter.useFilter(allInstances, remove); } catch(Exception e) {
setInstancesIndices(str); } else { setInstancesIndices("first-last"); setInvertSelection(Utils.getFlag('V', options)); if (getInputFormat() != null) { setInputFormat(getInputFormat());
public void testSpecifiedRange() { ((RemoveRange)m_Filter).setInstancesIndices("1-10"); ((RemoveRange)m_Filter).setInvertSelection(true); Instances result = useFilter(); assertEquals(m_Instances.numAttributes(), result.numAttributes()); assertEquals(10, result.numInstances()); for (int i = 0; i < 10; i++) { assertEquals(m_Instances.instance(i).toString(), result.instance(i).toString()); } }
/** * Signify that this batch of input to the filter is finished. Output() may * now be called to retrieve the filtered instances. * * @return true if there are instances pending output * @throws IllegalStateException if no input structure has been defined */ @Override public boolean batchFinished() { if (getInputFormat() == null) { throw new IllegalStateException("No input instance format defined"); } if (!isFirstBatchDone()) { // Push instances for output into output queue m_Range.setUpper(getInputFormat().numInstances() - 1); for (int i = 0; i < getInputFormat().numInstances(); i++) { if (!m_Range.isInRange(i)) { push(getInputFormat().instance(i), false); // No need to copy } } } else { for (int i = 0; i < getInputFormat().numInstances(); i++) { push(getInputFormat().instance(i), false); // No need to copy } } flushInput(); m_NewBatch = true; m_FirstBatchDone = true; return (numPendingOutput() != 0); }
/** Creates a default RemoveRange */ public Filter getFilter() { RemoveRange f = new RemoveRange(); return f; }
setInstancesIndices(str); } else { setInstancesIndices("first-last"); setInvertSelection(Utils.getFlag('V', options)); if (getInputFormat() != null) { setInputFormat(getInputFormat());
public void testSpecifiedRange() { ((RemoveRange)m_Filter).setInstancesIndices("1-10"); ((RemoveRange)m_Filter).setInvertSelection(true); Instances result = useFilter(); assertEquals(m_Instances.numAttributes(), result.numAttributes()); assertEquals(10, result.numInstances()); for (int i = 0; i < 10; i++) { assertEquals(m_Instances.instance(i).toString(), result.instance(i).toString()); } }
/** * Signify that this batch of input to the filter is finished. Output() may * now be called to retrieve the filtered instances. * * @return true if there are instances pending output * @throws IllegalStateException if no input structure has been defined */ @Override public boolean batchFinished() { if (getInputFormat() == null) { throw new IllegalStateException("No input instance format defined"); } if (!isFirstBatchDone()) { // Push instances for output into output queue m_Range.setUpper(getInputFormat().numInstances() - 1); for (int i = 0; i < getInputFormat().numInstances(); i++) { if (!m_Range.isInRange(i)) { push(getInputFormat().instance(i), false); // No need to copy } } } else { for (int i = 0; i < getInputFormat().numInstances(); i++) { push(getInputFormat().instance(i), false); // No need to copy } } flushInput(); m_NewBatch = true; m_FirstBatchDone = true; return (numPendingOutput() != 0); }
/** Creates a default RemoveRange */ public Filter getFilter() { RemoveRange f = new RemoveRange(); return f; }
/** * Input an instance for filtering. Filter requires all training instances be * read before producing output. * * @param instance the input instance * @return true if the filtered instance may now be collected with output(). * @throws IllegalStateException if no input structure has been defined */ @Override public boolean input(Instance instance) { if (getInputFormat() == null) { throw new IllegalStateException("No input instance format defined"); } if (m_NewBatch) { resetQueue(); m_NewBatch = false; } if (isFirstBatchDone()) { push(instance); return true; } else { bufferInput(instance); return false; } }
/** * Main method for testing this class. * * @param argv should contain arguments to the filter: use -h for help */ public static void main(String[] argv) { runFilter(new RemoveRange(), argv); } }
/** * Gets the current settings of the filter. * * @return an array of strings suitable for passing to setOptions. */ @Override public String[] getOptions() { Vector<String> options = new Vector<String>(); if (getInvertSelection()) { options.add("-V"); } options.add("-R"); options.add(getInstancesIndices()); return options.toArray(new String[0]); }