-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataset.java
More file actions
56 lines (54 loc) · 1.7 KB
/
Dataset.java
File metadata and controls
56 lines (54 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.io.BufferedReader;
import java.io.FileReader;
public class Dataset {
private static String[] attributes = null;
public String[][] getDataset(String path){
int rows = cntLine(path)-1;
String[][] dataset = new String[rows][];
try {
BufferedReader br = new BufferedReader(new FileReader(path));
String header = br.readLine();
attributes = header.split(",");
int index = 0;
String line;
while((line = br.readLine())!=null){
String values[] = line.split(",");
dataset[index] = new String[attributes.length];
for(int i=0;i<attributes.length;i++){
String value = values[i];
dataset[index][i]=value;
}
index++;
}
br.close();
}
catch (Exception e) {
e.printStackTrace();
}
return dataset;
}
public int cntLine(String path){
int cnt=0;
try {
BufferedReader br = new BufferedReader(new FileReader(path));
while(br.readLine()!=null){
cnt++;
}
br.close();
} catch (Exception e) {
e.printStackTrace();
}
return cnt;
}
public String[] getHeaderattributes(String keyattr){
String[] headerAttributes = new String[attributes.length-1];
int ind=0;
for(int i=0;i<attributes.length;i++){
if(!attributes[i].equals(keyattr)) headerAttributes[ind++]=attributes[i];
}
return headerAttributes;
}
public static String[] getAttributes(){
return attributes;
}
}