6
Ich versuche, den coreNLP Sentimentanalysator in Eclipse zu implementieren. Fehler erhalten:Stanford CoreNLP sentiment
Unable to resolve "edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz"
Als Klassenpfad, Dateiname oder URL. Ich habe alle NLP-Dateien mit Maven installiert, also bin ich mir nicht sicher, warum es nach etwas anderem sucht. Hier ist der Code, bei dem ich den Fehler bekomme.
import java.util.Properties;
import edu.stanford.nlp.ling.CoreAnnotations;
import edu.stanford.nlp.neural.rnn.RNNCoreAnnotations;
import edu.stanford.nlp.pipeline.Annotation;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
import edu.stanford.nlp.sentiment.SentimentCoreAnnotations;
import edu.stanford.nlp.trees.Tree;
import edu.stanford.nlp.util.CoreMap;
public class StanfordSentiment {
StanfordCoreNLP pipeline;
public StanfordSentiment(){
Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, parse, sentiment");
pipeline = new StanfordCoreNLP(props);
}
public float calculateSentiment (String text) {
float mainSentiment = 0;
int longest = 0;
Annotation annotation = pipeline.process(text);
for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) {
Tree tree = sentence.get(SentimentCoreAnnotations.AnnotatedTree.class);
int sentiment = RNNCoreAnnotations.getPredictedClass(tree) - 2;
String partText = sentence.toString();
if (partText.length() > longest) {
mainSentiment = sentiment;
longest = partText.length();
}
}
return mainSentiment;
}
}
Stellt sich heraus, ich brauchte die Stanford-corenlp-3.3.1-models.jar auf die buildpath hinzuzufügen und es funktionierte. –