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

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

/*
 * Created on Sep 2, 2004
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package eti.bi.alphaminer.patch.standard.operation.property;


import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.util.Hashtable;

import javax.swing.JButton;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.border.EmptyBorder;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;


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.Core.NumericAttribute;

import eti.bi.alphaminer.core.handler.ICaseHandler;
import eti.bi.alphaminer.operation.operator.INodeInfo;
import eti.bi.alphaminer.operation.operator.Operator;
import eti.bi.alphaminer.operation.property.OperatorProperty;
import eti.bi.exception.SysException;
import eti.bi.util.ValueValidator;
import eti.bi.common.Locale.Resource;

/**
 * @author achiu
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public class DataSetAttributesOperatorProperty extends OperatorProperty {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4879509470469793635L;
	private MiningDataSpecification m_MetaData;
	private int m_TargetIndex = -1;
		
	private String[] m_MetaDataTableHeader = {Resource.srcStr("m_AttributeLabel"), Resource.srcStr("TypeTableHeader"), Resource.srcStr("DataTypeTableHeader"),Resource.srcStr("RoleTableHeader")};
	private Object[][] m_MetaDataTableContent;
	private JScrollPane jScrollPane1;
	private JTable jTable1;
	private DataSetAttributesTableModel TableModel;
	private JPanel jPanel1 = new JPanel();
	private JButton m_ButtonReset = new JButton();
	private JButton m_ButtonApply = new JButton();
	private JButton m_ButtonClose = new JButton();
	
	//<< Added by Joyce 2005-01-21
	private static final int m_Type_Col = 1;
	
	public static final String NUMERIC = "Numeric";
	public static final String CATEGORICAL = "Categorical" ;
	public static String NUMERIC_Text;
	public static String CATEGORICAL_Text;
	
	public static final String STRING = "String";
	public static final String DOUBLE = "Double";
	public static String STRING_Text;
	public static String DOUBLE_Text;
	
	public static final String USE = "Use";
	public static final String NOT_USE = "Not Use";
	public static final String TARGET = "Target";
	
	public static String USE_Text;
	public static String NOT_USE_Text;
	public static String TARGET_Text;
	
	public static final String TARGET_TAG = "afds34324412342fsdfsgdfds";
	private MiningAttribute m_ParentTargetAttr = null;
	//Declare as public since these values will be referenced by DataSetAttributesOperator. Mar 17, 2005. TWang.
	//>>
		
	public DataSetAttributesOperatorProperty(String a_CaseID, String a_NodeID, String a_Name,  INodeInfo a_NodeInfo, ICaseHandler a_CaseHandler)
	throws MiningException, SysException
	{
		super(a_CaseID, a_NodeID, a_Name,  a_NodeInfo, a_CaseHandler);
		createDataSetAttributesOperatorProperty();
		this.setResizable(true);
		this.setMaximizable(true);
		this.setTitle(Resource.srcStr("SetAttributes")+" ["+a_NodeID+"]") ; // Added title menu by Joyce 2005/02/17
	}	
	
	/**
	 * @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
	 */
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == m_ButtonApply) {
			if (validateProperty()){
				if (setContent())
				{
					m_ParameterChanged = true;
				}
				//m_ParentPanel.getCaseWindow().setModified(true);
				setPropertiesModified();
			}
		} else if (e.getSource() == m_ButtonReset) {
			getContent();
			jTable1.setModel(new DataSetAttributesTableModel(m_MetaDataTableContent, m_MetaDataTableHeader, m_TargetIndex));
		} else if (e.getSource() == m_ButtonClose)
			close();
	}

	protected void initContent() throws MiningException 
	{
		if (m_ParentOperators.size()>0)
		{
			Operator parentOp = (Operator)m_ParentOperators.elementAt(0);
			
			if (parentOp.getOutputBIObject()!=null && parentOp.getOutputBIObject().getBIData()!=null)
			{
				m_MetaData = parentOp.getOutputBIObject().getBIData().getMetaData();
				m_ParentTargetAttr = parentOp.getOutputBIObject().getBIData().getTargetAttribute();
			}
		}
		
		NUMERIC_Text = Resource.srcStr("NUMERIC");
		CATEGORICAL_Text = Resource.srcStr("CATEGORICAL");
		STRING_Text = Resource.srcStr("STRING");
		DOUBLE_Text = Resource.srcStr("DOUBLE");
		USE_Text = Resource.srcStr("USE");
		NOT_USE_Text = Resource.srcStr("NOT_USE");
		TARGET_Text = Resource.srcStr("TARGET");
	}

	private void getContent() {
		
		if (m_MetaData==null || m_Node==null)
			return;	
		int m_Column = m_MetaData.getAttributesNumber();
		if (m_Column==0)
			return;
		
		Hashtable oldParams = (Hashtable)m_Node.getParameters().clone();
		String targetAttr = null;
	
		
		String value = null;	
		String [] param;
		boolean valid = true;
		
		MiningAttribute[] miningAttributes = m_MetaData.getAttributesArray();
		MiningAttribute attribute = null;
		String name = null;
		
		Object[][] content = new Object[m_Column][m_MetaDataTableHeader.length];
		Object[] row = null;
		
	    if(m_Node.getParametersSize()<=0){
	        valid = false;
		}
		
	    // Check if the number of attribute is the same
	    value = (String) m_Node.getParameterValue("numOfAttr");
	    if(value==null || !ValueValidator.isInteger(value)){
	        valid = false;
	    }else{
	        int num = Integer.parseInt(value);
	        if(num != m_MetaData.getAttributesNumber()){
	            valid = false;
	        }
	    }
	            
	    // Check for each attribute type
	    for (int i=0; i<m_Column && valid; i++)
	    {
			row = new Object[m_MetaDataTableHeader.length];
			attribute = miningAttributes[i];
			name = attribute.getName();			
			value = (String)oldParams.get(name);
			
			if (value==null)
			{
			    valid=false;
			}else
			{
			    param = value.split(",");
			    if((param[3].equalsIgnoreCase(NUMERIC) 
			            	&& attribute instanceof CategoricalAttribute)
			        || (param[3].equalsIgnoreCase(CATEGORICAL) 
			                && attribute instanceof NumericAttribute)){
			        valid = false;
			    }
			}
	    }
	    
		for (int i=0; i<m_Column; i++)
		{
			row = new Object[m_MetaDataTableHeader.length];
			attribute = miningAttributes[i];
			name = attribute.getName();			
			value = (String)oldParams.get(name);
			
//			if(value == null)
//			    valid = false;
//			else {
			
			//check if the old and new data set are consistent
			if(valid && value!=null){
			    param = value.split(",");
			    if((param[3].equalsIgnoreCase(NUMERIC) 
			            	&& attribute instanceof CategoricalAttribute)
			        || (param[3].equalsIgnoreCase(CATEGORICAL) 
			                && attribute instanceof NumericAttribute)){
			        valid = false;
			    }else {
			        oldParams.remove(name);
			    }
			}
			
			//TODO if enable other data tye need to check for original data type too    
			    
			row[0] = name;
			row [3] = USE_Text;
			
			if (attribute instanceof NumericAttribute){
				row[1] = NUMERIC_Text;
			    if (attribute.getDataType() == NumericAttribute.DOUBLE )
			        row[2] =  DOUBLE_Text;
			    
			    if(m_ParentTargetAttr!=null 
			            && m_ParentTargetAttr.getName().equals(attribute.getName())
			            && m_ParentTargetAttr instanceof NumericAttribute
			            && m_ParentTargetAttr.getDataType() == attribute.getDataType()){
			        row[3] = TARGET_Text;
				    m_TargetIndex = i;
			    }
			}
			else if (attribute instanceof CategoricalAttribute){
				row[1] = CATEGORICAL_Text;
				if (attribute.getDataType() == CategoricalAttribute.STRING)
				    row[2] =  STRING_Text;
				
				 if(m_ParentTargetAttr!=null 
				         && m_ParentTargetAttr.getName().equals(attribute.getName())
				         && m_ParentTargetAttr instanceof CategoricalAttribute
				         && m_ParentTargetAttr.getDataType() == attribute.getDataType()){
				        row[3] = TARGET_Text;
					    m_TargetIndex = i;
				    }
			}
			
			content[i] = row;
		}
		
		if(valid){
		    targetAttr = (String) m_Node.getParameterValue(TARGET_TAG);
		}
		
		
	    if(valid){
	        Object[][] defaultContent = content;
	        content = new Object[m_Column][m_MetaDataTableHeader.length];
			row = null;
			
			for (int i=0; i<m_Column; i++)
			{
			    row = new Object[m_MetaDataTableHeader.length];
			    attribute = miningAttributes[i];
			    name = attribute.getName();	
			    
			    if(name.equals(targetAttr)){
			        m_TargetIndex = i;
			    }
			    
			    row[0] = name;
			//	set value stored in node
				value = (String) m_Node.getParameterValue(name);
				if(value!=null){
				    param = value.split(",");
				    row [1] = maptoText(param[0]);    //set type
				    row [2] = maptoText(param[1]);	   //set data type
				    row [3] = maptoText(param[2]);	   //set row
				    
				    content[i] = row;
				}else{
				    content[i] = defaultContent[i];
				}
			}
	    }
		m_MetaDataTableContent = content;					
	}
	
	private boolean validateProperty(){
		String message = "";
		if (jTable1.getRowCount() <= 0) {
			message += Resource.srcStr("EmptyAttributeMessage");
			m_MessageDialog.showWarning(message, Resource.srcStr("InvalidValueMessage"));
			return false;
		}	
		return true;
	}
	private boolean setContent(){
//		if (((DataSetAttributesTableModel)jTable1.getModel()).isModified() 
//		        || (jTable1.getRowCount()>0 && m_Node.getParameterValue(TARGET_TAG)==null))
	    if (jTable1.getRowCount()>0)
		{
		    MiningAttribute mAtt;
		    String attr = null;
			String type = null;
			String dataType = null;
			String role = null;
			String oriType = null;
			String oriDataType = null;
			String param = null;
			
//			int x = m_Node.getParametersSize();
			String Tips = (String) m_Node.getParameterValue("Tips");
			m_Node.getParameters().clear();
			if(Tips!=null)
			    m_Node.setParameterValue("Tips", Tips);
//			int y = m_Node.getParametersSize();

			for (int i=0; i<m_MetaDataTableContent.length; i++)
			{
				attr = (String)(TableModel).getValueAt(i, 0);
				mAtt = m_MetaData.getMiningAttribute(attr);
				if(mAtt instanceof CategoricalAttribute){
				    oriType = CATEGORICAL;
				    
				    //TODO change if later enabled more data type
				    oriDataType = STRING;
				}else {
				    oriType = NUMERIC;
				    
				    //TODO change if later enabled more data type
				    oriDataType = DOUBLE;
				}
				
				type = maptoName((String)(TableModel).getValueAt(i, 1));
				dataType = maptoName((String)((DataSetAttributesTableModel)TableModel).getValueAt(i, 2));
				role = maptoName((String)(TableModel).getValueAt(i, 3));
				
				if(role.equals(TARGET)){
				   m_Node.setParameterValue(TARGET_TAG, attr);
				}
				
				
				//TODO
				param = type +"," + dataType + "," + role + "," + oriType + "," + oriDataType;
				m_Node.setParameterValue(attr, param);
			}
			
			//Operator op = m_ParentPanel.getOperator(m_NodeID);
			//((DataSetAttributesOperator) m_Operator).clearResult();
			clearOperatorTempResult();
		
		}
	    
	    m_Node.removeParameterValue("numOfAttr");
	    m_Node.setParameterValue("numOfAttr", Integer.toString(m_MetaData.getAttributesNumber()));
	    setPropertiesModified();
	    return true;
	}
	
	
	private void createDataSetAttributesOperatorProperty() throws MiningException {
		jScrollPane1 = new JScrollPane();
		jTable1 = new JTable();

		this.setIconifiable(false);
		this.setResizable(true);
		this.setDefaultCloseOperation(
			javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
		this.getContentPane().setLayout(new BorderLayout());
		m_ButtonClose.setSelected(false);
		m_ButtonClose.setText("Close");
		this.getContentPane().add(jScrollPane1, BorderLayout.CENTER);
		this.getContentPane().add(jPanel1, BorderLayout.SOUTH);

⌨️ 快捷键说明

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