import com.rapidminer.example.Attributes; //导入方法依赖的package包/类
@Override
public ExampleSet applyOnData(ExampleSet exampleSet) throws OperatorException {
ExampleSet resultSet = (ExampleSet) exampleSet.clone();
Attributes attributes = exampleSet.getAttributes();
Iterator iterator = attributes.iterator();
while (iterator.hasNext()) {
Attribute currentAttribute = iterator.next();
MappingTranslation mappingTranslation = translations.get(currentAttribute.getName());
if (mappingTranslation != null) {
// removing attribute from resultSet
Attributes resultAttributes = resultSet.getAttributes();
resultAttributes.remove(resultAttributes.get(currentAttribute.getName()));
// construct new attribute and add to memory table and exampleset
Attribute newAttribute = AttributeFactory.createAttribute(currentAttribute.getName(),
currentAttribute.getValueType(), currentAttribute.getBlockType());
resultSet.getExampleTable().addAttribute(newAttribute);
resultAttributes.addRegular(newAttribute);
AttributeRole role = attributes.getRole(currentAttribute);
if (role.isSpecial()) {
resultAttributes.setSpecialAttribute(newAttribute, role.getSpecialName());
}
// now copy value for each example
Iterator exampleIterator = exampleSet.iterator();
for (Example resultExample : resultSet) {
Example example = exampleIterator.next();
String nominalValue = example.getValueAsString(currentAttribute);
int result = mappingTranslation.newMapping.getIndex(nominalValue);
if (result != -1) {
resultExample.setValue(newAttribute, result);
} else {
resultExample.setValue(newAttribute, Double.NaN);
}
}
newAttribute.setMapping(mappingTranslation.newMapping);
}
}
return resultSet;
}