Java Reference
In-Depth Information
String tags[] = tagger.tag(sentence);
The words and their tags are then displayed as shown here:
for (int i = 0; i<sentence.length; i++) {
System.out.print(sentence[i] + "/" + tags[i] + " ");
}
The output is as follows. Each word is followed by its type:
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
With any sentence, there may be more than one possible assignment of tags to words. The
topKSequences method will return a set of sequences based on their probability of be-
ing correct. In the next code sequence, the topKSequences method is executed using
the sentence variable and then displayed:
Sequence topSequences[] = tagger.topKSequences(sentence);
for (inti = 0; i<topSequences.length; i++) {
System.out.println(topSequences[i]);
}
Its output follows in which the first number represents a weighted score and the tags with-
in the brackets are the sequence of tags scored:
-0.5563571615737618 [DT, NN, IN, DT, NNP, NNP, VBD, IN, DT,
JJ, NN, VBN, IN, DT, JJ, NN]
-2.9886144610050907 [DT, NN, IN, DT, NNP, NNP, VBD, IN, DT,
JJ, NN, VBN, IN, DT, JJ, .]
-3.771930515521527 [DT, NN, IN, DT, NNP, NNP, VBD, IN, DT,
JJ, NN, VBN, IN, DT, NN, NN]
Note
Ensure that you include the correct Sequence class. For this example, use import
opennlp.tools.util.Sequence;
The Sequence class has several methods, as detailed in the following table:
Search WWH ::




Custom Search