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

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

package com.prudsys.pdm.Models.Sequential.Algorithms.Seq;

import java.util.Vector;

import com.prudsys.pdm.Models.Sequential.ItemSetSeq;


/**
 * Handling of transction list of sequential transactions.
 * Sequential transactions are contained in sequential
 * itemsets (ItemSetSeq).
 *
 * In addition to every element of a sequential itemset
 * a time as long value (e.g. milliseconds cince 1970)
 * can be assigned.
 *
 */
public class TransactionSetSeq {

  /**
   * Debugging.
   */
  private static final boolean debug = true;

  /**
   * Vector containing the sequential itemsets.
   */
  private Vector transactionList     = null;

  /**
   * Vector containing the times of transactions.
   */
  private Vector transactionTimeList = null;

  /**
   * Number of transactions.
   */
  private int size = 0;

  /**
   * Use additional explicit times.
   */
  private boolean useExplicitTimes = false;

  /**
   * Minimum support count.
   */
  private int minSuppCount = 0;

  /**
   * An empty transaction set. Additionally the use
   * of explicit times can be specified.
   *
   * @param useTimes use explicit times
   */
  public TransactionSetSeq(boolean useTimes) {

    this.transactionList  = new Vector();

    this.useExplicitTimes = useTimes;
    if (useExplicitTimes)
      this.transactionTimeList = new Vector();
  }

  /**
   * An empty transaction set.
   */
  public TransactionSetSeq() {

    this(false);
  }

  /**
   * Add transaction to transaction set.
   *
   * @param ItemSetSeq sequential item set
   */
  public void addTransaction(ItemSetSeq itemSetSeq) {

    transactionList.addElement(itemSetSeq);

    size = transactionList.size();
  }

  /**
   * Add transaction with times to transaction set. Times in
   * transaction must be contained in a Vector of Long
   * wrapper objects as time units.
   *
   * Operation is only allowed if explicit times are used.
   * Note that if the number of elements in the times vector
   * differs from that of the item set the operation also fails.
   *
   * @param ItemSetSeq sequential item set
   * @param ItemSetTimes times of sequential item set
   * @return true if transaction added, else false
   */
  public boolean addTimeTransaction(ItemSetSeq ItemSetSeq, Vector ItemSetTimes) {

    // Check for consistency:
    if (!useExplicitTimes)
      return false;

    if (ItemSetTimes.size() != ItemSetSeq.getSize())
      return false;

    // Add transaction:
    transactionList.addElement(ItemSetSeq);
    size = transactionList.size();

    // Add times:
    transactionTimeList.addElement(ItemSetTimes);

    return true;
  }

  /**
   * Remove all transactions from transaction set.
   *
   * New since version 1.1 to support abstract specification.
   */
  public void removeAllTransactions() {

    transactionList.removeAllElements();
  }


  /**
   * Get the number of transactions in transaction set.
   *
   * @return number of transactions
   */
   public int getSize() {
     return size;
   }

  /**
   * Are explicit times used?
   *
   * @return use of explicit times
   */
   public boolean useExplicitTimes() {
     return useExplicitTimes;
   }

   /**
    * Get sequential itemset (i.e. transaction) at defined position.
    *
    * @param index position of desired item set
    * @return desired sequential item set, null if impossible
    */
   public ItemSetSeq getTransactionAt(int index) {

      return getItemSetAt(index);
   }

   /**
    * Get sequential itemset (i.e. transaction) at defined position.
    *
    * @param index position of desired item set
    * @return desired sequential item set, null if impossible
    */
   public ItemSetSeq getItemSetAt(int index) {

      // Check bounds:
      if (index < 0 || index >= size) {
        System.out.println("want " + index + " have " + size);
        return null;
      };

      // Get item set:
      return  ((ItemSetSeq)(transactionList.elementAt(index)));
   }

   /**
    * Set sequential itemset at defined position.
    *
    * @param iss item set to replace the previous one
    * @param index position of desired item set
    */
   public void setItemSetAt(ItemSetSeq iss, int index) {

      // Check bounds:
      if (index < 0 || index >= size) {
        System.out.println("want " + index + " have " + size);
        return;
      };

      // Set item set:
      transactionList.setElementAt(iss, index);
   }

  /**
   * Calculate and set minimum support count.
   * Minimum support count is the minimum number of
   * transactions that must contain a given itemset
   * to be considered as large itemset.
   *
   * @param minsupp minimum support from [0,1] interval
   */
  public void setMinSuppCount(double minsupp) {

    minSuppCount=(int)(transactionList.size()*minsupp + 0.9999999);
  }

  /**
   * Gets minimum support count.
   *
   * @return minimum support count
   */
  public int getMinSuppCount() {

    return minSuppCount;
  }

  /**
   * String representation of sequential transaction set.
   *
   * @return String representation
   */
  public String toString() {

   String text = "TransactionSeqSet (" + size + " transactions)" + "\n";
   for (int i = 0; i < size; i++) {
     text = text + "["+i+"]\t" + ((ItemSetSeq)transactionList.elementAt(i)).toString();
     if (i < size - 1)
        text = text + "\n";
    };

    return text;
  }

   /**
    * Prints all transactions. If explicit times are used,
    * print also the times.
    */
   public void print() {

     System.out.println(toString());
  }

}

⌨️ 快捷键说明

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