Using the Stanford pipeline to perform tagging

We have used the Stanford pipeline in several previous examples. In this example, we will use the Stanford pipeline to extract POS tags. As with our previous Stanford examples, we create a pipeline based on a set of annotators: tokenize, ssplit, and pos.

These will tokenize, split the text into sentences, and then find the POS tags:

Properties props = new Properties(); 
props.put("annotators", "tokenize, ssplit, pos"); 
StanfordCoreNLP pipeline = new StanfordCoreNLP(props); 

To process the text, we will use the theSentence variable as input to Annotator. The pipeline's annotate method is then invoked, as shown here:

Annotation document = new Annotation(theSentence); pipeline.annotate(document); ...

Get Natural Language Processing with Java - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.