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

📄 miningdataspecification.java

📁 一个数据挖掘软件ALPHAMINERR的整个过程的JAVA版源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 *    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 Valentine Stepanenko (valentine.stepanenko@zsoft.ru)
  * @author Michael Thess
  * @version 1.2
  */

package com.prudsys.pdm.Core;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.Reader;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Hashtable;

import com.prudsys.pdm.Adapters.PmmlVersion20.DataDictionary;
import com.prudsys.pdm.Adapters.PmmlVersion20.DataField;
import com.prudsys.pdm.Adapters.PmmlVersion20.Header;
import com.prudsys.pdm.Adapters.PmmlVersion20.PMML;
import com.prudsys.pdm.Adapters.PmmlVersion20.TransformationDictionary;
import com.prudsys.pdm.Input.Records.Arff.MiningArffStream;
import com.prudsys.pdm.Input.Records.Transactions.TransactionStream;
import com.prudsys.pdm.Transform.MiningTransformationActivity;
import com.prudsys.pdm.Utils.PmmlUtils;
import com.prudsys.pdm.Utils.StringUtils;

/**
  * The collection of mining attributes specifying how to interpret the input data
  * attributes. <p>
  *
  * A description of the attributes accepted by the model for scoring data. <p>
  *
  * From CWM Data Mining. <p>
  *
  * Superclasses:
  * <ul>
  *   <li> Class
  * </ul>
  * Contained Elements:
  * <ul>
  *   <li> MiningAttribute
  * </ul>
  * References:
  * <ul>
  *   <li> <i>attribute</i>: References the MiningAttributes. <br>
  *       - class: MiningAttribute <br>
  *       - defined by: HasAttribute::attribute <br>
  *       - multiplicity: one or more
  * </ul>
  * Constraints:
  * <ul>
  *   <li> Attributes must have unique names.
  * </ul>
  *
  * In addition, functionality from PMML was added.
  * It corresponds to the PMML element DataDictionary.
  *
  * Since version 1.1 also the transformation history (if exists)
  * has been added. This is indicated by the attribute transformed.
  * Then the original meta data is contained in the variable
  * pretransformedMetaData. The transformation dictionary that has
  * driven the transformations is contained in the attribute
  * relationsDictionary.
  *
  * Since version 1.2 also contains meta data operations object for
  * meta data comparison operations and basis transformations.
  *
  * @see MiningAttribute
  * @see MiningSettings
  * @see com.prudsys.pdm.Adapters.PmmlVersion20.DataDictionary
  * @see com.prudsys.pdm.Adapters.PmmlVersion20.TransformationDictionary
  */
public class MiningDataSpecification extends com.prudsys.pdm.Cwm.Core.Class
                                     implements MiningMatrixElement, PmmlSerializable, Cloneable
{
    // -----------------------------------------------------------------------
    //  Variables declarations
    // -----------------------------------------------------------------------
    /** Name of the meta data. Now inherited from ModelElement (name). */
//  protected String relationName;

    /** Array list containing all mining attributes of this meta data. */
    protected ArrayList miningAttributes = new ArrayList();

    /** Mapping of attribute names to attributes. */
    protected Hashtable names2attributes = new Hashtable();

    /** Array containing all mining attributes of this meta data. */
    protected MiningAttribute attributesArray[] = null;

    /** Reference to settings containing this meta data object. Not used. */
    protected MiningSettings settings[] = null;

    /** Initial state of this meta data. */
    protected MiningDataSpecification pretransformedMetaData = null;

    /** If there have been transformations applied. */
    protected boolean transformed = false;

    /** Transformation activity describing the transformation starting from pretransformedMetaData. */
    protected MiningTransformationActivity miningTransformationActivity = null;

    /** Name of file containing meta data. */
    protected String fileName;

    //--------------- New for Meta Data Basis Trafos ------------------------
    /** Reference to meta data operations object owned by this meta data. */
    protected MetaDataOperations metaDataOp;

    // -----------------------------------------------------------------------
    //  Constructors
    // -----------------------------------------------------------------------
    /**
     * New mining data specification.
     */
    public MiningDataSpecification()
    {
      this(null);
    }

    /**
     * New mining data specification with given name.
     *
     * @param name name of mining data specification
     */
    public MiningDataSpecification(String name)
    {
      setName(name);
      metaDataOp = new MetaDataOperations(this);
    }

    // -----------------------------------------------------------------------
    //  Getter and setter methods
    // -----------------------------------------------------------------------
    /**
     * Get name of mining data specification. Better to use getName.
     *
     * @return name of mining data specification
     */
    public String getRelationName()
    {
        return getName();
    }

    /**
     * Set name of minig data specification. Better to use setName.
     *
     * @param name name of mining data specification
     */
    public void setRelationName(String name)
    {
        setName(name);
    }

    /**
     * Get mining attribute by name.
     *
     * @param attributeName name of attribute required
     * @return specified mining attribute, null if not found
     */
    public MiningAttribute getMiningAttribute( String attributeName )
    {
        if (attributeName == null) return null;
        return (MiningAttribute) names2attributes.get(attributeName);
    }

    /**
     * Get mining attribute by index of the array of attributes of
     * mining data specification.
     *
     * @param attributeIndex index of attribute required
     * @return specified mining attribute, null if not found
     */
    public MiningAttribute getMiningAttribute( int attributeIndex )
    {
        return (MiningAttribute) miningAttributes.get(attributeIndex);
    }

    /**
     * Adds mining attribute to mining data specification.
     * Attribute is appended to the current list of mining attributes. <p>
     *
     * Note that attribute is added anyway to the list. However, if the
     * name of the new attribute is empty or there already exists an
     * attribute with the same name, it is not added to the name hashtable.
     * This means that it could not be retrieved via its name. It is
     * highly recommended only to use attributes with unique names.
     *
     * @param miningAttribute mining attribute to add
     * @return true attribute also added to name hashtable, false if attribute
     * name is null or there already exists an attribute with the same name
     */
    public boolean addMiningAttribute( MiningAttribute miningAttribute )
    {
        miningAttributes.add( miningAttribute );
        String attname = miningAttribute.getName();
        if ( attname == null || names2attributes.get(attname) != null )
          return false;
        else
          names2attributes.put(attname, miningAttribute);
        return true;
    }

    /**
     * Sets mining attribute at index of the array of attributes of
     * mining data specification.
     *
     * Note that attribute is set anyway to the list. However, if the
     * name of the new attribute is empty or there already exists an
     * attribute with the same name, it is not added to the name hashtable.
     * This means that it could not be retrieved via its name. It is
     * highly recommended only to use attributes with unique names.
     *
     * @param attributeIndex index of new mining attribute
     * @param miningAttribute new mining attribute to set
     * @return true attribute also added to name hashtable, false if attribute
     * name is null or there already exists an attribute with the same name
     */
    public boolean setMiningAttribute( int attributeIndex, MiningAttribute miningAttribute)
    {
        // Remove name from names hashtable:
        String attname = ((MiningAttribute) miningAttributes.get(attributeIndex)).getName();
        if (attname != null && names2attributes.get(attname) != null)
          names2attributes.remove(attname);

        // Set new attribute:
        miningAttributes.set( attributeIndex, miningAttribute );

        // Add new attribute name to hashtable:
        attname = miningAttribute.getName();
        if ( attname == null || names2attributes.get(attname) != null )
          return false;
        else
          names2attributes.put(attname, miningAttribute);
        return true;
    }

    /**
     * Returns number of mining attributes in mining data specification.
     *
     * @return number of mining attributes
     */
    public int getAttributesNumber()
    {
        return miningAttributes.size();
    }

    /**
     * Returns array of all mining attributes of mining data specification.
     *
     * @return array of all mining attributes
     */
    public MiningAttribute[] getAttributesArray()
    {
        int size = miningAttributes.size();
        attributesArray = new MiningAttribute[ size ];
        for (int i = 0; i < size; i++)
        {
            attributesArray[i] = getMiningAttribute( i );
        }
        return attributesArray;
    }

    /**
     * Sets array of all mining attributes of mining data specification.
     *
     * @param attributesArray array of all mining attributes to set
     */
    public void setAttributesArray(MiningAttribute[] attributesArray)
    {
        miningAttributes.clear();
        names2attributes.clear();
        int size = ( attributesArray != null ) ? attributesArray.length : 0;
        for (int i = 0; i < size; i++)
        {
            addMiningAttribute( attributesArray[i] );
        }
        this.attributesArray = attributesArray;
    }

    /**
     * Returns index of given mining attribute.
     *
     * @param miningAttribute given mining attribute
     * @return index of mining attribute, -1 if attribute is not found
     */
    public int getAttributeIndex( MiningAttribute miningAttribute )
    {
        return miningAttributes.indexOf( miningAttribute );
    }

    /**
     * Get original mining data specification (before transformation was applied).
     *
     * @return original meta data
     */
    public MiningDataSpecification getPretransformedMetaData()
    {
        return pretransformedMetaData;
    }

    /**
     * Set original mining data specification (before transformation was applied).
     *
     * @param pretransformedMetaData pretransformedMetaData new original meta data
     */
    public void setPretransformedMetaData(MiningDataSpecification pretransformedMetaData)
    {
        this.pretransformedMetaData = pretransformedMetaData;
    }

    /**
     * Has the meta data been transformed?
     *
     * @return true if transformed, otherwise false
     */
    public boolean isTransformed()
    {
        return transformed;
    }

    /**
     * Sets whether the meta data has been transformed.
     *
     * @param transformed transformation state of meta data
     */
    public void setTransformed(boolean transformed)
    {
        this.transformed = transformed;
    }

    /**
     * Returns the transformations dictionary that
     * has driven the transformations.
     *
     * @return transformation dictionary of the transformations
     */
    public MiningTransformationActivity getMiningTransformationActivity()
    {
        return miningTransformationActivity;

⌨️ 快捷键说明

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