forked from imakasx/CyberShield-Hackathon2025
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleCSV.java
More file actions
72 lines (61 loc) · 2.76 KB
/
SimpleCSV.java
File metadata and controls
72 lines (61 loc) · 2.76 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
72
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.*;
import java.util.*;
public class SimpleCSV {
// random platforms
private static final List<String> PLATFORMS = Arrays.asList(
"Twitter/X", "Facebook", "Instagram", "YouTube", "Telegram",
"Reddit", "Quora", "Koo", "LinkedIn", "WhatsApp"
);
// favour India
private static final List<String> PRO_TEXTS = Arrays.asList(
"भारत के वैज्ञानिकों पर गर्व है।",
"India’s startups are growing fast.",
"हमारी एकता ही हमारी ताकत है।",
"ISRO की success ने दुनिया को inspire किया।",
"Make in India बढ़ा रहा है manufacturing."
);
// against India
private static final List<String> AGAINST_TEXTS = Arrays.asList(
"India को गलत तरीके से दिखाया जा रहा है।",
"Misleading claims about Indian policies.",
"भारत के खिलाफ biased narrative है।",
"Unverified allegations used to criticise India.",
"India को unfair तरीके से judge किया गया।"
);
public static void main(String[] args) {
int rows = 50; // kitni rows
String file = "file.csv";
try {
generate(file, rows);
System.out.println("CSV created: " + Paths.get(file).toAbsolutePath());
} catch (IOException e) {
System.err.println("Error: " + e.getMessage());
}
}
private static void generate(String file, int rows) throws IOException {
Random rnd = new Random();
try (BufferedWriter bw = Files.newBufferedWriter(
Paths.get(file), StandardCharsets.UTF_8,
StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
// header
bw.write("id,platform,text");
bw.newLine();
for (int id = 1; id <= rows; id++) {
String platform = PLATFORMS.get(rnd.nextInt(PLATFORMS.size()));
boolean pro = rnd.nextBoolean();
String text = pro
? PRO_TEXTS.get(rnd.nextInt(PRO_TEXTS.size()))
: AGAINST_TEXTS.get(rnd.nextInt(AGAINST_TEXTS.size()));
// write row
bw.write(id + "," + csv(platform) + "," + csv(text));
bw.newLine();
}
}
}
// csv safe
private static String csv(String s) {
return "\"" + s.replace("\"", "\"\"") + "\"";
}
}