-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFM.java
108 lines (95 loc) · 2.54 KB
/
FM.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package SOM;
import java.io.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Pattern;
public class FM {
private static DateFormat df = new SimpleDateFormat("dd-MM-yy HH:mm:ss");
private static Date dateobj = new Date();
private Scanner scanner; //= new Scanner(new File("tall.txt"));
private FileWriter writer;
private double [][] TestData;
private boolean log_called=false;
String fname;
int linecount;
int IOSize;
int datasets;
public FM(String filename, int iosize){
IOSize=iosize;
fname=filename;
datasets=validateData();
System.out.println("Dataset Count: "+datasets);
TB.log("Reading Dataset "+filename);
TB.log("Dataset Count: "+datasets);
TestData = new double[datasets][iosize];
df = new SimpleDateFormat("dd-MM-yy HH:mm:ss");
dateobj = new Date();
}
public double[][] readData(){
boolean intfound=false;
Pattern delimiter=Pattern.compile("[,\n]");
try {
scanner = new Scanner(new File(fname),"UTF-8");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
scanner.useDelimiter(delimiter);
for(int j = 0;j<datasets;j++){
for(int i=0;i<IOSize;i++){
intfound=false;
while(intfound==false && scanner.hasNext()){
try{
String pattern = "[a-zA-Z]*";
scanner.skip(pattern);
if(scanner.hasNextDouble()){
TestData[j][i] = scanner.nextDouble();
intfound=true;
}
else { scanner.next(); }
}
catch (NumberFormatException ex) { continue; }
}
}
}
scanner.close();
return TestData;
}
private int validateData(){
int setcount=0;
try {
scanner = new Scanner(new File(fname),"UTF-8");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
scanner.useDelimiter(",");
while(scanner.hasNext()){
try{
String pattern = "[a-zA-Z\n]*";
scanner.skip(pattern);
if(scanner.hasNextDouble()){
scanner.nextDouble();
}
else { scanner.next(); }
setcount++;
}
catch (NumberFormatException ex) { continue; }
}
System.out.println("Incomplete Integers: "+(setcount%IOSize));
TB.log("Incomplete Integers: "+(setcount%IOSize));
scanner.close();
return ((setcount-(setcount%IOSize))/IOSize);
}
public int getdatacount(){ return datasets;}
public void ShowData(){
for(int j = 0;j<datasets;j++){
for(int i=0;i<IOSize;i++){
System.out.print(TestData[j][i]);
System.out.print(" ");
}
System.out.print("\n");
}
}
}