-
Notifications
You must be signed in to change notification settings - Fork 0
/
Reader.java
54 lines (48 loc) · 1.75 KB
/
Reader.java
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
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class Reader {
public Amostra[] readDataSet() {
Amostra amostras[] = new Amostra[272];
double input[] = new double[7];
double output[] = new double[3];
try {
FileReader file = new FileReader("ecoli.data");
BufferedReader fr = new BufferedReader(file);
String line;
int amostra = 0;
while ((line = fr.readLine()) != null) {
String[] s = line.split("\\s+");
for(int i=1; i<s.length; i++){
if(i==(s.length-1)){
switch(s[i]){
case "cp":
output[0]=1;
output[1]=0;
output[2]=0;
break;
case "pp":
output[0]=0;
output[1]=1;
output[2]=0;
break;
case "im":
output[0]=0;
output[1]=0;
output[2]=1;
break;
}
}else{
input[i-1] = Double.parseDouble(s[i]);
}
}
amostras[amostra] = new Amostra(input, output);
amostra++;
}
file.close();
} catch (IOException e) {
System.err.printf("Erro na abertura do arquivo: %s.\n", e.getMessage());
}
return amostras;
}
}