/// <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 format has been set. /// </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 (instance.isMissing(m_AttIndex.Index)) { if (!get_MatchMissingValues()) { push((Instance) instance.copy()); return true; } else { return false; } } if (Numeric) { if (!m_Values.Invert) { if (instance.value_Renamed(m_AttIndex.Index) < m_Value) { push((Instance) instance.copy()); return true; } } else { if (instance.value_Renamed(m_AttIndex.Index) >= m_Value) { push((Instance) instance.copy()); return true; } } } if (Nominal) { if (m_Values.isInRange((int) instance.value_Renamed(m_AttIndex.Index))) { Instance temp = (Instance) instance.copy(); if (get_ModifyHeader()) { temp.setValue(m_AttIndex.Index, m_NominalMapping[(int) instance.value_Renamed(m_AttIndex.Index)]); } push(temp); return true; } } return false; }
/// <summary> Takes string values referenced by an Instance and copies them from a /// source dataset to a destination dataset. The instance references are /// updated to be valid for the destination dataset. The instance may have the /// structure (i.e. number and attribute position) of either dataset (this /// affects where references are obtained from). Only works if the number /// of string attributes is the same in both indices (implicitly these string /// attributes should be semantically same but just with shifted positions). /// /// </summary> /// <param name="instance">the instance containing references to strings in the source /// dataset that will have references updated to be valid for the destination /// dataset. /// </param> /// <param name="instSrcCompat">true if the instance structure is the same as the /// source, or false if it is the same as the destination (i.e. which of the /// string attribute indices contains the correct locations for this instance). /// </param> /// <param name="srcDataset">the dataset for which the current instance string /// references are valid (after any position mapping if needed) /// </param> /// <param name="srcStrAtts">an array containing the indices of string attributes /// in the source datset. /// </param> /// <param name="destDataset">the dataset for which the current instance string /// references need to be inserted (after any position mapping if needed) /// </param> /// <param name="destStrAtts">an array containing the indices of string attributes /// in the destination datset. /// </param> protected internal virtual void copyStringValues(Instance instance, bool instSrcCompat, Instances srcDataset, int[] srcStrAtts, Instances destDataset, int[] destStrAtts) { if (srcDataset == destDataset) { return ; } if (srcStrAtts.Length != destStrAtts.Length) { throw new System.ArgumentException("Src and Dest string indices differ in length!!"); } for (int i = 0; i < srcStrAtts.Length; i++) { int instIndex = instSrcCompat?srcStrAtts[i]:destStrAtts[i]; Attribute src = srcDataset.attribute(srcStrAtts[i]); Attribute dest = destDataset.attribute(destStrAtts[i]); if (!instance.isMissing(instIndex)) { //System.err.println(instance.value(srcIndex) // + " " + src.numValues() // + " " + dest.numValues()); //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" int valIndex = dest.addStringValue(src, (int) instance.value_Renamed(instIndex)); // setValue here shouldn't be too slow here unless your dataset has // squillions of string attributes instance.setValue(instIndex, (double) valIndex); } } }