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

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

package eti.bi.alphaminer.patch.standard.operation.operator;


import java.util.Vector;


import com.prudsys.pdm.Core.MiningException;
import com.prudsys.pdm.Input.MiningInputStream;
import com.prudsys.pdm.Input.MiningStoredData;
import com.prudsys.pdm.Input.Records.Arff.MiningArffStream;
import com.prudsys.pdm.Input.Relational.MiningSqlSource;
import com.prudsys.pdm.Input.Relational.MiningSqlStream;
import com.prudsys.pdm.Transform.Special.CopyMiningStream;

import eti.bi.alphaminer.core.handler.ICaseHandler;
import eti.bi.alphaminer.operation.operator.INodeInfo;
import eti.bi.alphaminer.operation.operator.InputOperator;
import eti.bi.alphaminer.vo.BIData;
import eti.bi.alphaminer.vo.BIObject;
import eti.bi.alphaminer.vo.IBIData;
import eti.bi.alphaminer.vo.IOperatorNode;
import eti.bi.exception.SysException;

/**
 * InputDataOperator is a kind of Operator
 */
public class InputDataOperator extends InputOperator {

/*	private MiningStoredData m_MiningStoredData;
	private MiningDataSpecification m_MiningDataSpecification;  
*/
	
//	private BIData m_OutputBIData;
	
	


	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * @param a_CaseID
	 * @param a_CaseWindow
	 * @param aOperatorInfo
	 */
	public InputDataOperator(String a_CaseID, INodeInfo aNodeInfo, ICaseHandler aCaseHandler) {
		super(a_CaseID, aNodeInfo, aCaseHandler);
		// TODO Auto-generated constructor stub
	}

	public void setMiningStoredData(MiningInputStream a_MiningInputData)
		throws SysException
	{
		IBIData aBIData = getOutputBIObject().getBIData();
		
		// If the mining input data is null, reset the BIData and clear temp data
		if (a_MiningInputData==null)
		{
			aBIData.setMiningStoredData(null);
			return;
		}
			
		MiningStoredData miningStoredData = new MiningStoredData();
		try
		{
			(new CopyMiningStream()).transform(a_MiningInputData, miningStoredData);
			miningStoredData.reset();
			aBIData.setMiningStoredData(miningStoredData);
			aBIData.writeTempBIData();
		} catch (MiningException me)
		{
			if (aBIData!=null)
			{
				aBIData.setMiningStoredData(null);
			}
			throw new SysException("[InputDataOperator].[setMiningStoredData].MiningException",me);
		}
	}
	
/*	public void loadTempBIData() throws MiningException
	{
		try
		{
			if (!m_OutputBIData.loadTempBIData())
			{
				// If the temp data file could not be loaded, get the metadata form the parameter
				BICase a_Case = CaseHandler.getInstance().getCase(m_CaseID, false);
				OperatorNode node = (OperatorNode) a_Case.getNode(NodeFactory.OPERATOR, m_NodeID);
				String filename = node.getParameterValue("Source location");
				if (filename!=null)
				{
					m_OutputBIData.setMetaData(MiningDataSpecification.getMiningDataSpecification(filename));
				}
			}
		} catch (Exception me)
		{
			throw new MiningException("Error in loading temporary data: " + me.getMessage());
		}
	}
	*/
	
	public boolean hasResult()
	{
		if (m_OutputBIObject != null)
		{
			return (m_OutputBIObject.hasResult(BIObject.DATA));
		}else
		{
			return false;
		}
	}

	public void execute(IOperatorNode a_OperatorNode, Vector a_Parents) throws SysException
	{
		
		/* Get parameter from user input */
		String type = (String) a_OperatorNode.getParameterValue("Source Type");
		
		/* Get input bi object from parent node */
		// No parent node //
		
		/* Prepare output mining data */
		BIData aOutputBIData = new BIData(getCaseID(), getNodeID());
		m_OutputBIObject.setBIData(aOutputBIData);		

		if (type==null)
		{
			throw new SysException("Please specify required information for input data source");
		}
		else if (type.equals("ARFF"))
		{
			String filename = (String) a_OperatorNode.getParameterValue("Source location");
			MiningInputStream input;
			try {
				input = new MiningArffStream(filename);
				setMiningStoredData(input);
				input.close();
			} catch (MiningException e) {
				throw new SysException("",e);
			}
		}
		else if (type.equals("ODBC"))
		{			
			MiningSqlSource a_Source = new MiningSqlSource();
			a_Source.setUrl((String) a_OperatorNode.getParameterValue("DB Name"));
			a_Source.setUser((String) a_OperatorNode.getParameterValue("DB User"));
			a_Source.setPassword((String) a_OperatorNode.getParameterValue("DB Password"));
			a_Source.setDriver((String) a_OperatorNode.getParameterValue("DB Driver"));
		
			MiningInputStream a_Input;
			try {
				a_Input = new MiningSqlStream(a_Source,"select * from " + (String) a_OperatorNode.getParameterValue("DB Table"));
				setMiningStoredData(a_Input);
				a_Input.close();
			} catch (IllegalArgumentException e) {
				throw new SysException("",e);
			} catch (MiningException e) {
				throw new SysException("",e);
			}
		}			
		a_OperatorNode.setParameterValue("Temporary data", aOutputBIData.getTempBIDataPath());			
	}
}

⌨️ 快捷键说明

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