-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddRandomFeatures.java
More file actions
71 lines (56 loc) · 1.6 KB
/
AddRandomFeatures.java
File metadata and controls
71 lines (56 loc) · 1.6 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class AddRandomFeatures {
/**
* @param args
*/
public static void main(String[] args) {
System.err.println("Usage: java AddRandomFeature random_feature_names(: separated) cadinality <input_tsv_file >output_tsv_file");
try {
if (args.length != 2) {
System.err.println("wrong input arguments - exit");
System.exit(-1);
}
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out, true);
String line = br.readLine(); // first line;
String str = "";
String[] names = args[0].split(":");
String[] upperBoundStrs = args[1].split(":");
if (names.length != upperBoundStrs.length) {
System.err.println("wrong input arguments - exit");
System.exit(-1);
}
int n = names.length;
int[] upperBounds = new int[upperBoundStrs.length];
int j=0;
for (String e: upperBoundStrs) {
upperBounds[j++] = Integer.parseInt(e);
}
for (String e : names) {
str += e + "\t";
}
pw.println(str + line);
Random randomGenerator = new Random();
int cnt = 0;
while ((line = br.readLine()) != null) {
str = "";
for (int i=0; i<n; i++) {
int f = randomGenerator.nextInt(upperBounds[i]) + 1;
str += f + "\t";
}
pw.println(str + line);
cnt++;
if (cnt % 1000 == 0) {
System.err.println(cnt + " lines processed.");
}
}
pw.close();
br.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}