利用Stanford Parser进行观点词否定词抽取
问题:
接上一篇内容,当我们在文本中得到特征词的观点词之后,如果我们要做情感分析、极性判定(用户是在赞美还是批评),除了分析观点词本身的情感色彩之外,我们还需得到句子中是否有对该观点词的否定。如“我喜欢这个产品”->肯定;“我不喜欢这个产品”->否定。常见的否定词一般有“不”“无”“没有”等,否定词常常出现在观点词前面(不一定紧邻,有可能当中会隔着助词或副词等),因此如果光用统计的方法去判定准确率不高。
方法:
1.选择文本数据(数据源,如产品评论文本等)
2.对文本进行断句和分词
3.语法分析(Stanford Parser)
4.观点词抽取(参考前一篇内容)
5.否定词抽取。(利用stanford Parser返回的TypedDependency关系对象集合,查找当前观点词是否和其他词存在否定关系)
代码:
这里给的代码直接略过了前面几步,输入为:分词后的句子和观点词,输出:该观点词的否定词。
package textAnalysis;
import java.io.StringReader;
import java.util.Collection;
import java.util.List;
import edu.stanford.nlp.process.Tokenizer;
import edu.stanford.nlp.ling.HasWord;
import edu.stanford.nlp.ling.Label;
import edu.stanford.nlp.trees.*;
import edu.stanford.nlp.ling.HasWord;
import edu.stanford.nlp.parser.lexparser.LexicalizedParser;
import edu.stanford.nlp.process.Tokenizer;
import edu.stanford.nlp.trees.GrammaticalStructure;
import edu.stanford.nlp.trees.GrammaticalStructureFact
import edu.stanford.nlp.trees.PennTreebankLanguagePack
import edu.stanford.nlp.trees.Tree;
import edu.stanford.nlp.trees.TreebankLanguagePack;
import edu.stanford.nlp.trees.TypedDependency;
import edu.stanford.nlp.trees.international.pennchinese.ChineseTreebankLanguageP
import edu.stanford.nlp.parser.lexparser.LexicalizedParser;
import edu.stanford.nlp.parser.lexparser.Test;
public class NegWordExtra {
}
注:本程序用的是Stanford 2011年9月14号发布的jar包和词库。因为发现在12年2月3号发的那个包把否定关系“neg”归为了副词修饰形容词的“advmod”关系了,所以没法得到否定词,具体情况还在学习研究中,有知道的同学也麻烦告诉我下。谢谢。