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

📄 edgecursor.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 Michael Thess
  * @version 1.2
  */

package com.prudsys.pdm.Olap.Cursor;

import java.util.Collection;
import java.util.List;

import javax.olap.OLAPException;
import javax.olap.query.querycoremodel.Segment;

import com.prudsys.pdm.Core.Category;
import com.prudsys.pdm.Core.MiningAttribute;
import com.prudsys.pdm.Core.MiningDataSpecification;
import com.prudsys.pdm.Core.MiningException;
import com.prudsys.pdm.Cwm.JMIList;
import com.prudsys.pdm.Input.MiningInputStream;
import com.prudsys.pdm.Input.MiningVector;
import com.prudsys.pdm.Olap.Metadata.Dimension;
import com.prudsys.pdm.Olap.Query.Core.DimensionView;
import com.prudsys.pdm.Olap.Query.Core.EdgeView;
import com.prudsys.pdm.Utils.IntVector;

/**
 * Edge cursor access class.
 */
public class EdgeCursor extends Cursor implements javax.olap.cursor.EdgeCursor
{
  // -----------------------------------------------------------------------
  //  Variables declarations
  // -----------------------------------------------------------------------
  /** List of dimension cursors owned by this edge cursor. */
  protected JMIList dimensionCursor = new JMIList();

  /** Cube cursor owning this one as page edge. */
  protected CubeCursor pageOwner;

  /** Cube cursor owning this one as ordinate edge. */
  protected CubeCursor ordinateOwner;

  /** Reference to EdgeView. */
  protected EdgeView edgeView;

  /** Is page edge cursor. */
  protected boolean isPage = false;

  /** Stream with edge data. */
  protected MiningInputStream edgeStream = null;

  /** Mining vector containing only missing values. */
  protected MiningVector emptyVector = null;

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

  /**
   * Constructor with edge data.
   *
   * @param cubeCursor cube cursor owning this edge
   * @param isPage is page edge, otherwise ordinate edge
   * @param edgeView reference to associated edge view
   * @param edgeStream edge stream containing the data
   * @throws OLAPException couldn't create edge cursor
   */
  public EdgeCursor(CubeCursor cubeCursor, boolean isPage,
                    EdgeView edgeView, MiningInputStream edgeStream) throws OLAPException {

    this.isPage = isPage;
    if (isPage)
      this.pageOwner = cubeCursor;
    else
      this.ordinateOwner = cubeCursor;
    this.edgeView   = edgeView;
    this.edgeStream = edgeStream;

    createEmptyVector();
    createDimensions();
  }

  /**
   * Creates vector of missing values.
   *
   * @throws OLAPException cannot create vector
   */
  private void createEmptyVector() throws OLAPException {

    try {
      MiningDataSpecification metaData = edgeStream.getMetaData();
      int nAtt = metaData.getAttributesNumber();
      double[] val = new double[nAtt];
      for (int i = 0; i < nAtt; i++)
        val[i] = Category.MISSING_VALUE;
      emptyVector = new MiningVector(val);
      emptyVector.setMetaData(metaData);
    }
    catch (MiningException ex) {
      throw new OLAPException( ex.toString() );
    }
  }

  // -----------------------------------------------------------------------
  //  Create associated dimension cursors
  // -----------------------------------------------------------------------
  /**
   * Executes OLAP query using the multidimensional stream.
   *
   * @throws OLAPException couldn't execute query
   */
  private void createDimensions() throws OLAPException {

    try {
      // Create dimension cursors:
      int nDim = edgeView.getDimensionView().size();
      int[] indexes = new int[nDim];
      MiningDataSpecification metaData = edgeStream.getMetaData();
      for (int i = 0; i < nDim; i++) {
        DimensionView dimView  = (DimensionView) edgeView.getDimensionView().get(i);
        Dimension dim = (Dimension) dimView.getDimension();
        MiningAttribute ma = dim.getDimensionAttribute(0);
        indexes[i]    = metaData.getAttributeIndex(ma);

        // Crate edge cursor and add to page edges:
        DimensionCursor dimCursor = new DimensionCursor(this, dimView, null, null);
        addDimensionCursor(dimCursor);
      }
      for (int i = 0; i < nDim; i++) {
        DimensionCursor dc = (DimensionCursor) getDimensionCursor().get(i);
        DimensionCursor lc = null;
        if (i > 0) lc = (DimensionCursor) getDimensionCursor().get(i-1);
        DimensionCursor rc = null;
        if (i < nDim-1) rc = (DimensionCursor) getDimensionCursor().get(i+1);
        dc.leftCursor  = lc;
        dc.rightCursor = rc;
        if (i > 0) dc.setLeftNr(-1);
      }

      // Page cursors are changing dynamically, extent calculated in CubeCursor:
      if (isPage) return;

      // Calculate extents of all dimensions:
      IntVector[] extVec = new IntVector[nDim];  // array of extents
      for (int i = 0; i < nDim; i++)
        extVec[i] = new IntVector();

      int[] prevKeys     = new int[nDim]; // previous keys
      int[] dimKeys      = new int[nDim]; // current keys
      int nLine          = 0;             // number of lines
      edgeStream.reset();
      while ( edgeStream.next() ) {
        // Get vector:
        MiningVector mv = edgeStream.read();
        for (int i = 0; i < nDim; i++)
          dimKeys[i] = (int) mv.getValue( indexes[i] );

        // First line:
        if (nLine == 0) {
          System.arraycopy(dimKeys, 0, prevKeys, 0, nDim);
          for (int i = 0; i < nDim; i++)
            extVec[i].addElement(0);
        }
        nLine = nLine + 1;

        // Compare with previous keys:
        for (int i = 0; i < nDim; i++) {
          int ndim = extVec[i].size();
          if (dimKeys[i] != prevKeys[i]) {
            extVec[i].addElement(0);
            prevKeys[i] = dimKeys[i];
            ndim = ndim + 1;
          }

          int ext = extVec[i].IntegerAt(ndim-1);
          extVec[i].setElementAt(ext+1, ndim-1);
        }
      }

      // Assign extents to dimensions:
      for (int i = 0; i < nDim; i++) {
        int[] extents = null;
        if (i == 0) {
          extents = new int[1];
          extents[0] = extVec[0].size();
        }
        else {
          int ndim = extVec[i-1].size();
          extents = new int[ndim];
          for (int j = 0; j < ndim; j++)
            extents[j] = extVec[i-1].IntegerAt(j);
        };
        DimensionCursor dc = (DimensionCursor) getDimensionCursor().get(i);
        dc.setExtents(extents);
      }

    }
    catch (MiningException ex) {
      throw new OLAPException( ex.toString() );
    }
  }

  // -----------------------------------------------------------------------
  //  Getter and setter methods
  // -----------------------------------------------------------------------
  public void setDimensionCursor(Collection input) throws OLAPException {

    dimensionCursor.set(input);
  }

  public List getDimensionCursor() throws OLAPException {

    return dimensionCursor.get();
  }

  public void addDimensionCursor(javax.olap.cursor.DimensionCursor input) throws OLAPException {

    dimensionCursor.add(input);
  }

  public void removeDimensionCursor(javax.olap.cursor.DimensionCursor input) throws OLAPException {

    dimensionCursor.remove(input);
  }

  public void addDimensionCursorBefore(javax.olap.cursor.DimensionCursor before, javax.olap.cursor.DimensionCursor input) throws OLAPException {

    dimensionCursor.addBefore(before, input);
  }

  public void addDimensionCursorAfter(javax.olap.cursor.DimensionCursor before, javax.olap.cursor.DimensionCursor input) throws OLAPException {

    dimensionCursor.addAfter(before, input);

⌨️ 快捷键说明

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