读取一个文本中的词语和它的极性。并根据极性数字正负分出极性,中间头疼了很久怎么把String转为double,一个很简单的方法搞定了。。。。。大神就是大神,佩服佩服。
菜鸟留存,以后备用。
public class TrainSentiment {
//读取文件的流public static void main(String[] args) throws IOException{
try {
String pathname = "D:/公司工作/后台词库/customs_NLP_sentiment_score.txt";
File file = new File(pathname);
InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(file),"utf-8");
BufferedReader br = new BufferedReader(inputStreamReader);
String line = " ";
while((line = br.readLine())!=null){
String[] str=line.split("\\s+");
if (Double.valueOf(str[1])>0.0&&str[0].length()>0) {
System.out.println("pos");
}else {
System.out.println("neg");
}
System.out.println("["+str[0]+"="+str[1]+"]");
}
//System.out.println(dnumber);
br.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("Filepath is not found");
}
}