示例#1
0
  /**
   * This will remove all buffered instances from the inputformat dataset. Use this method rather
   * than getInputFormat().delete();
   */
  protected void flushInput() {

    if ((m_InputStringAtts.getAttributeIndices().length > 0)
        || (m_InputRelAtts.getAttributeIndices().length > 0)) {
      m_InputFormat = m_InputFormat.stringFreeStructure();
      m_InputStringAtts = new StringLocator(m_InputFormat, m_InputStringAtts.getAllowedIndices());
      m_InputRelAtts = new RelationalLocator(m_InputFormat, m_InputRelAtts.getAllowedIndices());
    } else {
      // This more efficient than new Instances(m_InputFormat, 0);
      m_InputFormat.delete();
    }
  }
示例#2
0
  /**
   * 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.
   * Any subsequent instances filtered should be filtered based on setting obtained from the first
   * batch (unless the inputFormat has been re-assigned or new options have been set). This default
   * implementation assumes all instance processing occurs during inputFormat() and input().
   *
   * @return true if there are instances pending output
   * @throws NullPointerException if no input structure has been defined,
   * @throws Exception if there was a problem finishing the batch.
   */
  public boolean batchFinished() throws Exception {

    if (m_InputFormat == null) {
      throw new NullPointerException("No input instance format defined");
    }
    flushInput();
    m_NewBatch = true;
    m_FirstBatchDone = true;

    if (m_OutputQueue.empty()) {
      // Clear out references to old strings/relationals occasionally
      if ((m_OutputStringAtts.getAttributeIndices().length > 0)
          || (m_OutputRelAtts.getAttributeIndices().length > 0)) {
        m_OutputFormat = m_OutputFormat.stringFreeStructure();
        m_OutputStringAtts =
            new StringLocator(m_OutputFormat, m_OutputStringAtts.getAllowedIndices());
      }
    }

    return (numPendingOutput() != 0);
  }
示例#3
0
  /**
   * Copies string/relational 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.
   *
   * @param instance the Instance containing the string/relational values to copy.
   * @param isInput if true the input format and input attribute locators are used otherwise the
   *     output format and output locators
   */
  protected void copyValues(Instance instance, boolean isInput) {

    RelationalLocator.copyRelationalValues(
        instance,
        (isInput) ? m_InputFormat : m_OutputFormat,
        (isInput) ? m_InputRelAtts : m_OutputRelAtts);

    StringLocator.copyStringValues(
        instance,
        (isInput) ? m_InputFormat : m_OutputFormat,
        (isInput) ? m_InputStringAtts : m_OutputStringAtts);
  }
示例#4
0
  /**
   * Takes string/relational 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/relational attributes is the same in both indices (implicitly these string/relational
   * attributes should be semantically same but just with shifted positions).
   *
   * @param instance the instance containing references to strings/ relational values in the source
   *     dataset that will have references updated to be valid for the destination dataset.
   * @param 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/relational attribute indices
   *     contains the correct locations for this instance).
   * @param srcDataset the dataset for which the current instance string/relational value references
   *     are valid (after any position mapping if needed)
   * @param destDataset the dataset for which the current instance string/relational value
   *     references need to be inserted (after any position mapping if needed)
   */
  protected void copyValues(
      Instance instance, boolean instSrcCompat, Instances srcDataset, Instances destDataset) {

    RelationalLocator.copyRelationalValues(
        instance, instSrcCompat,
        srcDataset, m_InputRelAtts,
        destDataset, m_OutputRelAtts);

    StringLocator.copyStringValues(
        instance,
        instSrcCompat,
        srcDataset,
        m_InputStringAtts,
        getOutputFormat(),
        m_OutputStringAtts);
  }