That is the idea of the POS Tagger Factory. You can change the context generator using the factory.
Take a look at this JUnit. Method testPOSTaggerWithCustomFactory https://github.com/apache/opennlp/blob/master/opennlp-tools/src/test/java/opennlp/tools/postag/POSTaggerFactoryTest.java Give it a try and come back if you need help. William 2017-01-09 9:28 GMT-02:00 Vincent <vincent.s...@openindex.io>: > Hi William, > > Thanks for the reply. I think I haven't been exactly clear in phrasing my > question. > > I'm using OpenNLP as a Maven depencency for my own project, which is more > like shell around OpenNLP, only calling the functions I need to train/apply > the POSTagger. I don't have the OpenNLP code in my project, I just wanted > to inherit from the code to customize/override the feature selection. But > this is problematic because for example, POSModel is a final class and > can't be extended. > > I hope that this makes sense. > > Cheers, > > Vincent > > > On 05-01-17 17:46, William Colen wrote: > >> Hi Vincent, >> >> OpenNLP will take care of serializing the information necessary to call >> your custom factory instead of the default one. >> Just to make sure of that, change your custom POSContextGenerator by >> adding >> a small log message. You should see the message both during training and >> runtime. >> >> To train, use the methods that you can pass in your custom factory. >> >> -- William >> >> 2017-01-05 13:53 GMT-02:00 Vincent <vincent.s...@openindex.io>: >> >> Hi all, >>> >>> I would like to be able to have a bit more influence on the features used >>> for POS-tagging. I suppose that feature selection happens in the >>> POSContextGenerator. However, I can't seem to be able to change the type >>> of >>> POSContextGenerator that is being called from POSTaggerFactory: the >>> getPOSContextGenerator() function always returns the >>> DefaultPOSContextGenerator. >>> >>> Looking for a way to make a custom POSContextGenerator work, I made a >>> custom POSTaggerFactory too, that inherits from the regular >>> POSTaggerFactory, but returns my own POSContextGenerator. However, for >>> example, a class like POSModel (in turn used by POSTaggerME) is final, >>> and >>> can't be inherited from to use my custom POSTaggerFactory. >>> >>> It seems I just need to copy the entire code into my own project, or is >>> there a better way to make this work? >>> >>> Thanks in advance! >>> >>> Cheers, >>> >>> Vincent >>> >>> >>> >