小编kel*_*raj的帖子

加快CoreNLP情绪分析

谁能想到加快我的CoreNLP情绪分析的方法(下图)?

我在服务器启动时初始化CoreNLP管道:

// Initialize the CoreNLP text processing pipeline
public static Properties props = new Properties();
public static StanfordCoreNLP pipeline;

// Set text processing pipeline's annotators
props.setProperty("annotators", "tokenize, ssplit, pos, parse, sentiment");
// Use Shift-Reduce Constituency Parsing (O(n),
// http://nlp.stanford.edu/software/srparser.shtml) vs CoreNLP's default
// Probabilistic Context-Free Grammar Parsing (O(n^3))
props.setProperty("parse.model", "edu/stanford/nlp/models/srparser/englishSR.ser.gz");
pipeline = new StanfordCoreNLP(props);
Run Code Online (Sandbox Code Playgroud)

然后我从我的控制器调用管道:

String text = 'A sample string.'
Annotation annotation = pipeline.process(text);
List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
for (CoreMap sentence : sentences) {
    Tree tree = sentence.get(SentimentCoreAnnotations.SentimentAnnotatedTree.class); …
Run Code Online (Sandbox Code Playgroud)

java optimization performance stanford-nlp sentiment-analysis

6
推荐指数
1
解决办法
526
查看次数