-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAAAreader.java
More file actions
55 lines (50 loc) · 2.14 KB
/
AAAreader.java
File metadata and controls
55 lines (50 loc) · 2.14 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
import java.util.Scanner;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
public class AAAreader {
public static void main(String[] args) {
try {
File path = new File("/Users/noellependergraft/Documents/Research/AAA/html");
File[] files = path.listFiles();
FileWriter output = new FileWriter("AAA.txt");
for (File file:files) {
Scanner scan = new Scanner(file);
String line = scan.nextLine();
while (!line.contains(",\"review\": [")) {
if (scan.hasNextLine()) {
line = scan.nextLine();
} else {
break;
}
}
while (scan.hasNextLine()) {
line = scan.nextLine().trim();
if (line.startsWith("\"datePublished\": \"")) {
line = line.replace("\"datePublished\": \"","");
//System.out.println(line.substring(0,line.lastIndexOf("\"")));
output.write(line.substring(0,line.lastIndexOf("\"")) + "\t");
} else if (line.startsWith("\"reviewBody\": \"")) {
line = line.replace("\"reviewBody\": \"","");
//System.out.println(line.substring(0,line.lastIndexOf("\"")));
output.write(line.substring(0,line.lastIndexOf("\"")) + "\t");
} else if (line.startsWith("\"author\":")) {
line = scan.nextLine().trim();
line = line.replace("\"@type\": \"","");
//System.out.println(line.substring(0,line.lastIndexOf("\"")));
output.write(line.substring(0,line.lastIndexOf("\"")) + "\t");
line = scan.nextLine().trim();
line = line.replace("\"name\":\"","");
//System.out.println(line.substring(0,line.lastIndexOf("\"")));
output.write(line.substring(0,line.lastIndexOf("\"")) + "\t");
} else if (line.startsWith("\"ratingValue\": \"")) {
line = line.replace("\"ratingValue\": \"","");
//System.out.println(line.substring(0,line.lastIndexOf("\"")));
output.write(line.substring(0,line.lastIndexOf("\"")) + "\n");
}
}
}
} catch (IOException e) {
}
}
}