⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 miningtransformationfactory.java

📁 一个数据挖掘软件ALPHAMINERR的整个过程的JAVA版源代码
💻 JAVA
字号:
/*
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

 /**
  * Title: XELOPES Data Mining Library
  * Description: The XELOPES library is an open platform-independent and data-source-independent library for Embedded Data Mining.
  * Copyright: Copyright (c) 2002 Prudential Systems Software GmbH
  * Company: ZSoft (www.zsoft.ru), Prudsys (www.prudsys.com)
  * @author Michael Thess
  * @version 1.0
  */
package com.prudsys.pdm.Transform;

import java.util.Vector;

/**
 * Creates mining transformation objects, especially MiningTransformationStep,
 * in an easy way.
 *
 * The following correspondends of terms to CWM transformation holds:
 * classifier map (CWM)         <-> multiple-to-multiple map (XELOPES)
 * classifier feature map (CWM) <-> one-to-multiple map (XELOPES)
 * feature map (CWM)            <-> one-to-one map (XELOPES)
 */
public class MiningTransformationFactory extends com.prudsys.pdm.Cwm.Core.Class
{
  // -----------------------------------------------------------------------
  //  Variables declarations
  // -----------------------------------------------------------------------
  /** Multiple-to-multiple transformations. */
  private Vector multipleToMultiple = new Vector();

  /** One-to-multiple transformations. */
  private Vector oneToMultiple = new Vector();

  /** One-to-one transformations. */
  private Vector oneToOne = new Vector();

  /** Type of last transformation added. */
  private int lastObType = -1;

  // -----------------------------------------------------------------------
  //  Constructor
  // -----------------------------------------------------------------------
  /**
   * Empty constructor.
   */
  public MiningTransformationFactory()
  {

  }

  // -----------------------------------------------------------------------
  //  Add mappings to factory
  // -----------------------------------------------------------------------
  /**
   * Resets all data.
   */
  public void reset() {

    multipleToMultiple.removeAllElements();
    oneToMultiple.removeAllElements();
    oneToOne.removeAllElements();
    lastObType = -1;
  }

  /**
   * Add classifier map (probably with feature and classifierFeature maps).
   *
   * @param mcmp new classifier map (i.e. multiple-to-multiple map) to add
   */
  public void addMultipleToMultipleMapping(MultipleToMultipleMapping mcmp) {

    if (lastObType > -1) {
      // Get last classifier map:
      MultipleToMultipleMapping mcm = (MultipleToMultipleMapping) multipleToMultiple.elementAt( multipleToMultiple.size()-1 );

      // Add all feature maps:
      OneToOneMapping[] featureMap = new OneToOneMapping[ oneToOne.size() ];
      for (int i = 0; i < oneToOne.size(); i++)
        featureMap[i] = (OneToOneMapping) oneToOne.elementAt(i);
      mcm.setOneToOneMapping( featureMap );
      oneToOne.removeAllElements();

      // Add all classifier feature maps:
      OneToMultipleMapping[] cfMap = new OneToMultipleMapping[ oneToMultiple.size() ];
      for (int i = 0; i < oneToMultiple.size(); i++)
        cfMap[i] = (OneToMultipleMapping) oneToMultiple.elementAt(i);
      mcm.setOneToMultipleMapping( cfMap );
      oneToMultiple.removeAllElements();
    }

    multipleToMultiple.addElement( mcmp );

    lastObType = 2;
  }

  /**
   * Add classifier feature map.
   *
   * @param mcfm new classifier feature map (i.e. one-to-multiple map) to add
   */
  public void addOneToMultipleMapping(OneToMultipleMapping mcfm) {

    if (lastObType == -1)
      multipleToMultiple.addElement( new MultipleToMultipleMapping() );

    if (lastObType == 2)
      multipleToMultiple.addElement( new MultipleToMultipleMapping() );

    oneToMultiple.addElement(mcfm);

    lastObType = 1;
  }

  /**
   * Add feature map.
   *
   * @param mfm new feature map (i.e. one-to-one map) to add
   */
  public void addOneToOneMapping(OneToOneMapping mfm) {

    if (lastObType == -1)
      multipleToMultiple.addElement( new MultipleToMultipleMapping() );

    if (lastObType == 1) {
      // Get last classifier map:
      MultipleToMultipleMapping mcm = (MultipleToMultipleMapping) multipleToMultiple.elementAt( multipleToMultiple.size()-1 );

      // Add all classifier feature maps:
      OneToMultipleMapping[] cfMap = new OneToMultipleMapping[ oneToMultiple.size() ];
      for (int i = 0; i < oneToMultiple.size(); i++)
        cfMap[i] = (OneToMultipleMapping) oneToMultiple.elementAt(i);
      mcm.setOneToMultipleMapping( cfMap );
      oneToMultiple.removeAllElements();

      multipleToMultiple.addElement( new MultipleToMultipleMapping() );
    }

    oneToOne.addElement( mfm );

    lastObType = 0;
  }

  // -----------------------------------------------------------------------
  //  Create mining transformation step
  // -----------------------------------------------------------------------
  /**
   * Creates mining transformation step.
   *
   * @return mining transformation step from the given data
   */
  public MiningTransformationStep createMiningTransformationStep() {

    // Get last classifier map:
    MultipleToMultipleMapping mcm = (MultipleToMultipleMapping) multipleToMultiple.elementAt( multipleToMultiple.size()-1 );

    // Add all feature maps:
    OneToOneMapping[] ownFeatureMap = (OneToOneMapping[]) mcm.getOneToOneMapping();
    if (ownFeatureMap == null)
      ownFeatureMap = new OneToOneMapping[0];
    OneToOneMapping[] featureMap = new OneToOneMapping[ oneToOne.size() + ownFeatureMap.length ];
    for (int i = 0; i < oneToOne.size(); i++)
      featureMap[i] = (OneToOneMapping) oneToOne.elementAt(i);
    for (int i = 0; i < ownFeatureMap.length; i++)
      featureMap[oneToOne.size() + i] = ownFeatureMap[i];
    mcm.setOneToOneMapping( featureMap );

    // Add all classifier feature maps:
    OneToMultipleMapping[] ownCfMap = (OneToMultipleMapping[]) mcm.getOneToMultipleMapping();
    if (ownCfMap == null)
      ownCfMap = new OneToMultipleMapping[0];
    OneToMultipleMapping[] cfMap = new OneToMultipleMapping[ oneToMultiple.size() + ownCfMap.length ];
    for (int i = 0; i < oneToMultiple.size(); i++)
      cfMap[i] = (OneToMultipleMapping) oneToMultiple.elementAt(i);
    for (int i = 0; i < ownCfMap.length; i++)
      cfMap[oneToMultiple.size() + i] = ownCfMap[i];
    mcm.setOneToMultipleMapping( cfMap );

    // Create transformation step:
    MultipleToMultipleMapping[] mcma = new MultipleToMultipleMapping[ multipleToMultiple.size() ];
    for (int i = 0; i < multipleToMultiple.size(); i++)
      mcma[i] = (MultipleToMultipleMapping) multipleToMultiple.elementAt(i);

    MiningTransformationMap[] mtm = new MiningTransformationMap[1];
    mtm[0] = new MiningTransformationMap();
    mtm[0].setMiningClassifierMap(mcma);

    MiningTransformationTask mtt = new MiningTransformationTask();
    mtt.setMiningTransformation(mtm);

    MiningTransformationStep mts = new MiningTransformationStep();
    mts.setTransformationTask(mtt);

    return mts;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -