Computer Science, asked by axdtyjerrinas9515, 1 year ago

How to perform sentiwordnet python sentiment analysis of a dentence?

Answers

Answered by shahma2
0
I need to do sentiment analysis on some csv files containing tweets. I'm using SentiWordNet to do the sentiment analysis.

I got the following piece of sample java code they provided on their site. I'm not sure how to use it. The path of the csv file that I want to analyze is C:\Users\MyName\Desktop\tweets.csv . The path of the SentiWordNet_3.0.0.txt is C:\Users\MyName\Desktop\SentiWordNet_3.0.0\home\swn\www\admin\dump\SentiWordNet_3.0.0_20130122.txt . I'm new to java, pls help, thanks! The link to the sample java code below is this.

import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.util.HashMap; import java.util.Iterator; import java.util.Set; import java.util.Vector; public class SWN3 { private String pathToSWN = "data"+File.separator+"SentiWordNet_3.0.0.txt"; private HashMap<String, String> _dict; public SWN3(){ _dict = new HashMap<String, String>(); HashMap<String, Vector<Double>> _temp = new HashMap<String, Vector<Double>>(); try{ BufferedReader csv = new BufferedReader(new FileReader(pathToSWN)); String line = ""; while((line = csv.readLine()) != null) { String[] data = line.split("\t"); Double score = Double.parseDouble(data[2])-Double.parseDouble(data[3]); String[] words = data[4].split(" "); for(String w:words) { String[] w_n = w.split("#"); w_n[0] += "#"+data[0]; int index = Integer.parseInt(w_n[1])-1; if(_temp.containsKey(w_n[0])) { Vector<Double> v = _temp.get(w_n[0]); if(index>v.size()) for(int i = v.size();i<index; i++) v.add(0.0); v.add(index, score); _temp.put(w_n[0], v); } else { Vector<Double> v = new Vector<Double>(); for(int i = 0;i<index; i++) v.add(0.0); v.add(index, score); _temp.put(w_n[0], v); } }
Similar questions