Java读取文本 和词语正负性并分开极性。

读取一个文本中的词语和它的极性。并根据极性数字正负分出极性,中间头疼了很久怎么把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");
}





}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值