/** Creates a specialized AddID */ public Filter getFilter(int pos) { AddID af = new AddID(); af.setIDIndex("" + (pos + 1)); return af; }
/** * 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 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()) { bufferInput(instance); return false; } else { convertInstance(instance); return true; } }
/** * Signify 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"); } if (!isFirstBatchDone()) { m_Counter = 0; // Convert pending input instances for (int i = 0; i < getInputFormat().numInstances(); i++) { convertInstance(getInputFormat().instance(i)); } } // Free memory flushInput(); m_NewBatch = true; m_FirstBatchDone = true; return (numPendingOutput() != 0); }
/** * Gets the current settings of the filter. * * @return an array of strings suitable for passing to setOptions */ @Override public String[] getOptions() { Vector<String> result = new Vector<String>(); result.add("-C"); result.add(getIDIndex()); result.add("-N"); result.add(getAttributeName()); return result.toArray(new String[result.size()]); }
/** * Updates ranges based on the given instance, once it has been filtered. * * @see weka.core.neighboursearch.NearestNeighbourSearch#update(weka.core.Instance) */ @Override public void update(Instance ins) throws Exception { getFilter().input(ins); m_AddID.input(getFilter().output()); m_ModifiedSearchMethod.update(m_AddID.output()); }
/** * Convert a single instance over. The converted instance is added to the end * of the output queue. * * @param instance the instance to convert */ protected void convertInstance(Instance instance) { Instance inst; m_Counter++; // build instance try { inst = (Instance) instance.copy(); // First copy string values from input to output copyValues(inst, true, inst.dataset(), outputFormatPeek()); // Insert the new attribute and reassign to output inst.setDataset(null); inst.insertAttributeAt(m_Index.getIndex()); inst.setValue(m_Index.getIndex(), m_Counter); push(inst); // No need to copy instance } catch (Exception e) { e.printStackTrace(); } }
m_AddID.setIDIndex("" + (filteredData.numAttributes() + 1)); m_AddID.setInputFormat(filteredData); filteredData = Filter.useFilter(filteredData, m_AddID);
/** Creates a default AddID */ public Filter getFilter() { return new AddID(); }
/** * Sets the format of the input instances. * * @param instanceInfo an Instances object containing the input instance * structure (any instances contained in the object are ignored - * only the structure is required). * @return true if the outputFormat may be collected immediately * @throws Exception if the format couldn't be set successfully */ @Override public boolean setInputFormat(Instances instanceInfo) throws Exception { Instances outputFormat; Attribute newAttribute; super.setInputFormat(instanceInfo); m_Counter = -1; m_Index.setUpper(instanceInfo.numAttributes()); outputFormat = new Instances(instanceInfo, 0); newAttribute = new Attribute(m_Name); if ((m_Index.getIndex() < 0) || (m_Index.getIndex() > getInputFormat().numAttributes())) { throw new IllegalArgumentException("Index out of range"); } outputFormat.insertAttributeAt(newAttribute, m_Index.getIndex()); setOutputFormat(outputFormat); return true; }
if (getInputFormat() != null) { setInputFormat(getInputFormat());
/** * Updates ranges based on the given instance, once it has been filtered. * * @see weka.core.neighboursearch.NearestNeighbourSearch#update(weka.core.Instance) */ @Override public void update(Instance ins) throws Exception { getFilter().input(ins); m_AddID.input(getFilter().output()); m_ModifiedSearchMethod.update(m_AddID.output()); }
/** * Convert a single instance over. The converted instance is added to the end * of the output queue. * * @param instance the instance to convert */ protected void convertInstance(Instance instance) { Instance inst; m_Counter++; // build instance try { inst = (Instance) instance.copy(); // First copy string values from input to output copyValues(inst, true, inst.dataset(), outputFormatPeek()); // Insert the new attribute and reassign to output inst.setDataset(null); inst.insertAttributeAt(m_Index.getIndex()); inst.setValue(m_Index.getIndex(), m_Counter); push(inst); // No need to copy instance } catch (Exception e) { e.printStackTrace(); } }
m_AddID.setIDIndex("" + (filteredData.numAttributes() + 1)); m_AddID.setInputFormat(filteredData); filteredData = Filter.useFilter(filteredData, m_AddID);
/** Creates a default AddID */ public Filter getFilter() { return new AddID(); }
/** * Gets the current settings of the filter. * * @return an array of strings suitable for passing to setOptions */ @Override public String[] getOptions() { Vector<String> result = new Vector<String>(); result.add("-C"); result.add(getIDIndex()); result.add("-N"); result.add(getAttributeName()); return result.toArray(new String[result.size()]); }
/** * Sets the format of the input instances. * * @param instanceInfo an Instances object containing the input instance * structure (any instances contained in the object are ignored - * only the structure is required). * @return true if the outputFormat may be collected immediately * @throws Exception if the format couldn't be set successfully */ @Override public boolean setInputFormat(Instances instanceInfo) throws Exception { Instances outputFormat; Attribute newAttribute; super.setInputFormat(instanceInfo); m_Counter = -1; m_Index.setUpper(instanceInfo.numAttributes()); outputFormat = new Instances(instanceInfo, 0); newAttribute = new Attribute(m_Name); if ((m_Index.getIndex() < 0) || (m_Index.getIndex() > getInputFormat().numAttributes())) { throw new IllegalArgumentException("Index out of range"); } outputFormat.insertAttributeAt(newAttribute, m_Index.getIndex()); setOutputFormat(outputFormat); return true; }
if (getInputFormat() != null) { setInputFormat(getInputFormat());
/** * 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 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()) { bufferInput(instance); return false; } else { convertInstance(instance); return true; } }