Java Reference
In-Depth Information
try {
MaxentTagger tagger = new MaxentTagger(getModelDir() +
"//wsj-0-18-bidirectional-distsim.tagger");
List<List<HasWord>> sentences =
MaxentTagger.tokenizeText(
new BufferedReader(new
FileReader("sentences.txt")));
} catch (FileNotFoundException ex) {
// Handle exceptions
}
The sentences.txt file contains the first four sentences of Chapter 5 , At A Venture of
the topic Twenty Thousands Leagues Under the Sea :
The voyage of the Abraham Lincoln was for a long time
marked by no special incident.
But one circumstance happened which showed the wonderful
dexterity of Ned Land, and proved what confidence we might
place in him.
The 30th of June, the frigate spoke some American whalers,
from whom we learned that they knew nothing about the
narwhal.
But one of them, the captain of the Monroe, knowing that
Ned Land had shipped on board the Abraham Lincoln, begged
for his help in chasing a whale they had in sight.
A loop is added to process each sentence of the sentences list. The tagSentence
method returns a List instance of TaggedWord objects as shown next. The
TaggedWord class implements the HasWord interface and adds a tag method that re-
turns the tag associated with the word. As shown here, the toString method is used to
display each sentence:
List<TaggedWord> taggedSentence =
tagger.tagSentence(sentence);
for (List<HasWord> sentence : sentences) {
List<TaggedWord> taggedSentence=
tagger.tagSentence(sentence);
Search WWH ::




Custom Search