我有一个依赖树作为字符串。但是我转换为树并进行情绪分析。它只给我-1(不工作)。 我能够使用parse.pennPrint()成功打印树,它看起来很好。
String sentence="(TOP (S (S (NP (NNP china)) (VP (VBD experimented) (PP (IN in) (NP (DT the) (NN past))) (PP (IN with) (NP (NP (JJ various) (JJ political) (NNS systems,)) (VP (VBG including) (NP (JJ multi-party) (NN democracy,))))))) (CC but) (S (NP (PRP it)) (VP (VBD did) (RB not) (VP (VB work,) (S (NP (NN president) (NN xi) (NN jinping)) (VP (VBD said) (PP (IN during) (NP (NP (DT a) (NN visit)) (S (VP (TO to) (VP (VB europe,) (VP (VBG warning) (SBAR (IN that) (S (S (VP (VBG copying) (NP (JJ foreign) (JJ political) (CC or) (NN development) (NNS models)))) (VP (MD could) (VP (VB be) (ADJP (JJ catastrophic)))))))))))))))))))";
int sentiment_score =0;
try{
Tree parse = Tree.valueOf(sentence);
parse.pennPrint();
sentiment_score = RNNCoreAnnotations.getPredictedClass(parse);
System.out.println("input tree, score: "+sentiment_score);
}
catch(Exception e){
e.printStackTrace();
}
使用parse.pennPrint()创建的打印树:
(TOP (S (S (NP(NNP中国)) (副总裁(VBD实验) (PP(IN in) (NP(DT)(NN过去))) (PP(IN) (NP (NP(JJ各种)(JJ政治)(NNS系统,)) (VP(包括VBG) (NP(JJ多党)(NN民主,))))))) (CC但是) (S (NP(PRP)) (VP(VBD)(RB不) (副总裁(VB工作) (S (NP(NN总统)(NN xi)(NN jinping)) (副总裁(VBD说) (PP(IN期间) (NP (NP(DT a)(NN访问)) (S (VP(TO to) (副总裁(VB欧洲) (VP(VBG警告) (SBAR(IN) (S (S (副总裁(VBG复印) (NP(JJ外国)(JJ政治) (CC或) (NN开发)(NNS型号)))) (副总裁(医学博士) (副总裁(VB) (ADJP(JJ灾难性)))))))))))))))))))
答案 0 :(得分:0)
您需要运行情绪分类器 - 您的代码会尝试从树中获取[不存在的]情绪标签。最简单的方法是运行解析器并从原始文本开始:
Annotation document = new Annotation("your text");
StanfordCoreNLP pipeline = new StanfordCoreNLP(new Properties(){{
setProperty("annotators", "tokenize,ssplit,parse,sentiment")
}});
pipeline.annotate(document);