📄 categoricaltransformationoperator.java
字号:
// mapping.addCategoryPair(cat, new Category(new Integer(newCat)));
// break;
// case CategoricalAttribute.BOOLEAN:
// mapping.addCategoryPair(cat, new Category(new Boolean(newCat)));
// break;
// case CategoricalAttribute.DATETIME_PRUDSYS:
// mapping.addCategoryPair(cat, new Category(new Double(newCat)));
// break;
// case CategoricalAttribute.DATETIME_UNIX:
// mapping.addCategoryPair(cat, new Category(Long.getLong(newCat)));
// break;
}
}
return mapping;
}
public CategNumMapping preparecCategNumMapping(MiningDataSpecification a_MetaData, IOperatorNode a_Node) throws MiningException
{
CategNumMapping mapping = new CategNumMapping();
String sourceName = null;
String dataTypeStr = null;
int dataType = NumericAttribute.DOUBLE;
String targetCategStr = null;
Vector targetCateg = new Vector();
//get the target attribute
sourceName = (String) a_Node.getParameterValue("target");
//get the target data type
dataTypeStr = (String) a_Node.getParameterValue("targetDataType");
MiningAttribute mAtt = a_MetaData.getMiningAttribute(sourceName);
//get the target categories
targetCategStr = (String) a_Node.getParameterValue("targetCateg");
dataType = Integer.valueOf(dataTypeStr).intValue();
targetCateg = ValueValidator.unescapeParam(targetCategStr);
mapping.setSourceName(sourceName);
mapping.setTargetName(sourceName);
for(int i=0; i<((CategoricalAttribute)mAtt).getCategoriesNumber(); i++){
Category cat = ((CategoricalAttribute)mAtt).getCategory(i);
String newCat = (String)targetCateg.get(i);
switch(dataType){
case NumericAttribute.DOUBLE:
if(ValueValidator.isDouble(newCat))
mapping.addCategoryPair(cat, new Double(newCat));
else
mapping.addCategoryPair(cat, new Double(Double.NaN));
break;
// case NumericAttribute.FLOAT:
// mapping.addCategoryPair(cat, new Category(new Double(newCat)));
// break;
// case NumericAttribute.INTEGER:
// mapping.addCategoryPair(cat, new Category(new Float(newCat)));
// break;
// case NumericAttribute.BOOLEAN:
// mapping.addCategoryPair(cat, new Category(new Integer(newCat)));
// break;
// case NumericAttribute.DATETIME_PRUDSYS:
// mapping.addCategoryPair(cat, new Category(new Boolean(newCat)));
// break;
// case NumericAttribute.DATETIME_UNIX:
// mapping.addCategoryPair(cat, new Category(new Double(newCat)));
// break;
}
}
return mapping;
}
public Numerization preparecNumerization(MiningDataSpecification a_MetaData, IOperatorNode a_Node)throws MiningException
{
Numerization mapping = new Numerization();
String sourceName = null;
//get the target attribute
sourceName = (String) a_Node.getParameterValue("target");
mapping.setSourceName(sourceName);
mapping.setTargetName(sourceName);
return mapping;
}
private void validateParameters(MiningDataSpecification a_MetaData, IOperatorNode a_Node)throws AppException{
String value = null;
String sourceName = null;
int mode;
String dataTypeStr = null;
int dataType = CategoricalAttribute.STRING;
String targetCategStr = null;
Vector targetCateg = new Vector();
MiningAttribute mAtt = null;
boolean valid = true;
String message = "";
//get the target attribute
sourceName = (String) a_Node.getParameterValue("target");
if (sourceName == null){
message += Resource.srcStr("categoricalattributeMessage");
valid = false;
throw new AppException(message);
}
else {
mAtt = a_MetaData.getMiningAttribute(sourceName);
if(mAtt==null || !(mAtt instanceof CategoricalAttribute)){
message += Resource.srcStr("categoricalattributeMessage");
valid = false;
throw new AppException(message);
}
}
//get the mode
value = (String) a_Node.getParameterValue("mode");
if(value ==null || !ValueValidator.isNumeric(value)){
message += "Please select a target type or Auto numerization\n";
throw new AppException(message);
}
mode = Integer.valueOf(value).intValue();
if(mode == CATEG_MAPPING || mode == CATEG_NUM_MAPPING){
//get the target data type
dataTypeStr = (String) a_Node.getParameterValue("targetDataType");
if (dataTypeStr==null){
message += Resource.srcStr("datatypeMessage");
valid = false;
throw new AppException(message);
}
targetCategStr = (String) a_Node.getParameterValue("targetCateg");
if (targetCategStr==null){
message += Resource.srcStr("TargetcategoriesMessage");
valid = false;
throw new AppException(message);
}else{
targetCateg = ValueValidator.unescapeParam(targetCategStr);
if(targetCateg.size() != ((CategoricalAttribute)mAtt).getCategoriesNumber()){
message += Resource.srcStr("TargetcategoriesMessage");
valid = false;
throw new AppException(message);
}
}
if(valid && mode == CATEG_MAPPING){
dataType = Integer.valueOf(dataTypeStr).intValue();
for(int i=0; i<((CategoricalAttribute)mAtt).getCategoriesNumber(); i++){
//check the type
switch(dataType){
case CategoricalAttribute.STRING:
break;
// case CategoricalAttribute.DOUBLE:
// if(!ValueValidator.isDouble((String)targetCateg.get(i)))
// message += "";
// break;
// case CategoricalAttribute.FLOAT:
// if(!ValueValidator.isFloat((String)targetCateg.get(i)))
// message +="";
// break;
// case CategoricalAttribute.INTEGER:
// if(!ValueValidator.isNumeric((String)targetCateg.get(i)))
// message +="";
// break;
// case CategoricalAttribute.BOOLEAN:
// case CategoricalAttribute.DATETIME_PRUDSYS:
// case CategoricalAttribute.DATETIME_UNIX:
// break;
default:
message += Resource.srcStr("datatypeMessage")+"\n";
throw new AppException(message);
}
}
}
if(valid && mode == CATEG_NUM_MAPPING){
dataType = Integer.valueOf(dataTypeStr).intValue();
ArrayList catValues = ((CategoricalAttribute)mAtt).getValues();
for(int i=0; i<((CategoricalAttribute)mAtt).getCategoriesNumber(); i++){
String newCat = ((String)targetCateg.get(i)).trim();
switch(dataType){
case NumericAttribute.DOUBLE:
if(!newCat.equals("") && !ValueValidator.isDouble(newCat)){
message += "The target for category " + ((Category)catValues.get(i)).getValue().toString() +" should be a double \n";
throw new AppException(message);
}
break;
// case NumericAttribute.FLOAT:
// if(!ValueValidator.isFloat((String)targetCateg.get(i)))
// message +="";
// break;
// case NumericAttribute.INTEGER:
// if(!ValueValidator.isNumeric((String)targetCateg.get(i)))
// message +="";
// break;
// case NumericAttribute.BOOLEAN:
// case NumericAttribute.DATETIME_PRUDSYS:
// case NumericAttribute.DATETIME_UNIX:
// break;
default:
message += Resource.srcStr("datatypeMessage");
throw new AppException(message);
}
}
}
}else if (mode != NUMERIZATION){
message += "Please select a target type or Auto numerization\n";
throw new AppException(message);
}
// if(!message.equals(""))
// throw new AppException(message);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -