Using the POSDictionary class

A tag dictionary specifies what the valid tags for a word are. This can prevent a tag from being applied inappropriately to a word. In addition, some search algorithms execute faster, since they do not have to consider other less probable tags.

In this section, we will demonstrate how to:

  • Obtain the tag dictionary for a tagger
  • Determine what tags a word has
  • Show how to change the tags for a word
  • Add a new tag dictionary to a new tagger factory

As with the previous example, we will use a try-with-resources block to open our input streams for the POS model and then create our model and tagger factory, as shown here:

try (InputStream modelIn = new FileInputStream( 
        new File(getModelDir(), "en-pos-maxent.bin"));) { 
    POSModel model = new POSModel(modelIn); 
    POSTaggerFactory posTaggerFactory = model.getFactory(); 
    ... 
} catch (IOException e) { 
    //Handle exceptions 
}

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset