I\'m trying to get my head around the Stanford CoreNLP API. I wish to get a simple sentence to be tokenized using following code:
Properties props = new
This line retrieves sentence annotations.
List<CoreMap> sentences = document.get(SentencesAnnotation.class);
But your pipeline contains only the tokenizer, not the sentence splitter.
Change the following line:
props.put("annotators", "tokenize, ssplit"); // add sentence splitter
The code you have picked up from Stanford NLP website performs all the annotations on the text variable. In order to perform specific annotations you have to change the code accordingly.
To perform tokenization, this would be sufficient
Properties props = new Properties();
props.put("annotators", "tokenize");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
Annotation document = new Annotation(text);
pipeline.annotate(document);
for (CoreLabel token: document.get(TokensAnnotation.class)) {
String word = token.get(TextAnnotation.class);
}
This line of code would return Null if annotators doesn't include Sentence Splitter("ssplit")
document.get(SentencesAnnotation.class);
And so you were encountering NullPointerException.