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

📄 category.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 Valentine Stepanenko (valentine.stepanenko@zsoft.ru)
  * @author Michael Thess
  * @version 1.0
  */

package com.prudsys.pdm.Core;

 /**
  * A Category is a potential value of a CategoricalAttribute. <p>
  *
  * For a given CategoricalAttribute, all categories must
  * be of the same Category subclass. <p>
  *
  * From CWM Data Mining. <p>
  *
  * Superclasses:
  * <ul>
  *   <li> ModelElement
  * </ul>
  * Attributes:
  * <ul>
  *   <li> <i>displayValue</i>: A string used when the category is displayed. <br>
  *     - type: String <br>
  *     - multiplicity: exactly one
  *   <li> <i>property</i>: Categories with "missing" property represent that
  *                  no information is available. If there are categories with
  *                  property "invalid" then other categories are valid by default.
  *                  If there are categories with property "valid" then other
  *                  categories are invalid by default. Positive and negative define
  *                  allowed values of a binary attribute. <br>
  *     - type: CategoryProperty (missing | invalid | valid | positive | negative) <br>
  *     - multiplicity: exactly one
  *   <li> <i>value</i>: Value holder for the Category. <br>
  *     - type: Any <br>
  *     - multiplicity: exactly one
  * </ul>
  * Constraints:
  * <ul>
  *   <li> An instance of Category must be owned by precisely one
  *   instance of CategoricalAttribute or any of its subclasses.
  * </ul>
  *
  * In addition, functionality from PMML was added.
  * It corresponds to the PMML element Value.
  *
  * @see CategoryProperty
  * @see CategoricalAttribute
  * @see com.prudsys.pdm.Adapters.PmmlVersion20.Value
  */
public class Category extends com.prudsys.pdm.Cwm.Core.ModelElement implements MiningMatrixElement
{
    // -----------------------------------------------------------------------
    //  Constants representing special values
    // -----------------------------------------------------------------------
    /** Constant representing a valid value. */
    public final static double VALID_VALUE = 0;

    /** Constant representing a missing value. */
    public final static double MISSING_VALUE = Double.NaN;

    /** Constant representing a not valid value. */
    public final static double INVALID_VALUE = Double.NEGATIVE_INFINITY;

    // -----------------------------------------------------------------------
    //  Variables declarations
    // -----------------------------------------------------------------------
    /** String representation of category. */
    private String displayValue;

    /** Property of category. */
    private CategoryProperty property;

    /** The category object. */
    private Object value;

    /** Reference to categorical attribute the category belongs to. Not used. */
    @SuppressWarnings("unused")
	private CategoricalAttribute categoricalAttribute;

    /** Reference to ordinal attribute the category belongs to. Not used. */
    @SuppressWarnings("unused")
	private OrdinalAttribute ordinalAttribute;

    // -----------------------------------------------------------------------
    //  Constructors
    // -----------------------------------------------------------------------
    /**
     * Empty constructor.
     */
    public Category()
    {
    }

    /**
     * Create new category from category object.
     *
     * @param value category object itself
     * @see CategoryProperty
     */
    public Category( Object value ) {

      this(value.toString(), value, new CategoryProperty());
    }

    /**
     * Create new category from full set of its objects.
     *
     * @param displayValue string that represents the category
     * @param value category object itself
     * @param property category property (missing, valid, positive, ...)
     * @see CategoryProperty
     */
    public Category( String displayValue, Object value, CategoryProperty property )
    {
        this.displayValue = displayValue;
        this.value        = value;
        this.property     = property;
    }

    // -----------------------------------------------------------------------
    //  Getter and setter methods
    // -----------------------------------------------------------------------
    /**
     * Return display value.
     *
     * @return display value
     */
    public String getDisplayValue()
    {
        return displayValue;
    }

    /**
     * Set display value.
     *
     * @param displayValue display value
     */
    public void setDisplayValue(String displayValue)
    {
        this.displayValue = displayValue;
    }

    /**
     * Return main category object.
     *
     * @return category value
     */
    public Object getValue()
    {
        return value;
    }

    /**
     * Set category object.
     *
     * @param value category value to set
     */
    public void setValue(Object value)
    {
        this.value = value;
    }

    /**
     * Return category property.
     *
     * @return category property
     */
    public CategoryProperty getProperty()
    {
        return property;
    }

    /**
     * Set category property.
     *
     * @param property category property to set
     */
    public void setProperty(CategoryProperty property)
    {
        this.property = property;
    }

    // -----------------------------------------------------------------------
    //  Methods for tests of special values
    // -----------------------------------------------------------------------
    /**
     * Is value valid?
     * Use this method instead of
     * <code> &ltvalue&gt == Category.VALID_VALUE </code> !
     *
     * @param value value to be checked
     * @return true if valid, else false
     */
    public static boolean isValidValue(double value) {

      if (value == VALID_VALUE)
        return true;
      else
        return false;
    }

    /**
     * Is value a missing value?
     * Use this method instead of
     * <code> &ltvalue&gt == Category.MISSING_VALUE </code> !
     *
     * @param value value to be checked
     * @return true if missing value, else false
     */
    public static boolean isMissingValue(double value) {

      return Double.isNaN(value);
    }

    /**
     * Is value invalid?
     * Use this method instead of
     * <code>&ltvalue&gt == Category.INVALID_VALUE</code> !
     *
     * @param value value to be checked
     * @return true if invalid, else false
     */
    public static boolean isInvalidValue(double value) {

      return Double.isInfinite(value);
    }

    // -----------------------------------------------------------------------
    //  java.lang.Object methods
    // -----------------------------------------------------------------------
    /**
     * Return hash code using only the hash code of the
     * category object (value).
     *
     * @return hash code of value
     */
    public int hashCode()
    {
        int hash = value.hashCode();
        return hash;
    }

    /**
     * Check for equality based only on the equality
     * operation of the category objects (values).
     *
     * @param obj object to compare
     * @return equality based on values comparison
     */
    public boolean equals( Object obj )
    {
        boolean b = false;
        if( obj != null && ( obj instanceof Category ) )
        {
            Category category = (Category)obj;
            b = value.equals( category.getValue() );
        }
        return b;
    }

    /**
     * Return display value as string representation.
     *
     * @return display value
     */
    public String toString()
    {
        return displayValue;
    }
}

⌨️ 快捷键说明

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