Java Reference
In-Depth Information
We will use annotation2 to show the results by displaying the word and it's POS, as
shown here:
List<CoreMap> sentences =
annotation2.get(SentencesAnnotation.class);
for (CoreMap sentence : sentences) {
for (CoreLabel token :
sentence.get(TokensAnnotation.class)) {
String word = token.get(TextAnnotation.class);
String pos =
token.get(PartOfSpeechAnnotation.class);
System.out.println("Word: " + word + " POS Tag: " +
pos);
}
}
The output is as follows:
Word: The POS Tag: DT
Word: policeman POS Tag: NN
Word: chased POS Tag: VBD
Word: him POS Tag: PRP
Word: down POS Tag: RP
Word: the POS Tag: DT
Word: street POS Tag: NN
Word: . POS Tag: .
As demonstrated, this is an easy way of achieving concurrent behavior using the Stanford
pipeline.
Search WWH ::




Custom Search