-
Notifications
You must be signed in to change notification settings - Fork 0
/
NgramParser.java
executable file
·56 lines (44 loc) · 1.54 KB
/
NgramParser.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
52
53
54
55
56
import java.io.*;
import java.util.*;
public class NgramParser {
private String file;
private ArrayList<String> triplets = new ArrayList<String>();
private ArrayList<String> polarities = new ArrayList<String>();
public NgramParser(String f) {
file = f;
createNgramPolarityList();
}
public ArrayList<String> getTriplet() {
return triplets;
}
public ArrayList<String> getPolarity() {
return polarities;
}
private void createNgramPolarityList() {
try {
LineNumberReader lnr = new LineNumberReader(new FileReader(file));
String line = null;
while((line = lnr.readLine()) != null) {
int result = (lnr.getLineNumber() - 1) % 3;
if (result == 0) {
if (!(line.matches("-->[n|p][o|e][s|g]"))) {
Scanner s = new Scanner(line);
s.useDelimiter("#");
//System.out.println(line);
while(s.hasNext()) {
String s1 = s.next().trim();
String s2 = s.next().trim();
String s3 = s.next().trim();
String correctTriplet = s1 + "#" + s2 + "#" + s3;
triplets.add(correctTriplet);
}
} else {
polarities.add(line.substring(3));
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}