📄 customsequence.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: Java Data Mining API. Supported standarts: <a href="http://www.dmg.org">Predictive Model Markup Language (PMML 2.0) </a>; <a href="http://www.omg.org/cwm">DataMining specification for Common Warehouse Metamodel (OMG)</a>.
* Copyright: Copyright (c) 2002 Prudential Systems Software GmbH
* Company: <a href="mailto:valentine.stepanenko@zsoft.ru">ZSoft, Spb, Russia</a>
* @author Victor Borichev
* @author Valentine Stepanenko (valentine.stepanenko@zsoft.ru)
* @version 1.0
*/
package com.prudsys.pdm.Models.CustomerSeq;
import java.util.Vector;
import com.prudsys.pdm.Models.AssociationRules.ItemSet;
/**
* Used for customer sequence analysis (aka sequential basket analysis).
* Stores a sequence of ItemSets. <p>
*
* From PDM CWM extension.
*
* @see ItemSet
*/
public class CustomSequence extends com.prudsys.pdm.Cwm.Core.ModelElement implements com.prudsys.pdm.Core.MiningMatrixElement
{
// -----------------------------------------------------------------------
// Variables declarations
// -----------------------------------------------------------------------
/** Support of the sequence. */
private int support;
/** Itemsets of sequence. */
private Vector itemsets;
// -----------------------------------------------------------------------
// Constructors
// -----------------------------------------------------------------------
/**
* Default constructor.
*/
public CustomSequence() {
itemsets = new Vector();
support = 0;
}
// -----------------------------------------------------------------------
// Getter and setter methods
// -----------------------------------------------------------------------
/**
* Set support count of the sequence.
*
* @param supp new support count value
*/
public void setSupportCount(int supp)
{
support = supp;
}
/**
* Get support count of sequence.
*
* @return support as int
*/
public int getSupportCount()
{
return support;
}
/**
* Get number of itemsets in the sequence.
*
* @return size of list as int
*/
public int getSize()
{
return itemsets.size();
}
// -----------------------------------------------------------------------
// Item set manipulation methods
// -----------------------------------------------------------------------
/**
* Add itemset to the sequence.
*
* @param is itemset to add
*/
public void addItemSet(ItemSet is)
{
itemsets.addElement(is);
}
/**
* Get itemset from sequence as specified position.
*
* @param index position of itemset
* @return itemset as AbsItemSet
*/
public ItemSet getItemSet(int index)
{
return (ItemSet)itemsets.get(index);
}
// -----------------------------------------------------------------------
// java.lang.Object methods
// -----------------------------------------------------------------------
/**
* Find out if two customer sequences are equal.
* They must have the same size and contain the same itemsets in the same order.
* The support count variables are not compared.
*
* @param obj the customer sequence to compare with
* @return true is equal, otherwise false
*/
public boolean equals(Object obj)
{
CustomSequence cs = (CustomSequence)obj;
if( getSize() != cs.getSize() ) return false; // different sizes
for( int i=0; i < getSize(); i++ )
if( ! getItemSet(i).equals( cs.getItemSet(i)) ) return false;
return true;
}
/**
* Calculates the hash code.
*
* @return hash code
*/
public int hashCode() {
return ((ItemSet)itemsets.get(0)).hashCode();
}
/**
* Converts customer sequence of itemsets to String.
*
* @return string representation of customer itemsset
*/
public String toString()
{
String text = "";
int size = itemsets.size();
for (int j = 0; j < size; j++)
{
ItemSet is = (ItemSet)itemsets.get(j);
for (int k = 0; k < is.getSize(); k++)
text = text + " "+is.getItemAt(k);
if (j != size-1)
text = text + ", ";
}
text = text + " SuppCount = " + support;
return text;
}
/**
* Print sequence of itemsets.
*/
public void print()
{
int size = itemsets.size();
for(int j=0;j<size;j++)
{
ItemSet is = (ItemSet)itemsets.get(j);
for(int k=0;k<is.getSize();k++) System.out.print(" "+is.getItemAt(k));
if(j!=size-1) System.out.print(", ");
}
System.out.println("\tsupp = "+support);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -