/// <summary> Copies string values contained in the instance copied to a new /// dataset. The Instance must already be assigned to a dataset. This /// dataset and the destination dataset must have the same structure. /// /// </summary> /// <param name="instance">the Instance containing the string values to copy. /// </param> /// <param name="destDataset">the destination set of Instances /// </param> /// <param name="strAtts">an array containing the indices of any string attributes /// in the dataset. /// </param> private void copyStringValues(Instance inst, Instances destDataset, int[] strAtts) { if (strAtts.Length == 0) { return ; } if (inst.dataset() == null) { throw new System.ArgumentException("Instance has no dataset assigned!!"); } else if (inst.dataset().numAttributes() != destDataset.numAttributes()) { throw new System.ArgumentException("Src and Dest differ in # of attributes!!"); } copyStringValues(inst, true, inst.dataset(), strAtts, destDataset, strAtts); }
/// <summary> 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. /// /// </summary> /// <param name="instance">the input instance /// </param> /// <returns> true if the filtered instance may now be /// collected with output(). /// </returns> /// <exception cref="IllegalStateException">if no input structure has been defined. /// </exception> public override bool input(Instance instance) { if (getInputFormat() == null) { throw new System.SystemException("No input instance format defined"); } if (m_NewBatch) { resetQueue(); m_NewBatch = false; } if (getOutputFormat().numAttributes() == 0) { return false; } double[] vals = new double[getOutputFormat().numAttributes()]; for (int i = 0; i < m_SelectedAttributes.Length; i++) { int current = m_SelectedAttributes[i]; vals[i] = instance.value_Renamed(current); } Instance inst = null; if (instance is SparseInstance) { inst = new SparseInstance(instance.weight(), vals); } else { inst = new Instance(instance.weight(), vals); } copyStringValues(inst, false, instance.dataset(), m_InputStringIndex, getOutputFormat(), OutputStringIndex); inst.Dataset = getOutputFormat(); push(inst); return true; }