April 2019
Beginner to intermediate
386 pages
11h 20m
English
We may not always want to identify each and every tag in the text. We can narrow the tags reported using a simple if statement as shown next. In this code sequence, we list only the nouns that make up the sentence:
for (TaggedWord taggedWord : taggedSentence) { if (taggedWord.tag().startsWith("NN")) { System.out.println(taggedWord.word() + " "); }}System.out.println();
When this code is executed, you will get the following output:
mouse cat
Read now
Unlock full access