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

📄 dimension.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)
 * @version 1.0
 */

package com.prudsys.pdm.Olap.Metadata;

import java.util.Collection;
import java.util.Iterator;
import java.util.Vector;

import javax.olap.OLAPException;

import com.prudsys.pdm.Core.CategoricalAttribute;
import com.prudsys.pdm.Core.MiningAttribute;
import com.prudsys.pdm.Olap.OlapEngine;


/**
 * A Dimension is an ordinate within a multidimensional structure, and consists of
 * an ordered list of values (i.e.,  members) that share a common semantic meaning
 * within the domain being modeled.  Each member designates a unique position
 * along its ordinate.
 *
 *
 *
 * Typical Dimensions are: Time, Product, Geography, Scenario (e.g., actual,
 * budget, forecast), Measure (e.g., sales, quantity).
 */
public class Dimension extends com.prudsys.pdm.Cwm.Core.Class implements javax.olap.metadata.Dimension
{
   // -----------------------------------------------------------------------
   //  Variables declarations from CWM
   // -----------------------------------------------------------------------
   /**
    * If true, then this Dimension is a Time Dimension (i.e., its members
    * collectively represent a time series).
    */
   public com.prudsys.pdm.Cwm.Core.Boolean isTime = new com.prudsys.pdm.Cwm.Core.Boolean();

   /**
    * If true, then this Dimension is a Measure Dimension (i.e., its members
    * represent Measures).
    */
   public com.prudsys.pdm.Cwm.Core.Boolean isMeasure = new com.prudsys.pdm.Cwm.Core.Boolean();

   /** Specific subsets (e.g. levels) of the members of the dimensions. */
   public MemberSelection memberSelection[];

   /** Default hierarchy. */
   public Hierarchy displayDefault;

   /** Hierarchies of the dimension. */
   public Hierarchy hierarchy[];

   /** Associations to cubes which use the dimension. */
   public CubeDimensionAssociation cubeDimensionAssociation[];

   /** Schema to which the dimension is assigned. */
   public Schema schema;

   // -----------------------------------------------------------------------
   //  Variables declarations from XELOPES extension
   // -----------------------------------------------------------------------
   /** Reference to OLAP engine object. */
   protected OlapEngine olapEngine;

   /** Contains the categorical attributes used for OLAP. */
   protected Vector dimensionAttributes = new Vector();

   /** Names of all numeric attributes to be transformed to categorical ones. */
   protected Vector numericAttributeNames = new Vector();

   // -----------------------------------------------------------------------
   //  Constructors from CWM
   // -----------------------------------------------------------------------
   /**
    * Empty constructor.
    */
   public Dimension()
   {

   }

   // -----------------------------------------------------------------------
   //  Constructors from XELOPES extension
   // -----------------------------------------------------------------------
   /**
    * Constructor with reference to OLAP engine object.
    *
    * @param olapEngine OLAP engine object
    */
   public Dimension(OlapEngine olapEngine) {

     this.olapEngine = olapEngine;
   }

   // -----------------------------------------------------------------------
   //  JMI methods from CWM
   // -----------------------------------------------------------------------
   public javax.olap.metadata.Schema getSchema() throws OLAPException
   {
     return schema;
   }

   public void setSchema(javax.olap.metadata.Schema schema) throws OLAPException
   {
     this.schema = (Schema) schema;
   }

   public java.lang.Boolean getIsMeasure() throws OLAPException
   {
     return isMeasure.getBoolean();
   }

   public void setIsMeasure(java.lang.Boolean isMeasure) throws OLAPException
   {
     com.prudsys.pdm.Cwm.Core.Boolean b = new com.prudsys.pdm.Cwm.Core.Boolean();
     b.setBoolean(isMeasure);
     this.isMeasure = b;
   }

   public boolean isMeasureValue() throws OLAPException
   {
     return isMeasure.isBooleanValue();
   }

   public void setIsMeasure(boolean isMeasure) throws OLAPException
   {
     this.setIsMeasure( new Boolean(isMeasure) );
   }

   public java.lang.Boolean getIsTime() throws OLAPException
   {
     return isTime.getBoolean();
   }

   public void setIsTime(java.lang.Boolean isTime) throws OLAPException
   {
     com.prudsys.pdm.Cwm.Core.Boolean b = new com.prudsys.pdm.Cwm.Core.Boolean();
     b.setBoolean(isTime);
     this.isTime = b;
   }

   public boolean isTimeValue() throws OLAPException
   {
     return isTime.isBooleanValue();
   }

   public void setIsTime(boolean isTime) throws OLAPException
   {
     this.setIsTime( new Boolean(isTime) );
   }

   public Collection getHierarchy() throws OLAPException
   {
     return com.prudsys.pdm.Cwm.Core.CWMTools.ArrayToList(hierarchy);
   }

   public void setHierarchy(Collection hierarchy) throws OLAPException
   {
     this.hierarchy = new Hierarchy[ hierarchy.size() ];
     Iterator it = hierarchy.iterator();
     for (int i = 0; i < hierarchy.size(); i++)
       this.hierarchy[i] = (Hierarchy) it.next();
   }

   public void addHierarchy( javax.olap.metadata.Hierarchy input) throws OLAPException
   {
     int size = (hierarchy == null) ? 0 : hierarchy.length;
     Hierarchy[] oldData = hierarchy;
     hierarchy = new Hierarchy[size+1];
     if (size > 0) System.arraycopy(oldData, 0, hierarchy, 0, size);
     hierarchy[size] = (Hierarchy) input;
   }

   public void removeHierarchy( javax.olap.metadata.Hierarchy input) throws OLAPException
   {
     int size = (hierarchy == null) ? 0 : hierarchy.length;
     if (size == 0)
       return;

     int ipos = -1;
     for (int i = 0; i < size; i++)
       if (hierarchy[i].equals(input)) {
         ipos = i;
         break;
       }
     if (ipos == -1)
       return;

     Hierarchy[] oldData = hierarchy;
     hierarchy = new Hierarchy[size-1];
     for (int i = 0; i < ipos; i++)
       hierarchy[i] = oldData[i];
     for (int i = ipos+1; i < size; i++)
       hierarchy[i-1] = oldData[i];
   }

   public Collection getMemberSelection() throws OLAPException
   {
     return com.prudsys.pdm.Cwm.Core.CWMTools.ArrayToList(memberSelection);
   }

   public void setMemberSelection(Collection memberSelection) throws OLAPException
   {
     this.memberSelection = new MemberSelection[ memberSelection.size() ];
     Iterator it = memberSelection.iterator();
     for (int i = 0; i < memberSelection.size(); i++)
       this.memberSelection[i] = (MemberSelection) it.next();
   }

   public void addMemberSelection( javax.olap.metadata.MemberSelection input) throws OLAPException
   {
     int size = (memberSelection == null) ? 0 : memberSelection.length;
     MemberSelection[] oldData = memberSelection;
     memberSelection = new MemberSelection[size+1];
     if (size > 0) System.arraycopy(oldData, 0, memberSelection, 0, size);
     memberSelection[size] = (MemberSelection) input;
   }

   public void removeMemberSelection( javax.olap.metadata.MemberSelection input) throws OLAPException
   {
     int size = (memberSelection == null) ? 0 : memberSelection.length;
     if (size == 0)
       return;

     int ipos = -1;
     for (int i = 0; i < size; i++)
       if (memberSelection[i].equals(input)) {
         ipos = i;
         break;
       }
     if (ipos == -1)
       return;

     MemberSelection[] oldData = memberSelection;
     memberSelection = new MemberSelection[size-1];
     for (int i = 0; i < ipos; i++)
       memberSelection[i] = oldData[i];
     for (int i = ipos+1; i < size; i++)
       memberSelection[i-1] = oldData[i];
   }

   public Collection getCubeDimensionAssociation() throws OLAPException
   {
     return com.prudsys.pdm.Cwm.Core.CWMTools.ArrayToList(cubeDimensionAssociation);
   }

   public void setCubeDimensionAssociation(Collection cubeDimensionAssociation) throws OLAPException
   {
     this.cubeDimensionAssociation = new CubeDimensionAssociation[ cubeDimensionAssociation.size() ];
     Iterator it = cubeDimensionAssociation.iterator();
     for (int i = 0; i < cubeDimensionAssociation.size(); i++)
       this.cubeDimensionAssociation[i] = (CubeDimensionAssociation) it.next();
   }

   public void addCubeDimensionAssociation( javax.olap.metadata.CubeDimensionAssociation input) throws OLAPException
   {
     int size = (cubeDimensionAssociation == null) ? 0 : cubeDimensionAssociation.length;
     CubeDimensionAssociation[] oldData = cubeDimensionAssociation;
     cubeDimensionAssociation = new CubeDimensionAssociation[size+1];
     if (size > 0) System.arraycopy(oldData, 0, cubeDimensionAssociation, 0, size);
     cubeDimensionAssociation[size] = (CubeDimensionAssociation) input;
   }

   public void removeCubeDimensionAssociation( javax.olap.metadata.CubeDimensionAssociation input) throws OLAPException
   {
     int size = (cubeDimensionAssociation == null) ? 0 : cubeDimensionAssociation.length;
     if (size == 0)
       return;

     int ipos = -1;
     for (int i = 0; i < size; i++)
       if (cubeDimensionAssociation[i].equals(input)) {
         ipos = i;
         break;
       }
     if (ipos == -1)
       return;

     CubeDimensionAssociation[] oldData = cubeDimensionAssociation;
     cubeDimensionAssociation = new CubeDimensionAssociation[size-1];
     for (int i = 0; i < ipos; i++)
       cubeDimensionAssociation[i] = oldData[i];
     for (int i = ipos+1; i < size; i++)
       cubeDimensionAssociation[i-1] = oldData[i];
   }

   public javax.olap.metadata.Hierarchy getDisplayDefault() throws OLAPException
   {
     return displayDefault;
   }

   public void setDisplayDefault(javax.olap.metadata.Hierarchy displayDefault) throws OLAPException
   {
     this.displayDefault = (Hierarchy) displayDefault;
   }

   public String toString() {

     String s = "Dimension name = " + getName() + " \n";
     if (feature != null) {
       s = s + "#attributes = " + feature.length + " : ";
       for (int i = 0; i < feature.length; i++) {
         if (feature[i] instanceof org.omg.cwm.objectmodel.core.Attribute)
           s = s + feature[i].getName() + ", ";
       }
       s = s.substring(0, s.length()-2);
       s = s + "\n";
     }
     if (hierarchy != null) {
       s = s + "#hierarchies = " + hierarchy.length + " :\n";
       for (int i = 0; i < hierarchy.length; i++) {
           s = s + hierarchy[i].toString() + "\n";
       }
     }

     return s;
   }

   // -----------------------------------------------------------------------
   //  Methods from XELOPES extension
   // -----------------------------------------------------------------------
   /**
    * Returns the number of dimension attributes.
    *
    * @return number of dimension attributes
    */
   public int getNumberOfDimensionAttributes() {

     return dimensionAttributes.size();
   }

   /**
    * Returns dimension attributes.
    *
    * @return vector of dimension attributes
    */
   public Vector getDimensionAttributes() {

     return dimensionAttributes;
   }

   /**
    * Sets dimension attributes.
    *
    * @param dimensionAttributes new vector of dimension attributes
    */
   public void setDimensionAttributes(Vector dimensionAttributes) {

     this.dimensionAttributes = dimensionAttributes;
   }

   /**
    * Returns mining attribute that corresponds to specified dimension number.
    *
    * @param index specified dimension index
    * @return attribute of this index, null if not found
    */
   public MiningAttribute getDimensionAttribute(int index) {

     if (index < 0 || index >= dimensionAttributes.size())
       return null;

     return (MiningAttribute) dimensionAttributes.elementAt(index);
   }

   /**
    * Returns vector of all numeric attribute names. These attributes must
    * be transformed to categorical ones to be included as dimensional attributes.
    *
    * @return vector of numeric attribute names
    */
   public Vector getNumericAttributeNames() {

     return numericAttributeNames;
   }

   /**
    * Adds input attribute. If the attributes is already a categorical one,
    * it is accepted as dimension attribute. Otherwise, it's name is added to
    * the list of numeric attributes which later must be transformed into
    * categorical ones.
    *
    * @param attribute new input mining attribute
    * @throws OLAPException attributes not a mining attribute
    */
   public void addInputAttribute(org.omg.cwm.objectmodel.core.Attribute attribute) throws OLAPException {

     if ( !(attribute instanceof MiningAttribute) )
       throw new OLAPException("attribute no instance of MiningAttribute class");

     addFeature(attribute);
     if (attribute instanceof CategoricalAttribute)
       dimensionAttributes.addElement(attribute);
     else
       numericAttributeNames.addElement( attribute.getName() );
   }
}

⌨️ 快捷键说明

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