C# OpenNLP.Net inputStreamFactory:尝试加载文件时出错

C# OpenNLP.Net inputStreamFactory:尝试加载文件时出错,c#,opennlp,C#,Opennlp,Hy, 我是OpenNLP.Net的新手,对基本步骤有点迷茫 我看了一些java代码,并尝试用C进行转换,但我认为我完全错了,因为我没有找到任何C代码 现在我正在尝试运行位于主目录中的代码 使用制度; 使用System.IO; 使用System.Collections.Generic; 使用System.Linq; 使用系统文本; 使用System.Threading.Tasks; 使用Newtonsoft.Json; 使用opennlp.tools.doccat; 使用opennlp.tool

Hy, 我是OpenNLP.Net的新手,对基本步骤有点迷茫

我看了一些java代码,并尝试用C进行转换,但我认为我完全错了,因为我没有找到任何C代码

现在我正在尝试运行位于主目录中的代码

使用制度; 使用System.IO; 使用System.Collections.Generic; 使用System.Linq; 使用系统文本; 使用System.Threading.Tasks; 使用Newtonsoft.Json; 使用opennlp.tools.doccat; 使用opennlp.tools.tokenize; 使用opennlp.tools.util; 公共类帐户 { 公共字符串名称{get;set;} 公共字符串电子邮件{get;set;} 公共日期时间DOB{get;set;} } 名称空间加载\u OpenNLP { 班级计划 { 静态环[]args { 帐户=新帐户 { Name=johndoe, 电子邮件=john@microsoft.com, DOB=new DateTime1980,2,20,0,0,0,DateTimeKind.Utc, }; 字符串json=JsonConvert.SerializeObjectaccount,Formatting.Indented; Console.WriteLinejson; getNLPModel; 字符串pause=Console.ReadLine; } 静态void getNLPModel//java.io.File openNLPTraining { InputStreamFactory InputStreamFactory=new MarkableFileInputStreamFactorynew java.io.field:\\text.txt; ObjectStream lineStream=新的明文ByLineStreamInputStreamFactory,UTF-8; ObjectStream sampleStream=新文档SampleStreamlineStream; } } } 它已编译,但找不到文件。。。怎么了?

您可以自己实现InputStreamFactory

下面是训练自定义NER模型的F示例,InputStreamFactory使用

在C语言中,相同的代码可能如下所示

using java.nio.charset;
using java.io;
using opennlp.tools.util;
using opennlp.tools.namefind;

namespace OpenNLP.Train
{
    class MyStreamFactory: InputStreamFactory
    {
        public Factory(string fileName) => _filename = fileName;
        private readonly string _filename;

        public InputStream createInputStream()
            => new FileInputStream(_filename);
    }
    class Program
    {
        static void Main(string[] args)
        {
            var factory = new MyStreamFactory("D:\\text.txt");
            var lineStream = new PlainTextByLineStream(factory, StandardCharsets.UTF_8);
            var sampleStream = new NameSampleDataStream(lineStream);
            var nameFinderFactory = new TokenNameFinderFactory();

            var trainingParameters = new TrainingParameters();

            var model = NameFinderME.train("en", "person", sampleStream, trainingParameters, nameFinderFactory);
        }
    }
}

我终于让剧本开始工作了。我很快就会寄出去的。显然,对可用路径可能有一些正确的限制。
using java.nio.charset;
using java.io;
using opennlp.tools.util;
using opennlp.tools.namefind;

namespace OpenNLP.Train
{
    class MyStreamFactory: InputStreamFactory
    {
        public Factory(string fileName) => _filename = fileName;
        private readonly string _filename;

        public InputStream createInputStream()
            => new FileInputStream(_filename);
    }
    class Program
    {
        static void Main(string[] args)
        {
            var factory = new MyStreamFactory("D:\\text.txt");
            var lineStream = new PlainTextByLineStream(factory, StandardCharsets.UTF_8);
            var sampleStream = new NameSampleDataStream(lineStream);
            var nameFinderFactory = new TokenNameFinderFactory();

            var trainingParameters = new TrainingParameters();

            var model = NameFinderME.train("en", "person", sampleStream, trainingParameters, nameFinderFactory);
        }
    }
}