Java Reference
In-Depth Information
System.out.print(sentence[i] + "/" + tags[i] + " ");
}
System.out.println();
The output is as follows. We have shown this output so that it will be clear how the
chunker works:
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
A
ChunkerModel
instance is created using the input stream. From this, the
Chunker-
ME
instance is created followed by the use of the
chunk
method as shown here. The
chunk
method will use the sentence's token and its tags to create an array of strings.
Each string will hold information about the token and its chunk:
ChunkerModel chunkerModel = new ChunkerModel(chunkerStream);
ChunkerME chunkerME = new ChunkerME(chunkerModel);
String result[] = chunkerME.chunk(sentence, tags);
Each token in the
results
array and its chunk tag are displayed as shown here:
for (int i = 0; i < result.length; i++) {
System.out.println("[" + sentence[i] + "] " +
result[i]);
}
The output is as follows. The token is enclosed in brackets followed by the chunk tag.
These tags are explained in the following table:
First Part
B
Beginning of a tag
I
Continuation of a tag
E
End of a tag (will not appear if tag is one word long)
Second Part