📄 inputdatafileoperator.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.
*/
/*
* $Author$
* $Date$
* $Revision$
*/
package eti.bi.alphaminer.patch.standard.operation.operator;
import java.util.Vector;
import com.prudsys.pdm.Core.MiningDataSpecification;
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.Records.Csv.MiningCsvStream;
import com.prudsys.pdm.Input.Records.Excel.MiningExcelStream;
import com.prudsys.pdm.Input.Records.Log.LogFileStream;
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;
/**
* @author jyung
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class InputDataFileOperator extends InputOperator {
/* private MiningStoredData m_MiningStoredData;
private MiningDataSpecification m_MiningDataSpecification;
*/
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* @param a_CaseID
* @param a_CaseWindow
* @param aOperatorInfo
*/
public InputDataFileOperator(String a_CaseID, INodeInfo aNodeInfo, ICaseHandler aCaseHandler) {
super(a_CaseID, aNodeInfo, aCaseHandler);
// TODO Auto-generated constructor stub
}
// private BIData m_OutputBIData;
private final String m_ARFF = "ARFF";
private final String m_CSV = "CSV";
private final String m_EXCEL = "EXCEL";
private final String m_IIS_LOG = "IIS_LOG";
private final String m_NCSA_COMMON_LOG = "NCSA_COMMON_LOG";
private final String m_NCSA_COMBINE_LOG = "NCSA_COMBINE_LOG";
private final String m_INTERSHOP_LOG = "INTERSHOP_LOG";
// set excel sheet at location
private int m_ExcelSheetAt = 0;
/**
* 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 + "]");
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 + "]");
}
public void setDataFileOperatorText(String a_filename){
setDescription(a_filename);
}
public void setMiningStoredData(MiningInputStream a_MiningInputData)
throws MiningException, 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 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 MiningException, 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 */
// ouputBIData already created in the property pane, do not create new output BI here.
//<< added by Joyce 2005/02/25
if (m_OutputBIObject.getBIData()== null){
IBIData aOutputBIData = new BIData(getCaseID(), getNodeID());
m_OutputBIObject.setBIData(aOutputBIData);
}
//>>
IBIData aOutputBIData = m_OutputBIObject.getBIData();
if (type==null)
{
throw new MiningException("Please specify required information for input data source");
}
else if (type.equals(m_ARFF))
{
String filename = (String) a_OperatorNode.getParameterValue("Source location");
MiningInputStream input = new MiningArffStream(filename);
setMiningStoredData(input);
input.close();
}
else if (type.equals(m_CSV))
{
String filename = (String) a_OperatorNode.getParameterValue("Source location");
MiningCsvStream csvStream = new MiningCsvStream(filename);
csvStream.setColumnNameType(MiningCsvStream.COLUMN_NAME_FIRST_LINE);
csvStream.setNumberTestLines(20);
csvStream.setSeparator(',');
csvStream.setQuotationMark('\"');
csvStream.open();
csvStream.updateCategoricalAttrsType();
setMiningStoredData(csvStream);
csvStream.close();
}
else if (type.equals(m_EXCEL))
{
///
String filename = (String) a_OperatorNode.getParameterValue("Source location");
m_ExcelSheetAt = (new Integer((String)a_OperatorNode.getParameterValue("Worksheet"))).intValue(); // Added by Joyce 2005/04/07
MiningExcelStream input = new MiningExcelStream(filename, null ,m_ExcelSheetAt);
// input.setSheetAt(m_ExcelSheetAt);
input.open();
/* while ( input.next() ) {
MiningVector mv = input.read();
System.out.println(mv + "\n") ;
}*/
setMiningStoredData(input);
//input.close();
}
else if (type.equals(m_IIS_LOG) ||type.equals(m_NCSA_COMMON_LOG) ||type.equals(m_NCSA_COMBINE_LOG) ||type.equals(m_INTERSHOP_LOG))
{
String filename = (String) a_OperatorNode.getParameterValue("Source location");
LogFileStream input = new LogFileStream(filename );
@SuppressWarnings("unused") MiningDataSpecification metaData = input.recognize();
setMiningStoredData(input);
input.close();
}
// 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 = new MiningSqlStream(a_Source,"select * from " + (String) a_OperatorNode.getParameterValue("DB Table"));
// setMiningStoredData(a_Input);
// a_Input.close();
// }
a_OperatorNode.setParameterValue("Temporary data", aOutputBIData.getTempBIDataPath());
}
public void set_ExcelSheetAt(int a_ExcelSheetAt){
m_ExcelSheetAt = a_ExcelSheetAt;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -