- Timestamp:
- 09/24/15 10:59:05 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/CrossPare/src/de/ugoe/cs/cpdp/loader/CSVDataLoader.java
r4 r41 1 // Copyright 2015 Georg-August-Universität Göttingen, Germany 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 1 15 package de.ugoe.cs.cpdp.loader; 2 16 … … 11 25 12 26 /** 13 * Loads the instances for a software version from a CSV file of the PROMISE 14 * data set mined byJurezko and Madeyski.27 * Loads the instances for a software version from a CSV file of the PROMISE data set mined by 28 * Jurezko and Madeyski. 15 29 * 16 30 * @author Steffen Herbold … … 18 32 class CSVDataLoader implements SingleVersionLoader { 19 33 20 /* 21 * (non-Javadoc) 22 * 23 * @see 24 * de.ugoe.cs.cpdp.loader.AbstractFolderLoader.SingleVersionLoader#load( 25 * java.io.File) 26 */ 27 @Override 28 public Instances load(File file) { 29 final String[] lines; 30 try { 31 lines = FileTools.getLinesFromFile(file.getAbsolutePath()); 32 } catch (IOException e) { 33 throw new RuntimeException(e); 34 } 34 /* 35 * (non-Javadoc) 36 * 37 * @see de.ugoe.cs.cpdp.loader.AbstractFolderLoader.SingleVersionLoader#load( java.io.File) 38 */ 39 @Override 40 public Instances load(File file) { 41 final String[] lines; 42 try { 43 lines = FileTools.getLinesFromFile(file.getAbsolutePath()); 44 } 45 catch (IOException e) { 46 throw new RuntimeException(e); 47 } 35 48 36 37 49 // configure Instances 50 final ArrayList<Attribute> atts = new ArrayList<Attribute>(); 38 51 39 40 41 42 43 44 45 46 47 52 String[] lineSplit = lines[0].split(","); 53 for (int j = 0; j < lineSplit.length - 4; j++) { 54 atts.add(new Attribute(lineSplit[j + 3])); 55 } 56 final ArrayList<String> classAttVals = new ArrayList<String>(); 57 classAttVals.add("0"); 58 classAttVals.add("1"); 59 final Attribute classAtt = new Attribute("bug", classAttVals); 60 atts.add(classAtt); 48 61 49 50 62 final Instances data = new Instances(file.getName(), atts, 0); 63 data.setClass(classAtt); 51 64 52 // fetch data 53 for (int i = 1; i < lines.length; i++) { 54 lineSplit = lines[i].split(","); 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()); 58 } 59 values[values.length - 1] = lineSplit[lineSplit.length - 1].trim() 60 .equals("0") ? 0 : 1; 61 data.add(new DenseInstance(1.0, values)); 62 } 65 // fetch data 66 for (int i = 1; i < lines.length; i++) { 67 lineSplit = lines[i].split(","); 68 double[] values = new double[lineSplit.length - 3]; 69 for (int j = 0; j < values.length - 1; j++) { 70 values[j] = Double.parseDouble(lineSplit[j + 3].trim()); 71 } 72 values[values.length - 1] = lineSplit[lineSplit.length - 1].trim().equals("0") ? 0 : 1; 73 data.add(new DenseInstance(1.0, values)); 74 } 63 75 64 65 76 return data; 77 } 66 78 67 68 69 70 71 72 73 74 75 76 79 /* 80 * (non-Javadoc) 81 * 82 * @see de.ugoe.cs.cpdp.loader.AbstractFolderLoader.SingleVersionLoader# 83 * filenameFilter(java.lang.String) 84 */ 85 @Override 86 public boolean filenameFilter(String filename) { 87 return filename.endsWith(".csv"); 88 } 77 89 78 90 }
Note: See TracChangeset
for help on using the changeset viewer.