?? miningmetadata.java
字號:
package org.scut.DataMining.Core;
import org.scut.DataMining.Core.MiningAttribute;
import java.util.ArrayList;
import java.util.Date;
public class MiningMetaData
{
/** Name of the mining meta data */
private String name;
/** Attributes on mining */
private ArrayList<MiningAttribute> attributes = new ArrayList<MiningAttribute>();
/** Target attribute indice */
private ArrayList<Integer> target = new ArrayList<Integer>();
/** None target attribute indice */
private ArrayList<Integer> input = new ArrayList<Integer>();
/**
* Constucts a MiningMetaData object with no name
*/
public MiningMetaData()
{
this.name = "";
}
/**
* Constucts a MiningMetaData object by name
* @param name name of the MiningMetaData
*/
public MiningMetaData(String name)
{
this.name = name;
}
/**
* Gets the name of the meta data
* @return name of the meta data object
*/
public String getName()
{
return this.name;
}
/**
* Sets the name of the meta data object
* @param name name to be set to the meta data object
*/
public void setName(String name)
{
this.name = name;
}
/**
* Gets the count of the attributes in the metadata
* @return count value
*/
public int getAttributeCount()
{
return this.attributes.size();
}
/**
* Gets the count of the targets
* @return
*/
public int getTargetCount()
{
return this.target.size();
}
/**
* Gets the countof the non-targets
* @return
*/
public int getInputCount()
{
return this.input.size();
}
/**
* Gets the attribute at a specified position
* @param idx position
* @return MiningAttribute at the specified position
*/
public MiningAttribute getAttribute(int idx)
{
return this.attributes.get(idx);
}
/**
* Gets the index of the target at a speicified position
* @param idx
* @return
*/
public int getTargetIndex(int idx)
{
return this.target.get(idx);
}
/**
* Gets the index of the input at a specified position
* @param idx
* @return
*/
public int getInputIndex(int idx)
{
return this.input.get(idx);
}
/**
* Sets an attribute at a specified position
* @param idx position to be set at
* @param attr attibute to be set
*/
public void setAttribute(int idx,MiningAttribute attr)
{
this.attributes.set(idx,attr);
}
/**
* Adds an Attribute to the MetaData
* @param attr MiningAttribute object
*/
public void addAttribute(MiningAttribute attr)
{
this.attributes.add(attr);
}
/**
* Adds an attribute to the meta data at specified position
* @param idx
* @param attr
*/
public void addAttribute(int idx,MiningAttribute attr)
{
this.attributes.add(idx,attr);
}
/**
* Adds a target indext to the target indice array list
* @param idx index of the target to be added
*/
public void addTarget(int idx)
{
if( idx<0 || idx>=this.attributes.size()) return;
boolean valid = true;
for(int theIdx : this.input)
{
if(theIdx == idx)
{
valid = false;
break;
}
}
for(int theIdx : this.target)
{
if(theIdx == idx)
{
valid = false;
break;
}
}
if(valid)
this.target.add(idx);
}
/**
* Adds the input index
* @param idx
*/
public void addInput(int idx)
{
if( idx<0 || idx>=this.attributes.size()) return;
boolean valid = true;
for(int theIdx : this.input)
{
if(theIdx == idx)
{
valid = false;
break;
}
}
for(int theIdx : this.target)
{
if(theIdx == idx)
{
valid = false;
break;
}
}
if(valid)
this.input.add(idx);
}
/**
* Adds a target index by name within the attribute list
* @param name name of the attribute to be added
*/
public void addTarget(String name)
{
for(int i=0;i<this.attributes.size();i++)
{
if(this.attributes.get(i).getName().equals(name))
{
this.addTarget(i);
break; //: name unique, just break
}
}
}
/**
* Adds input by name
* @param name
*/
public void addInput(String name)
{
for(int i=0;i<this.attributes.size();i++)
{
if(this.attributes.get(i).getName().equals(name))
{
this.addInput(i);
break; //: name unique, just break
}
}
}
/*********************************************************************/
public static void main(String[] args)
{
long start = new Date().getTime();
MiningMetaData md = new MiningMetaData("Hong");
NumericAttribute ma1 = new NumericAttribute("NA1");
NumericAttribute ma2 = new NumericAttribute("NA2");
NumericAttribute ma3 = new NumericAttribute("NA3");
md.addAttribute(ma1);
md.addAttribute(ma2);
md.addAttribute(ma3);
md.addTarget("NA2");
md.addTarget("NA1");
//md.addTarget(1);
//md.addTarget(0);
System.out.println(md.getName());
long end = new Date().getTime();
System.out.println("Time eclipsed[s]: " + (end-start)/1000.0);
}
/*********************************************************************/
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -