【发布时间】:2016-05-17 12:40:25
【问题描述】:
我想使用 C# 在 OpenNLP 中训练一个新模型。我将 IKVM 用于 java 部分。这是我的火车的方法: (我在jv中引用了java.io,在op中引用了open.tools)
public string train(string lang, string entity, jv.FileInputStream taggedCorpusStream, jv.FileOutputStream modelStream)
{
//for encoding
java.nio.charset.Charset charset = java.nio.charset.Charset.forName("UTF-8");
try
{
op.util.ObjectStream lineStream = new op.util.PlainTextByLineStream(taggedCorpusStream, charset);
op.util.ObjectStream sampleStream = new op.namefind.NameSampleDataStream(lineStream);
op.namefind.TokenNameFinderModel model;
jv.OutputStream modelOut = null;
try
{
model = op.namefind.NameFinderME.train(lang, entity, sampleStream, op.util.TrainingParameters.defaultParams(), new op.namefind.TokenNameFinderFactory());
modelOut = new jv.BufferedOutputStream(modelStream);
if (model != null)
{
model.serialize(modelOut);
}
return entity + " model trained successfully";
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
finally
{
sampleStream.close();
if (modelOut != null)
{
modelOut.close();
}
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
return "Something goes wrong with training module.";
}
我在调用第 5 个参数(即 TokenNameFinderFactor)中的 NameFinder.train 时遇到 NullReference 异常。现在我的问题是它的主要用途是什么以及我可以使用哪些替代方案或方法来解决这个问题?我需要创建自己的 TokenNameFinderFactor 吗?我没有得到或理解它的文档here 关于如何实现它。 任何帮助表示赞赏。谢谢。
【问题讨论】: