File size: 4,068 Bytes
bb654c7 |
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
/*
* Copyright (C) 2018 Southern Illinois University Carbondale, SoftSearch Lab
*
* Author: Amiangshu Bosu
*
* Licensed under GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.gnu.org/licenses/lgpl.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package edu.siu.sentise.preprocessing;
import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.HashMap;
import org.apache.log4j.chainsaw.Main;
import edu.siu.sentise.Configuration;
import edu.siu.sentise.util.Util;
public class AddSentiWord {
public static HashMap<String, Double> positiveSentiMap = new HashMap<>();
public static HashMap<String, Double> negtiveSentiMap = new HashMap<>();
public static ArrayList<String> swearWordMap;
/**
* converts sentiword.net tags to stanfordparser tags
*
* @param pos
* @return
*/
public static String getConvertedPOS(String pos) {
if (pos.equals("n"))
return "NN";
else if (pos.equals("v"))
return "VB";
else if (pos.equals("a"))
return "JJ";
else
return "";
}
public static void createPositiveSentiMap() {
BufferedReader bufferedReader = Util.getBufferedreaderByFileName(Configuration.POSITIVE_SENTI_WORD_FILE);
String line = null;
try {
while ((line = bufferedReader.readLine()) != null) {
String[] parse = line.split("#");
positiveSentiMap.put(parse[0] + "#" + getConvertedPOS(parse[1]), Double.parseDouble(parse[2]));
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void createNegativeSentiMap() {
BufferedReader bufferedReader = Util.getBufferedreaderByFileName(Configuration.NEGATIVE_SENTI_WORD_FILE);
String line = null;
try {
while ((line = bufferedReader.readLine()) != null) {
String[] parse = line.split("#");
negtiveSentiMap.put(parse[0] + "#" + getConvertedPOS(parse[1]), Double.parseDouble(parse[2]));
// System.out.println(line);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void createSwearWordMap() {
swearWordMap = new ArrayList<String>();
BufferedReader bufferedReader = Util.getBufferedreaderByFileName(Configuration.SWEAR_WORD_FILE);
String line = null;
try {
while ((line = bufferedReader.readLine()) != null) {
swearWordMap.add(line.trim());
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static boolean isSlangWord(String word) {
if (swearWordMap == null)
createSwearWordMap();
// System.out.println(word);
if (swearWordMap.contains(word)) {
return true;
}
return false;
}
public static double getPositiveSentiScore(String word, String pos) {
if (positiveSentiMap.size() == 0)
createPositiveSentiMap();
Double d = positiveSentiMap.get(word + "#" + getModifiedPOS(pos));
// System.out.println(word+ " "+d +" "+pos + positiveSentiMap.size());
if (d == null)
return 0;
return d;
}
public static double getNegativeSentiScore(String word, String pos) {
if (negtiveSentiMap.size() == 0)
createNegativeSentiMap();
Double d = negtiveSentiMap.get(word + "#" + getModifiedPOS(pos));
// System.out.println(word+ " "+d +" "+pos + negtiveSentiMap.size());
if (d == null)
return 0;
return d;
}
public static String getModifiedPOS(String pos) {
if (pos.startsWith("VB"))
return "VB";
if (pos.startsWith("JJ"))
return "JJ";
if (pos.startsWith("NN"))
return "NN";
else
return "";
}
public static void main(String[] args) {
createPositiveSentiMap();
createNegativeSentiMap();
}
}
|