-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert.java
More file actions
98 lines (72 loc) · 3.24 KB
/
Copy pathconvert.java
File metadata and controls
98 lines (72 loc) · 3.24 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
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
import java.util.Arrays;
import javax.swing.text.StyledEditorKit.BoldAction;
import java.util.ArrayList;
import java.io.File; // Import the File class
import java.io.IOException; // Import the IOException class to handle errors
import java.io.FileWriter;
public class convert {
public static void main(String[] args) {
FileReader myFileReader = new FileReader("data.json");
String[] data = myFileReader.getStringData(152584);
String[] content = Arrays.copyOfRange(data, 1, data.length - 1);
String[] swearWords = { "fuck", "shit", "damn", "asshole", "bitch", "nigger", "nigga", "@", "<", "https",
"http" };
// System.out.println(Arrays.toString(content));
ArrayList<String> csv = new ArrayList<>();
int s = 0;
for (int i = 0; i < content.length; i++) {
String temp = content[i].replace("\": \"", "\",\"");
// int index = content[i].indexOf("\": \"");
// System.out.println(temp);
s = 0;
for (String word : temp.split("\\s+")) { // split string into words
if (Arrays.asList(swearWords).contains(word.toLowerCase())) {
// System.out.println("String contains a swear word: " + word);
s = 1;
break;
}
}
if (s == 0) {
csv.add(temp);
}
}
try {
File myObj = new File(".//out.csv");
if (myObj.createNewFile()) {
System.out.println("File created: " + myObj.getName());
FileWriter myWriter = new FileWriter(".//out.csv");
// myWriter.write("msg, reply\\n");
String[] sp = { "https", "<", ">", "@", "\\","//","{","}"};
boolean dontWrite = false;
for (int counter = 0; counter < csv.size(); counter++) {
dontWrite = false;
String myString = csv.get(counter);
String input = myString.substring(0, myString.length() - 1);
// String output = input.replaceAll("\"([^\"]*)\"",
// "$1".replaceAll("[^\\p{ASCII}\\p{L}\\p{N}\\p{P}\\s]+", ""));
String output = input.replace(':', ',').trim();
// if (output.contains("https") == false && output.contains("<") == false
// && output.contains("\\") == false && output.contains("{") == false) {
// }
for (int i = 0; i < sp.length; i++) {
if (output.contains(sp[i]) == true) {
dontWrite = true;
System.out.println(output);
break;
}
}
if (dontWrite != true) {
myWriter.write(output + "\n");
}
}
myWriter.close();
} else {
System.out.println("File already exists.");
}
} catch (IOException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
// System.out.println(csv);
}
}