?? bidata.java
字號(hào):
/*
* 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.
*/
/*
* Created on 2004/12/31
*
* $Author$
* $Date$
* $Revision$
*
* * TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*
*/
package eti.bi.alphaminer.vo;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Vector;
import com.prudsys.pdm.Core.CategoricalAttribute;
import com.prudsys.pdm.Core.MiningAttribute;
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 eti.bi.alphaminer.core.transform.IDataTransformAction;
import eti.bi.common.Locale.Resource;
import eti.bi.common.System.SysConfig;
import eti.bi.exception.SysException;
/**
* This Data Mining Data store run time data produced by the operator
* nodes with the transformation histories, i.e. MiningStoredData, TransformAction, Target Attributes, etc.
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class BIData implements IBIData{
private String m_CaseID;
private String m_NodeID;
private Vector<IDataTransformAction> m_TransformActionHistory;
private MiningStoredData m_MiningStoredData;
private MiningDataSpecification m_MetaData;
private MiningAttribute m_TargetAttribute;
// private RemoveAttributes m_RemoveAttributes;
private String m_DataSourceName;
public BIData(String aCaseID, String aNodeID)
{
m_CaseID = aCaseID;
m_NodeID = aNodeID;
m_TransformActionHistory = new Vector<IDataTransformAction>();
m_DataSourceName = Resource.srcStr("m_DataSourceName");
}
/**
* @return Returns the metaData.
*/
public MiningDataSpecification getMetaData() {
return m_MetaData;
}
/**
* @param metaData The metaData to set.
*/
public void setMetaData(MiningDataSpecification metaData) {
m_MetaData = metaData;
}
//<<30/03/2005, Frank J. Xu
/**
* @param metaData The metaData to set.
*/
public void updateMetaData(MiningDataSpecification metaData) {
MiningDataSpecification newMetaData = metaData;
MiningAttribute[] attrs = newMetaData.getAttributesArray();
for(int i = 0; i < attrs.length; i++){
if(attrs[i] instanceof CategoricalAttribute){
CategoricalAttribute catAttr = (CategoricalAttribute)attrs[i];
if(catAttr.getCategoriesNumber() > 0 && catAttr.getCategoriesNumber() < MiningInputStream.CATEGORICAL_ATTRIBUTE_BOUND)
((CategoricalAttribute)attrs[i]).setUnboundedCategories(false);
}
}
setMetaData(newMetaData);
}
//30/03/2005, Frank J. Xu>>
/**
* @return Returns the miningStoredData.
*/
public MiningStoredData getMiningStoredData() {
return m_MiningStoredData;
}
/**
* @param miningStoredData The miningStoredData to set.
*/
public void setMiningStoredData(MiningStoredData miningStoredData) throws SysException{
//clear();
m_MiningStoredData = miningStoredData;
if (miningStoredData!=null)
{
try
{
//<<30/03/2005, Frank J. Xu
//setMetaData(miningStoredData.getMetaData());
updateMetaData(miningStoredData.getMetaData());
//30/03/2005, Frank J. Xu>>
}catch(MiningException e)
{
throw new SysException("[BIData].[setMiningStoredData]Fail to set metadata");
}
}else
{
setMetaData(null);
}
}
/**
* @return Returns the removeAttributes.
*/
/* public RemoveAttributes getRemoveAttributes() {
return m_RemoveAttributes;
}*/
/**
* @param removeAttributes The removeAttributes to set.
*/
/* public void setRemoveAttributes(RemoveAttributes removeAttributes) {
m_RemoveAttributes = removeAttributes;
}
*/
/* public void copyRemoveAttributes(RemoveAttributes removeAttributes)
{
if (removeAttributes!=null)
{
m_RemoveAttributes = new RemoveAttributes();
MiningAttribute[] attr = getMetaData().getAttributesArray();
String[] sourceAttr = (String [])removeAttributes.getSourceName().clone();
Vector remove = (Vector) removeAttributes.getRemoveAttributeNames();
m_RemoveAttributes.setSourceName(sourceAttr);
m_RemoveAttributes.setRemoveAttributeNames(remove);
}else
{
setRemoveAttributes(null);
}
}
*/
/**
* @return Returns the targetAttribute.
*/
public MiningAttribute getTargetAttribute() {
return m_TargetAttribute;
}
/**
* @param targetAttribute The targetAttribute to set.
*/
public void setTargetAttribute(MiningAttribute targetAttribute) {
m_TargetAttribute = targetAttribute;
}
/**
* @param targetAttribute The targetAttribute to set.
*/
public void copyTargetAttribute(MiningAttribute targetAttribute) {
if (targetAttribute!=null)
{
MiningAttribute aTargetAttribute = (MiningAttribute) m_MetaData.getMiningAttribute(targetAttribute.getName());
setTargetAttribute(aTargetAttribute);
}else
{
setTargetAttribute(null);
}
}
public void addTransformActionHistory(IDataTransformAction aNewTransformAction)
{
if (m_TransformActionHistory==null)
{
m_TransformActionHistory = new Vector<IDataTransformAction>();
}
m_TransformActionHistory.add(aNewTransformAction);
}
public Vector<IDataTransformAction> getTransformActionHistory()
{
return m_TransformActionHistory;
}
public void setTransformActionHistory(Vector<IDataTransformAction> aTransformationHistory)
{
m_TransformActionHistory = aTransformationHistory;
}
@SuppressWarnings("unchecked")
public void copyTransformActionHistory(Vector<IDataTransformAction> aTransformationHistory)
{
if (aTransformationHistory!=null)
{
m_TransformActionHistory = (Vector<IDataTransformAction>) aTransformationHistory.clone();
}else
{
m_TransformActionHistory = new Vector<IDataTransformAction>();
}
}
public void reset() throws SysException
{
if (m_MiningStoredData!=null)
{
try {
m_MiningStoredData.reset();
} catch (MiningException e) {
// TODO Auto-generated catch block
e.printStackTrace();
clear();
// setMiningStoredData(null);
}
}
}
public void clear()
{
clearTempBIData();
m_TransformActionHistory = new Vector<IDataTransformAction>();
m_MiningStoredData = null;
m_TargetAttribute = null;
// m_RemoveAttributes = null;
// m_DataSourceName = "Unknown Data Source Name";
}
public boolean hasResult()
{
return (m_MiningStoredData!=null);
}
public String getTempBIDataPath()
{
return SysConfig.getProperty("TEMP_CASES")+File.separator+"case_"+m_CaseID+File.separator+"tmp_"+m_NodeID+TEMP_FILE_EXTENSION;
}
public void clearTempBIData()
{
new File(SysConfig.getProperty("TEMP_CASES")+File.separator+"case_"+m_CaseID+File.separator+"tmp_"+m_NodeID+TEMP_FILE_EXTENSION).delete();
}
public void writeTempBIData() throws SysException
{
try
{
File f = new File(SysConfig.getProperty("TEMP_CASES")+File.separator+"case_"+m_CaseID);
f.mkdirs();
FileWriter fwriter = new FileWriter(getTempBIDataPath(), false);
m_MiningStoredData.write(fwriter, "arff");
fwriter.close();
} catch (IOException ie)
{
throw new SysException("IO Exception in writing temp file",ie);
} catch (MiningException e) {
throw new SysException("IO Exception in writing temp file",e);
}
}
public boolean loadTempBIData() throws SysException
{
File f = new File(getTempBIDataPath());
if (!f.exists() || !f.isFile())
{
return false;
}
MiningInputStream input = null;
try {
input = new MiningArffStream(getTempBIDataPath());
MiningStoredData miningStoredData = new MiningStoredData(input);
setMiningStoredData(miningStoredData);
input.close();
} catch (MiningException e) {
throw new SysException("Unable to load temp BI Data", e);
}
return true;
}
public File getTempFile()
{
File f = new File(SysConfig.getProperty("TEMP_CASES"));
if (!f.exists())
{
f.mkdir();
}
File tempFile = new File(getTempBIDataPath());
return tempFile;
}
/**
* @return Returns the m_DataSourceName.
*/
public String getDataSourceName() {
return m_DataSourceName;
}
/**
* @param dataSourceName The m_DataSourceName to set.
*/
public void setDataSourceName(String a_DataSourceName) {
m_DataSourceName = a_DataSourceName;
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -