package mpqareader; import java.io.*; import java.util.HashMap; public class SubjectivityLexicon implements Serializable { private static final long serialVersionUID = 0L; private HashMap map = new HashMap(); public SubjectivityLexicon(HashMap map) { this.map = map; } public SubjectivityLexicon(String filename) throws IOException { this(filename, true); } public SubjectivityLexicon(String filename, boolean usePoS) throws IOException { BufferedReader br = new BufferedReader(new FileReader(filename)); String line = br.readLine(); while(line != null) { line = line.trim(); String[] tokens = line.split("\\s+"); String w = null; String p = null; String t = null; String pp = "0"; for(String s: tokens) if(s.startsWith("type=")) t = "*" + s.substring("type=".length()); else if(s.startsWith("word1=")) w = s.substring("word1=".length()); else if(s.startsWith("pos1=")) p = s.substring("pos1=".length()); else if(s.startsWith("priorpolarity=")) { if(s.equals("priorpolarity=negative")) pp = "-"; else if(s.equals("priorpolarity=positive")) pp = "+"; } if(!usePoS || p.equals("anypos")) map.put(w, t + "/" + pp); else { if(p.equals("verb")) p = "VB"; else if(p.equals("noun")) p = "NN"; else if(p.equals("adj")) p = "JJ"; else if(p.equals("adverb")) p = "RB"; map.put(w + "/" + p, t + "/" + pp); } line = br.readLine(); } br.close(); System.err.println("Read subjectivity lexicon."); } public String lookup(String word, String pos, String lemma) { String w = word.toLowerCase(); if(pos.length() < 2) return null; if(lemma != null && !lemma.equals("_")) pos = pos.substring(0, 2); else if(pos.startsWith("RB")) lemma = w; String slClue = map.get(lemma); if(slClue == null) slClue = map.get(lemma + "/" + pos); return slClue; } public static void main(String[] argv) { try { SubjectivityLexicon lex = new SubjectivityLexicon(argv[0]); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); } catch(Exception e) { e.printStackTrace(); System.exit(1); } } }