| 1 | package de.ugoe.cs.cpdp.dataprocessing;
|
|---|
| 2 |
|
|---|
| 3 | import org.apache.commons.collections4.list.SetUniqueList;
|
|---|
| 4 |
|
|---|
| 5 | import weka.core.Instances;
|
|---|
| 6 |
|
|---|
| 7 | /**
|
|---|
| 8 | * Removes an attributes from all data sets using their name.
|
|---|
| 9 | * @author Steffen Herbold
|
|---|
| 10 | */
|
|---|
| 11 | public class AttributeRemoval implements ISetWiseProcessingStrategy, IProcessesingStrategy {
|
|---|
| 12 |
|
|---|
| 13 | /**
|
|---|
| 14 | * names of the attributes to be removed (determined by {@link #setParameter(String)})
|
|---|
| 15 | */
|
|---|
| 16 | private String[] attributeNames = new String[]{};
|
|---|
| 17 |
|
|---|
| 18 | /**
|
|---|
| 19 | * Sets that attributes that will be removed. The string contains the blank-separated names of the attributes to be removed.
|
|---|
| 20 | * <br><br>
|
|---|
| 21 | * Note, that removal of attributes with blanks is currently not supported!
|
|---|
| 22 | * @param parameters string with the blank-separated attribute names
|
|---|
| 23 | */
|
|---|
| 24 | @Override
|
|---|
| 25 | public void setParameter(String parameters) {
|
|---|
| 26 | if( parameters!=null ) {
|
|---|
| 27 | attributeNames = parameters.split(" ");
|
|---|
| 28 | }
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | /**
|
|---|
| 32 | * @see de.ugoe.cs.cpdp.dataprocessing.SetWiseProcessingStrategy#apply(weka.core.Instances, org.apache.commons.collections4.list.SetUniqueList)
|
|---|
| 33 | */
|
|---|
| 34 | @Override
|
|---|
| 35 | public void apply(Instances testdata, SetUniqueList<Instances> traindataSet) {
|
|---|
| 36 | for( String attributeName : attributeNames ) {
|
|---|
| 37 | for( int i=0 ; i<testdata.numAttributes() ; i++ ) {
|
|---|
| 38 | if( attributeName.equals(testdata.attribute(i).name()) ) {
|
|---|
| 39 | testdata.deleteAttributeAt(i);
|
|---|
| 40 | for( Instances traindata : traindataSet ) {
|
|---|
| 41 | traindata.deleteAttributeAt(i);
|
|---|
| 42 | }
|
|---|
| 43 | }
|
|---|
| 44 | }
|
|---|
| 45 | }
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | /**
|
|---|
| 49 | * @see de.ugoe.cs.cpdp.dataprocessing.ProcessesingStrategy#apply(weka.core.Instances, weka.core.Instances)
|
|---|
| 50 | */
|
|---|
| 51 | @Override
|
|---|
| 52 | public void apply(Instances testdata, Instances traindata) {
|
|---|
| 53 | for( String attributeName : attributeNames ) {
|
|---|
| 54 | for( int i=0 ; i<testdata.numAttributes() ; i++ ) {
|
|---|
| 55 | if( attributeName.equals(testdata.attribute(i).name()) ) {
|
|---|
| 56 | testdata.deleteAttributeAt(i);
|
|---|
| 57 | traindata.deleteAttributeAt(i);
|
|---|
| 58 | }
|
|---|
| 59 | }
|
|---|
| 60 | }
|
|---|
| 61 | }
|
|---|
| 62 | }
|
|---|