OpenNLP分类程序版本1.8
问题描述:
我试图在openNLP 1.8版中构建分类程序,但代码如下,我不断收到NullPointerException
。我究竟做错了什么?OpenNLP分类程序版本1.8
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);
}
}
答
你应该看看下面的教程。他们正在使用OpenNLP
版本1.7.2。这可能是一个更近期的例子。
希望它能帮助。