-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathNYTFileListReader.java
45 lines (35 loc) · 1.32 KB
/
NYTFileListReader.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
import java.io.*;
import java.util.ArrayList;
import java.util.List;
/**
* Created by sebastian on 28/03/15.
*/
public class NYTFileListReader {
/**
* Read the fileList file as produced by Gorski's jar
* @param fileName the name of the file
* @return a list of the NYT XML doc ids
*/
public static List<String> readFileList(String fileName) throws IOException {
InputStream inputStream = new FileInputStream(fileName);
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
List<String> ids = new ArrayList<String>();
String line = reader.readLine();
while (line != null) {
String[] list = line.split("/");
String docId = list[3].split("\\.")[0];
if (docId.length() != 7) {
throw new InvalidObjectException(String.format("{0} is not a valid NYT XML file ID. " +
"ID should be 7 digits long.", docId));
}
ids.add(docId);
System.out.println(docId);
// read next line
line = reader.readLine();
}
return ids;
}
public static void main(String[] args) throws IOException {
readFileList("/home/sebastian/git/sentiment_analysis/gorski/tools/fileList_Reviews.txt");
}
}