赞
踩
import com.hankcs.hanlp.HanLP; import com.hankcs.hanlp.seg.common.Term; import java.util.*; public class NaiveBayesSentimentAnalysis { private Map<String, Map<String, Double>> conditionalProbabilities; // 条件概率 private Map<String, Double> priorProbabilities; // 先验概率 private Set<String> vocabulary; // 词汇表 public NaiveBayesSentimentAnalysis(Map<String, Map<String, Integer>> wordCountsPerLabel, Map<String, Integer> labelCounts, Set<String> vocabulary) { conditionalProbabilities = new HashMap<>(); priorProbabilities = new HashMap<>(); this.vocabulary = vocabulary; train(wordCountsPerLabel, labelCounts); } // 使用训练好的模型进行情感判定 public String predict(String document) { List<Term> segmentedDocument = HanLP.segment(document); Map<String, Double> logPro
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。