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

📄 associationoperator.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.
 */

/*
 * $Author$ 
 * $Date$ 
 * $Revision$
*/
package eti.bi.alphaminer.patch.standard.operation.operator;
 

import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;




import com.prudsys.pdm.Core.CategoricalAttribute;
import com.prudsys.pdm.Core.Category;
import com.prudsys.pdm.Core.MiningAlgorithmSpecification;
import com.prudsys.pdm.Core.MiningException;
import com.prudsys.pdm.Core.MiningModel;
import com.prudsys.pdm.Input.MiningInputStream;
import com.prudsys.pdm.Input.MiningVector;
import com.prudsys.pdm.Input.Multidimensional.MultidimensionalStream;
import com.prudsys.pdm.Input.Multidimensional.SelectAttribute;
import com.prudsys.pdm.Models.AssociationRules.AssociationRulesAlgorithm;
import com.prudsys.pdm.Models.AssociationRules.AssociationRulesMiningModel;
import com.prudsys.pdm.Models.AssociationRules.AssociationRulesSettings;
import com.prudsys.pdm.Models.AssociationRules.ItemSet;
import com.prudsys.pdm.Models.AssociationRules.RuleSet;
import com.prudsys.pdm.Utils.GeneralUtils;

import eti.bi.alphaminer.core.handler.ICaseHandler;
import eti.bi.alphaminer.operation.operator.INodeInfo;
import eti.bi.alphaminer.operation.operator.ModelOperator;
import eti.bi.alphaminer.operation.operator.Operator;
import eti.bi.common.Locale.Resource;
import eti.bi.alphaminer.vo.BIData;
import eti.bi.alphaminer.vo.BIModel;
import eti.bi.alphaminer.vo.BIObject;
import eti.bi.alphaminer.vo.IBIData;
import eti.bi.alphaminer.vo.IBIModel;
import eti.bi.alphaminer.vo.IOperatorNode;
import eti.bi.exception.AppException;
import eti.bi.exception.SysException;
/**
 * AssociationOperator is a kind of Operator
 */
public class AssociationOperator extends ModelOperator {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * @param a_CaseID
	 * @param a_CaseWindow
	 * @param aOperatorInfo
	 */
	public AssociationOperator(String a_CaseID, INodeInfo aNodeInfo, ICaseHandler aCaseHandler) {
		super(a_CaseID, aNodeInfo, aCaseHandler);
		//2006/07/29 Xiaojun Chen
	}

	/* Parameter name for Association Operator in BIML */
	//public static String STEPS_TO_APRIORIHYBRID = "Steps to AprioriHybrid";
	public static String MIN_ITEM_SIZE = "Min item size";
	public static String MAX_ITEM_SIZE = "Max item size";	
	public static String MIN_SUPPORT = "Min support";
	public static String MIN_CONFIDENCE = "Min confidence";
	public static String GENERATE_RULES = "Generate rules";
	public static String ITEM_ID_ATTRIBUTE = "Item id attribute";
	public static String ITEM_ID_ATTRIBUTE_DATA_TYPE = "NULL";
	public static String TRANSACTION_ID_ATTRIBUTE = "Transaction id attribute";
	public static String TRANSACTION_ID_ATTRIBUTE_DATA_TYPE = "NULL";
	
	/* Parameter value for Association Operator */
	public static String VALUE_MAX_ITEM_SIZE_NO_LIMIT = "-1";
	
	/* Default parameter value for Association Operator */
	//public static String DEFAULT_STEPS_TO_APRIORIHYBRID = "4";
	public static String DEFAULT_MIN_ITEM_SIZE = "2";
	public static String DEFAULT_MAX_ITEM_SIZE = "5";	
	public static String DEFAULT_MIN_SUPPORT = "0.1";
	public static String DEFAULT_MIN_CONFIDENCE = "50";
	public static String DEFAULT_GENERATE_RULES = String.valueOf(true);
	
	/* Parameter name for MiningSettingSpecification and MiningAlgorithm */
	//<<Frank J. Xu, 10/05/2005
	//Using open source code from Xelopes1.2.4, instead of using the commercial version.	
	//private static String ALGORITHM_NAME = "AprioriHybrid";
	private static String ALGORITHM_NAME = "AprioriSimple";	
	//private static String MAP_APRIORYHYBRID_STEP = "aprioryHybridStep";
	//Frank J. Xu, 10/05/2005>>
	private static String MAP_MIN_ITEM_SIZE = "minimumItemSize";
	private static String MAP_MAX_ITEM_SIZE = "maximumItemSize";
	private static String MAP_GEN_RULES = "generateRules";	
	
	/**
	 * Set node id and update operator text of the DecisionTreeOperator at the same time.
	 * @param a_NodeID ID of the node
	 */
	public void setNodeID(String a_NodeID) {
		setLabel(getDescription() + " [" + a_NodeID + "]");
		setDefaultModelName("Association_" + a_NodeID);
		super.setNodeID(a_NodeID);
	}
	
	/**
	 * Set node id and update operator text of the DecisionTreeOperator at the same time.
	 * @param a_NodeID ID of the node
	 */
	public void setDescription(String a_Description) {
		m_Description = a_Description;
		setLabel(m_Description + " [" + m_NodeID + "]");
		setDefaultModelName("Association_" + m_NodeID);
	}
	
	/**
	 * Test if the Association Operator contains any results.
	 * @return true if Association Operator has result; false otherwise.
	 */
	public boolean hasResult() {
		if (m_OutputBIObject != null)
		{
			return (m_OutputBIObject.hasResult(BIObject.DATA) &&
					m_OutputBIObject.hasResult(BIObject.MODEL));
		}else
		{
			return false;
		}
	}
	
/*	public void clearDependentParameters() {
		System.out.println("clear dependent parameters: " + m_NodeID);
		BICase selectedCase = null;
		try {
			selectedCase = CaseHandler.getInstance().getCase(m_CaseID, false);
		} catch (BaseException be) {
			System.out.println(be.getMessage());
		}
		if (selectedCase==null)
			return;
		
		OperatorNode operatorNode =
			(OperatorNode) selectedCase.getNode(NodeFactory.OPERATOR, m_NodeID);		
		if (operatorNode==null)
			return;
		
		operatorNode.removeParameterValue(ITEM_ID_ATTRIBUTE);
		operatorNode.removeParameterValue(TRANSACTION_ID_ATTRIBUTE);
		super.clearDependentParameters();
	}*/
	
	/**
	 * Build association model for this Association Operator.
	 * @param a_OperatorNode Operator Node represented by this Association Operator.
	 * @param a_Parents a Vector storing node IDs of parent nodes of this Association Operator.
	 */
	public void execute(IOperatorNode a_OperatorNode, Vector a_Parents)
		throws MiningException, SysException, AppException
	{		
		/* Get parameter from user input */
		//String steps = a_OperatorNode.getParameterValue(STEPS_TO_APRIORIHYBRID);
		//if (steps==null)
		//	steps = DEFAULT_STEPS_TO_APRIORIHYBRID;
 		String minSize = (String) a_OperatorNode.getParameterValue(MIN_ITEM_SIZE);
		if (minSize==null)
			minSize = DEFAULT_MIN_ITEM_SIZE;
		String maxSize = (String) a_OperatorNode.getParameterValue(MAX_ITEM_SIZE);
		if (maxSize==null)
			maxSize = VALUE_MAX_ITEM_SIZE_NO_LIMIT;
		String support = (String) a_OperatorNode.getParameterValue(MIN_SUPPORT);
		if (support==null)
			support = DEFAULT_MIN_SUPPORT;
		String confidence = (String) a_OperatorNode.getParameterValue(MIN_CONFIDENCE);
		if (confidence==null)
			confidence = DEFAULT_MIN_CONFIDENCE;
		String generateRules = (String) a_OperatorNode.getParameterValue(GENERATE_RULES);	
		if (generateRules==null)
			generateRules = DEFAULT_GENERATE_RULES;
		String itemAttribute = (String) a_OperatorNode.getParameterValue(ITEM_ID_ATTRIBUTE);
		String transactionAttribute = (String) a_OperatorNode.getParameterValue(TRANSACTION_ID_ATTRIBUTE);
	
		/* Get input bi object from parent node */
		Operator parentOp = (Operator)a_Parents.elementAt(0);
		setInputBIObject(parentOp.getOutputBIObject());
		IBIData aInputBIData = getInputBIObject().getBIData();
		aInputBIData.getMiningStoredData().reset();
	
		/* Prepare output data model */
		BIData aOutputBIData = new BIData(getCaseID(), getNodeID());
		aOutputBIData.setTargetAttribute(aInputBIData.getTargetAttribute());
		aOutputBIData.setTransformActionHistory(aInputBIData.getTransformActionHistory());
		aOutputBIData.setMiningStoredData(aInputBIData.getMiningStoredData());
		IBIModel aOutputBIModel = new BIModel(getCaseID(), getNodeID(), IBIModel.TYPE_ASSOCIATION);
	
		/* Execute Association Model Building steps */    
	    /* Create MiningSettings object and assign metadata */
	    AssociationRulesSettings miningSettings = new AssociationRulesSettings();
	    miningSettings.setDataSpecification(aInputBIData.getMetaData());
	
	    /* Get transactional attributes */
	    CategoricalAttribute categoryItemId = null;
	    CategoricalAttribute categoryTransactId = null;

	    try {
		    if (itemAttribute!=null)
		    	categoryItemId = (CategoricalAttribute)aInputBIData.getMetaData().getMiningAttribute(itemAttribute);
		
		    if (transactionAttribute!=null)
		    	categoryTransactId = (CategoricalAttribute)aInputBIData.getMetaData().getMiningAttribute(transactionAttribute);	
	    } catch (Exception e)
		{
	    	m_SystemMessageHandler.appendMessage("Please specify all algorithm settings correctly in building the Association model.");
	    	throw new AppException("Please specify all algorithm settings correctly in building the Association model.");

⌨️ 快捷键说明

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