📄 transactionalizationoperator.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.io.File;
import java.util.ArrayList;
import java.util.Vector;
import weka.filters.unsupervised.instance.RemoveWithValues;
import com.prudsys.pdm.Core.CategoricalAttribute;
import com.prudsys.pdm.Core.Category;
import com.prudsys.pdm.Core.MiningAttribute;
import com.prudsys.pdm.Core.MiningDataSpecification;
import com.prudsys.pdm.Core.MiningException;
import com.prudsys.pdm.Input.MiningStoredData;
import com.prudsys.pdm.Transform.MiningTransformationFactory;
import com.prudsys.pdm.Transform.Special.NontransactionalToTransactional;
import eti.bi.alphaminer.core.handler.ICaseHandler;
import eti.bi.alphaminer.core.transform.WekaTransformAction;
import eti.bi.alphaminer.core.transform.XelopesTransformAction;
import eti.bi.alphaminer.operation.operator.INodeInfo;
import eti.bi.alphaminer.operation.operator.Operator;
import eti.bi.alphaminer.operation.operator.TransformOperator;
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;
/**
* ReplacementOperator is a kind of Operator
*/
public class TransactionalizationOperator extends TransformOperator {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* @param a_CaseID
* @param a_CaseWindow
* @param aOperatorInfo
*/
public TransactionalizationOperator(String a_CaseID, INodeInfo aNodeInfo, ICaseHandler aCaseHandler) {
super(a_CaseID, aNodeInfo, aCaseHandler);
// TODO Auto-generated constructor stub
}
/**
* Set node id and update operator text of the Transactionalization 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 Transactionalization 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 + "]");
}
/* (non-Javadoc)
* @see eti.bi.alphaminer.ui.operator.Operator#hasResult()
*/
public boolean hasResult() {
/* Normally the operator has to check if the output data object and/or the output
* model object are exist by calling m_OutputBIObject.hasResult(int) by passing BIObject.DATA
* and BIObject.MODEL respectively. You may check both existance or either one by simple modifying
* the logic below.
*/
if (m_OutputBIObject != null)
{
return (m_OutputBIObject.hasResult(BIObject.DATA)); //&&
// m_OutputBIObject.hasResult(BIObject.MODEL));
}else
{
return false;
}
}
/* (non-Javadoc)
* @see eti.bi.alphaminer.ui.operator.Operator#execute(eti.bi.alphaminer.vo.OperatorNode, java.util.Vector)
*/
public void execute(IOperatorNode a_OperatorNode, Vector a_Parents) throws MiningException, AppException, SysException {
/*Get input bi object from parent node */
Operator parentOp = (Operator)a_Parents.elementAt(0);
setInputBIObject(parentOp.getOutputBIObject());
IBIData aInputBIData = getInputBIObject().getBIData();
/* Prepare output mining data */
BIData aOutputBIData = new BIData(getCaseID(), getNodeID());
@SuppressWarnings("unused") BIModel aOutputBIModel = new BIModel(getCaseID(), getNodeID(), IBIModel.TYPE_CLASSIFIER);
aOutputBIData.copyTransformActionHistory(aInputBIData.getTransformActionHistory());
File tempFile = aOutputBIData.getTempFile();
/* Execute transform */
@SuppressWarnings("unused") MiningTransformationFactory mtf = new MiningTransformationFactory();
NontransactionalToTransactional trans= prepareTransactinoalization(aInputBIData.getMetaData(),a_OperatorNode);
XelopesTransformAction action1 = new XelopesTransformAction(m_CaseID, m_NodeID, trans);
MiningStoredData msd1 = action1.transform(aInputBIData.getMiningStoredData());
aOutputBIData.addTransformActionHistory(action1);
if(msd1.getVectorsNumber()>0){
RemoveWithValues removeWithValues= prepareRemoveMissingValues(msd1);
WekaTransformAction action2 = new WekaTransformAction(m_CaseID, m_NodeID, tempFile.getAbsolutePath(), removeWithValues);
MiningStoredData msd2 = action2.transform(msd1);
aOutputBIData.addTransformActionHistory(action2);
aOutputBIData.setMiningStoredData(msd2);
}
else
{
aOutputBIData.setMiningStoredData(msd1);
}
/* Set Output Mining Data */
aOutputBIData.copyTargetAttribute(aInputBIData.getTargetAttribute());
m_OutputBIObject.setBIData(aOutputBIData);
/* set run time parameter value to the node object (It needs to be stored in the BIML) */
//a_OperatorNode.setParameterValue("Temporary data", aOutputBIData.getTempBIDataPath());
/* write temp data */
//aOutputBIData.writeTempBIData();
//System.out.println(aOutputMiningStoredData);
}
public NontransactionalToTransactional prepareTransactinoalization(MiningDataSpecification a_MetaData, IOperatorNode a_Node)
{
NontransactionalToTransactional trans = new NontransactionalToTransactional();
trans.setUnstoredAttributeValue(false);
trans.setUnstoredVectorNrId(false);
return trans;
}
public RemoveWithValues prepareRemoveMissingValues(MiningStoredData a_msd)
throws MiningException
{
RemoveWithValues removeWithValues = new RemoveWithValues();
MiningAttribute mAtt = a_msd.getMetaData().getMiningAttribute("Attribute value");
String selection = "";
String value = null;
ArrayList catValues = ((CategoricalAttribute)mAtt).getValues();
for (int j = 0; j < catValues.size(); j++) {
if(((Category) catValues.get(j)).getValue().getClass()== String.class){
value = (String)((Category) catValues.get(j)).getValue();
if(value.trim().equals("")){
selection += Integer.toString(j+1)+",";
}
}
}
if(selection.length() >0 && selection.charAt(selection.length()-1)==','){
selection = selection.substring(0, selection.length()-1);
}
removeWithValues.setAttributeIndex(Integer.toString(3));
removeWithValues.setInvertSelection(false);
removeWithValues.setMatchMissingValues(true);
removeWithValues.setNominalIndices(selection);
return removeWithValues;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -