不懂你贴出来的文章,里面没看见有什么褒贬词,不知道你要怎么统计。下面给你一段代码,你按照你的要求自己改改 import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; public class JudgeGOB { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new FileReader(new File("c:" + File.separator + "wenzhang.txt"))); String string = ""; String str = ""; String[] judgeWordStrArr = new String[]{"轻薄:1", "骗散:-1", "腾飞:2", "猖獗:-2"}; int goodScore = 0; int badScore = 0; while((str = br.readLine()) != null) { string += str; } for(int i = 0 ; i < judgeWordStrArr.length ; i++) { String[] tempArr = judgeWordStrArr[i].split(":"); int score = Integer.valueOf(tempArr[1]); while((string.indexOf(tempArr[0]) ) != -1) { if(score > 0) { goodScore += score; }else { badScore += Math.abs(score); } string = string.replaceFirst(tempArr[0], ""); } } System.out.println("好评:" + goodScore); System.out.println("差评:" + badScore); } } 注:代码未测试,有可能有bug
java 情感分析 代码_求一段JAVA代码,关于文章情感分析的,
最新推荐文章于 2024-02-23 15:12:53 发布