OpenNLP分类程序版本1.8

时间:2017-10-18 06:57:24

标签: java text-mining opennlp categorization

我正在尝试在openNLP的1.8版本中构建分类程序但是使用下面的代码我一直得到NullPointerException。我做错了什么?

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);

        }
}

1 个答案:

答案 0 :(得分:1)

您应该看看以下教程。他们正在使用OpenNLP版本1.7.2。这可能是最近使用的一个例子。

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

希望它有所帮助。