-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCountNgrams.java
executable file
·51 lines (40 loc) · 1.22 KB
/
CountNgrams.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
46
47
48
49
50
51
import java.io.*;
import java.util.*;
public class CountNgrams {
private String file;
private ArrayList<String> triplets = new ArrayList<String>();
public CountNgrams(String f) {
file = f;
createNgramPolarityList();
}
public ArrayList<String> getTriplet() {
return triplets;
}
private void createNgramPolarityList() {
try {
LineNumberReader lnr = new LineNumberReader(new FileReader(file));
String line = null;
while((line = lnr.readLine()) != null) {
int result = (lnr.getLineNumber() - 1) % 6;
if (result == 0) {
Scanner s = new Scanner(line);
s.useDelimiter("#");
//System.out.println(line);
if(s.hasNext()) {
triplets.add(s.next().trim());
}
s.close();
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
CountNgrams cn = new CountNgrams(args[0]);
ArrayList<String> trip = cn.getTriplet();
for (String t : trip) {
System.out.println(t);
}
}
}