-
Notifications
You must be signed in to change notification settings - Fork 0
/
ValenceReader.java
51 lines (38 loc) · 1.29 KB
/
ValenceReader.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 javax.xml.parsers.*;
import org.w3c.dom.*;
import java.util.*;
/* This is the class that reads the file containing
* the valence shifter dictionary.
*/
public class ValenceReader {
private File valence;
private HashMap<String,String> valenceMap = new HashMap<String,String>();
public ValenceReader(String file) {
valence = new File(file);
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document docValence = db.parse(valence);
NodeList nlv = docValence.getElementsByTagName("valence");
for (int x = 0; x < nlv.getLength(); x++) {
Node utNode = nlv.item(x);
if (utNode.getNodeType() == Node.ELEMENT_NODE) {
Element utElmnt = (Element) utNode;
String idValence = utElmnt.getTextContent();
String valueValence = utElmnt.getAttribute("value");
//System.out.println(idValence + ":" + valueValence);
valenceMap.put(idValence, valueValence);
}
}
} catch(Exception e) {
e.printStackTrace();
}
}
public String getHmmValueFor(String valence) {
return valenceMap.get(valence);
}
public static void main (String [] args) {
ValenceReader vr = new ValenceReader(args[0]);
}
}