使用OpenNLP训练NER时,opennlp-tools-1.6.0.dll中发生'System.NullReferenceException'

时间:2017-07-16 12:03:43

标签: opennlp

我正在尝试使用OpenNLP训练NER,并且我在opennlp-tools-1.6.0中得到了System.NullReferenceException。这是代码。

public void Train()
    {
        Charset charset = Charset.forName("UTF-8");
        var lineStream = new PlainTextByLineStream(new FileInputStream(trainingDataFilePath), charset);
        var sampleStream = new NameSampleDataStream(lineStream);
        TokenNameFinderModel model = null;
        try
        {
            model = NameFinderME.train("en", "medicine", sampleStream, Collections.emptyMap());

            BufferedOutputStream modelOut = null;
            modelOut = new BufferedOutputStream(new FileOutputStream(onlpModelPath));
        }
        catch (Exception ex)
        {

            throw ex;
        }
    }

错误消息

An exception of type 'System.NullReferenceException' occurred in opennlp-tools-1.6.0.dll but was not handled in user code

栈跟踪

at opennlp.tools.ml.maxent.GISTrainer.trainModel(Int32 , DataIndexer , Prior , Int32 , Int32 )
at opennlp.tools.ml.maxent.GIS.trainModel(Int32 iterations, DataIndexer indexer, Boolean printMessagesWhileTraining, Boolean smoothing, Prior modelPrior, Int32 cutoff, Int32 threads)
at opennlp.tools.ml.maxent.GIS.doTrain(DataIndexer indexer)
at opennlp.tools.ml.maxent.GIS.<bridge>doTrain(DataIndexer x0)
at opennlp.tools.ml.AbstractEventTrainer.train(ObjectStream events)
at opennlp.tools.namefind.NameFinderME.train(String languageCode, String type, ObjectStream samples, TrainingParameters trainParams, AdaptiveFeatureGenerator generator, Map resources)
at opennlp.tools.namefind.NameFinderME.train(String languageCode, String type, ObjectStream samples, TrainingParameters trainParams, Byte[] featureGeneratorBytes, Map resources)
at opennlp.tools.namefind.NameFinderME.train(String languageCode, String type, ObjectStream samples, Map resources)
at Notes.Models.OpenNLP.Training.PersonClassifierTraining.Train() in C:\Educational\Notes\Notes\App_Data\Training\PersonClassifierTraining.cs:line 29
at Notes.Controllers.HomeController..ctor() in C:\Educational\Notes\Notes\Controllers\HomeController.cs:line 18

0 个答案:

没有答案