/** Creates a RemoveFrequentValues, with "-N 3" and "-C 4" */ public Filter getFilter() { RemoveFrequentValues f = new RemoveFrequentValues(); f.setAttributeIndex(Integer.toString(indexNominal + 1)); f.setNumValues(3); return f; }
/** * 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>(); options.add("-C"); options.add("" + (getAttributeIndex())); options.add("-N"); options.add("" + (getNumValues())); if (getUseLeastValues()) { options.add("-H"); } if (getModifyHeader()) { options.add("-H"); } if (getInvertSelection()) { options.add("-V"); } return options.toArray(new String[0]); }
/** * Input an instance for filtering. Ordinarily the instance is processed and * made available for output immediately. Some filters require all 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 format has been set. */ @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 RemoveFrequentValues(), argv); } }
/** * Signifies that this batch of input to the filter is finished. If the filter * requires all instances prior to filtering, 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"); } // process input if (m_Values == null) { determineValues(getInputFormat()); setOutputFormat(); } flushInput(); m_NewBatch = true; m_FirstBatchDone = true; return (numPendingOutput() != 0); }
String attIndex = Utils.getOption('C', options); if (attIndex.length() != 0) { setAttributeIndex(attIndex); } else { setAttributeIndex("last"); setNumValues(Integer.parseInt(numValues)); } else { setNumValues(2); setUseLeastValues(Utils.getFlag('L', options)); setModifyHeader(Utils.getFlag('H', options)); setInvertSelection(Utils.getFlag('V', options)); if (getInputFormat() != null) { setInputFormat(getInputFormat());
((RemoveFrequentValues) m_Filter).setAttributeIndex(Integer.toString(indexNominal)); m_Filter = getFilter(); try { ((RemoveFrequentValues) m_Filter).setModifyHeader(true); m_Filter.setInputFormat(icopy); result = useFilter(); assertEquals( "Returns " + ((RemoveFrequentValues) m_Filter).getNumValues() + " out of the " + m_Instances.attribute(indexNominal).numValues() + " labels", ((RemoveFrequentValues) m_Filter).getNumValues(), result.attribute(indexNominal).numValues() ); } catch (Exception ex) { m_Filter = getFilter(); try { ((RemoveFrequentValues) m_Filter).setModifyHeader(true); ((RemoveFrequentValues) m_Filter).setUseLeastValues(true); m_Filter.setInputFormat(icopy); result = useFilter(); assertEquals( "Returns " + ((RemoveFrequentValues) m_Filter).getNumValues() + " out of the " + m_Instances.attribute(indexNominal).numValues() + " labels", ((RemoveFrequentValues) m_Filter).getNumValues(), result.attribute(indexNominal).numValues() ); } catch (Exception ex) { m_Filter = getFilter(); try { ((RemoveFrequentValues) m_Filter).setModifyHeader(true); ((RemoveFrequentValues) m_Filter).setUseLeastValues(true);
/** test numeric attribute */ public void testNumeric() { Instances icopy = new Instances(m_Instances); try { ((RemoveFrequentValues) m_Filter).setAttributeIndex(Integer.toString(indexNumeric + 1)); m_Filter.setInputFormat(icopy); fail("Should have thrown an exception selecting on a NUMERIC attribute!"); } catch (Exception ex) { // OK } }
String attIndex = Utils.getOption('C', options); if (attIndex.length() != 0) { setAttributeIndex(attIndex); } else { setAttributeIndex("last"); setNumValues(Integer.parseInt(numValues)); } else { setNumValues(2); setUseLeastValues(Utils.getFlag('L', options)); setModifyHeader(Utils.getFlag('H', options)); setInvertSelection(Utils.getFlag('V', options)); if (getInputFormat() != null) { setInputFormat(getInputFormat());
((RemoveFrequentValues) m_Filter).setAttributeIndex(Integer.toString(indexNominal)); m_Filter = getFilter(); try { ((RemoveFrequentValues) m_Filter).setModifyHeader(true); m_Filter.setInputFormat(icopy); result = useFilter(); assertEquals( "Returns " + ((RemoveFrequentValues) m_Filter).getNumValues() + " out of the " + m_Instances.attribute(indexNominal).numValues() + " labels", ((RemoveFrequentValues) m_Filter).getNumValues(), result.attribute(indexNominal).numValues() ); } catch (Exception ex) { m_Filter = getFilter(); try { ((RemoveFrequentValues) m_Filter).setModifyHeader(true); ((RemoveFrequentValues) m_Filter).setUseLeastValues(true); m_Filter.setInputFormat(icopy); result = useFilter(); assertEquals( "Returns " + ((RemoveFrequentValues) m_Filter).getNumValues() + " out of the " + m_Instances.attribute(indexNominal).numValues() + " labels", ((RemoveFrequentValues) m_Filter).getNumValues(), result.attribute(indexNominal).numValues() ); } catch (Exception ex) { m_Filter = getFilter(); try { ((RemoveFrequentValues) m_Filter).setModifyHeader(true); ((RemoveFrequentValues) m_Filter).setUseLeastValues(true);
/** * Signifies that this batch of input to the filter is finished. If the filter * requires all instances prior to filtering, 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"); } // process input if (m_Values == null) { determineValues(getInputFormat()); setOutputFormat(); } flushInput(); m_NewBatch = true; m_FirstBatchDone = true; return (numPendingOutput() != 0); }
/** test string attribute */ public void testString() { Instances icopy = new Instances(m_Instances); try { ((RemoveFrequentValues) m_Filter).setAttributeIndex(Integer.toString(indexString + 1)); m_Filter.setInputFormat(icopy); fail("Should have thrown an exception selecting on a STRING attribute!"); } catch (Exception ex) { // OK } }
/** * 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 RemoveFrequentValues(), argv); } }
/** Creates a RemoveFrequentValues, with "-N 3" and "-C 4" */ public Filter getFilter() { RemoveFrequentValues f = new RemoveFrequentValues(); f.setAttributeIndex(Integer.toString(indexNominal + 1)); f.setNumValues(3); return f; }
/** * 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>(); options.add("-C"); options.add("" + (getAttributeIndex())); options.add("-N"); options.add("" + (getNumValues())); if (getUseLeastValues()) { options.add("-H"); } if (getModifyHeader()) { options.add("-H"); } if (getInvertSelection()) { options.add("-V"); } return options.toArray(new String[0]); }
/** * Input an instance for filtering. Ordinarily the instance is processed and * made available for output immediately. Some filters require all 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 format has been set. */ @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; } }
/** test string attribute */ public void testString() { Instances icopy = new Instances(m_Instances); try { ((RemoveFrequentValues) m_Filter).setAttributeIndex(Integer.toString(indexString + 1)); m_Filter.setInputFormat(icopy); fail("Should have thrown an exception selecting on a STRING attribute!"); } catch (Exception ex) { // OK } }
/** test numeric attribute */ public void testNumeric() { Instances icopy = new Instances(m_Instances); try { ((RemoveFrequentValues) m_Filter).setAttributeIndex(Integer.toString(indexNumeric + 1)); m_Filter.setInputFormat(icopy); fail("Should have thrown an exception selecting on a NUMERIC attribute!"); } catch (Exception ex) { // OK } }
/** * tests the filter in conjunction with the FilteredClassifier */ public void testFilteredClassifier() { try { Instances data = getFilteredClassifierData(); for (int i = 0; i < data.numAttributes(); i++) { if (data.classIndex() == i) continue; if (data.attribute(i).isNominal()) { ((RemoveFrequentValues) m_FilteredClassifier.getFilter()).setAttributeIndex( "" + (i + 1)); break; } } } catch (Exception e) { fail("Problem setting up test for FilteredClassifier: " + e.toString()); } super.testFilteredClassifier(); }
/** * tests the filter in conjunction with the FilteredClassifier */ public void testFilteredClassifier() { try { Instances data = getFilteredClassifierData(); for (int i = 0; i < data.numAttributes(); i++) { if (data.classIndex() == i) continue; if (data.attribute(i).isNominal()) { ((RemoveFrequentValues) m_FilteredClassifier.getFilter()).setAttributeIndex( "" + (i + 1)); break; } } } catch (Exception e) { fail("Problem setting up test for FilteredClassifier: " + e.toString()); } super.testFilteredClassifier(); }