Java Reference
In-Depth Information
This produces a more aesthetically pleasing output:
The/DT voyage/NN of/IN the/DT Abraham/NNP Lincoln/NNP was/
VBD for/IN a/DT long/JJ time/NN marked/VBN by/IN no/DT
special/JJ incident/NN ./.
But/CC one/CD circumstance/NN happened/VBD which/WDT showed/
VBD the/DT wonderful/JJ dexterity/NN of/IN Ned/NNP Land/NNP
,/, and/CC proved/VBD what/WP confidence/NN we/PRP might/MD
place/VB in/IN him/PRP ./.
The/DT 30th/JJ of/IN June/NNP ,/, the/DT frigate/NN spoke/
VBD some/DT American/JJ whalers/NNS ,/, from/IN whom/WP we/
PRP learned/VBD that/IN they/PRP knew/VBD nothing/NN about/
IN the/DT narwhal/NN ./.
But/CC one/CD of/IN them/PRP ,/, the/DT captain/NN of/IN
the/DT Monroe/NNP ,/, knowing/VBG that/IN Ned/NNP Land/NNP
had/VBD shipped/VBN on/IN board/NN the/DT Abraham/NNP
Lincoln/NNP ,/, begged/VBN for/IN his/PRP$ help/NN in/IN
chasing/VBG a/DT whale/NN they/PRP had/VBD in/IN sight/NN
./.
We can use the following code sequence to produce the same results. The word and tag
methods extract the words and their tags:
List<TaggedWord> taggedSentence =
tagger.tagSentence(sentence);
for (TaggedWord taggedWord : taggedSentence) {
System.out.print(taggedWord.word() + "/" +
taggedWord.tag() + " ");
}
System.out.println();
If we are only interested in finding specific occurrences of a given tag, we can use a se-
quence such as the following, which will list only the singular nouns ( NN ):
List<TaggedWord> taggedSentence =
tagger.tagSentence(sentence);
for (TaggedWord taggedWord : taggedSentence) {
if (taggedWord.tag().startsWith("NN")) {
System.out.print(taggedWord.word() + " ");
Search WWH ::




Custom Search