【问题标题】:OpenNLP NameFinder Training on C#C# 上的 OpenNLP NameFinder 培训
【发布时间】: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 关于如何实现它。 任何帮助表示赞赏。谢谢。

【问题讨论】:

    标签: java c# .net opennlp ikvm


    【解决方案1】:

    您发布问题已经有一段时间了。不确定您是否找到了解决方案。我有一个类似的问题(更确切地说是这里描述的问题http://permalink.gmane.org/gmane.comp.apache.opennlp.user/937)。解决方案很简单。

    将所有 IKVM dll 复制到您的项目文件夹中(调试/发布)。我只引用了一些,因此得到了错误。为此目的,很可能需要其中的一两个 dll,但我没有费心去确定具体的那些。

    现在,我可以训练新模型了。

    问候, 拉姆

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-21
      • 2018-07-05
      • 2019-01-06
      • 2018-04-06
      • 2012-08-12
      • 2019-07-10
      • 1970-01-01
      • 2012-06-15
      相关资源
      最近更新 更多