Sietse
Sietse

Reputation: 250

OpenNLP categorizer Version 1.8

Im trying to build a categorizer in version 1.8 of openNLP but with the code below I keep getting a NullPointerException. What am I doing wrong?

public class test 
{

        public static void main(String[] args) throws IOException 
        {
            InputStream is = new FileInputStream("D:/training.txt");
            DoccatModel m = new DoccatModel(is);
            Tokenizer tokenizer = WhitespaceTokenizer.INSTANCE;
            String tweet = "testing sentence";
            String[] tokens = tokenizer.tokenize(tweet);
            DocumentCategorizerME myCategorizer = new DocumentCategorizerME(m);
            double[] outcomes = myCategorizer.categorize(tokens);
            String category = myCategorizer.getBestCategory(outcomes);

        }
}

Upvotes: 1

Views: 261

Answers (1)

Patrick
Patrick

Reputation: 339

You should have a look at following tutorial. They are useing OpenNLP version 1.7.2. This may be a more recent example to work with.

https://www.tutorialkart.com/opennlp/training-of-document-categorizer-using-naive-bayes-algorithm-in-opennlp/

Hope it helps.

Upvotes: 1

Related Questions