- Timestamp:
- 08/05/14 10:00:41 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/CrossPare/src/de/ugoe/cs/cpdp/loader/CSVDataLoader.java
r2 r4 8 8 import weka.core.DenseInstance; 9 9 import weka.core.Instances; 10 import de.ugoe.cs.cpdp.loader.AbstractFolderLoader.SingleVersionLoader;11 10 import de.ugoe.cs.util.FileTools; 12 11 13 12 /** 14 * Loads the instances for a software version from a CSV file of the // TODO dataset citation 15 * data set. 13 * Loads the instances for a software version from a CSV file of the PROMISE 14 * data set mined by Jurezko and Madeyski. 15 * 16 16 * @author Steffen Herbold 17 17 */ 18 18 class CSVDataLoader implements SingleVersionLoader { 19 20 /** 21 * Loads the instances. 22 * @param file handle to the file of the instances 23 * @return the instances 19 20 /* 21 * (non-Javadoc) 22 * 23 * @see 24 * de.ugoe.cs.cpdp.loader.AbstractFolderLoader.SingleVersionLoader#load( 25 * java.io.File) 24 26 */ 25 27 @Override … … 31 33 throw new RuntimeException(e); 32 34 } 33 35 34 36 // configure Instances 35 37 final ArrayList<Attribute> atts = new ArrayList<Attribute>(); 36 37 String[] lineSplit = lines[0].split(","); 38 for ( int j=0 ; j<lineSplit.length-4 ; j++) {39 atts.add(new Attribute(lineSplit[j +3]));38 39 String[] lineSplit = lines[0].split(","); 40 for (int j = 0; j < lineSplit.length - 4; j++) { 41 atts.add(new Attribute(lineSplit[j + 3])); 40 42 } 41 43 final ArrayList<String> classAttVals = new ArrayList<String>(); … … 44 46 final Attribute classAtt = new Attribute("bug", classAttVals); 45 47 atts.add(classAtt); 46 48 47 49 final Instances data = new Instances(file.getName(), atts, 0); 48 50 data.setClass(classAtt); 49 51 50 52 // fetch data 51 for ( int i=1 ; i<lines.length ; i++) {53 for (int i = 1; i < lines.length; i++) { 52 54 lineSplit = lines[i].split(","); 53 double[] values = new double[lineSplit.length -3];54 for ( int j=0 ; j<values.length-1 ; j++) {55 values[j] = Double.parseDouble(lineSplit[j +3].trim());55 double[] values = new double[lineSplit.length - 3]; 56 for (int j = 0; j < values.length - 1; j++) { 57 values[j] = Double.parseDouble(lineSplit[j + 3].trim()); 56 58 } 57 values[values.length-1] = lineSplit[lineSplit.length-1].trim().equals("0") ? 0 : 1; 59 values[values.length - 1] = lineSplit[lineSplit.length - 1].trim() 60 .equals("0") ? 0 : 1; 58 61 data.add(new DenseInstance(1.0, values)); 59 62 } 60 63 61 64 return data; 62 65 } 63 66 67 /* 68 * (non-Javadoc) 69 * 70 * @see de.ugoe.cs.cpdp.loader.AbstractFolderLoader.SingleVersionLoader# 71 * filenameFilter(java.lang.String) 72 */ 64 73 @Override 65 74 public boolean filenameFilter(String filename) {
Note: See TracChangeset
for help on using the changeset viewer.