我正在尝试在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);
}
}
答案 0 :(得分:1)
您应该看看以下教程。他们正在使用OpenNLP
版本1.7.2。这可能是最近使用的一个例子。
希望它有所帮助。