简体   繁体   English

在C#中运行Stanford.NLP.CoreNLP 3.8示例时发生TypeInitializationException

[英]TypeInitializationException when running Stanford.NLP.CoreNLP 3.8 example in c#

I realize this issue was observed and resolved with the inclusion of the props.setProperty("ner.useSUTime", "0"); 我意识到这个问题已通过包含props.setProperty(“ ner.useSUTime”,“ 0”);得以解决。 However, the error persists. 但是,错误仍然存​​在。 I added corenlp 3.8 via nuget, I am using c# visual studio 2017, in a NetStandard2.0 configuration. 我通过nuget添加了corenlp 3.8,我在NetStandard2.0配置中使用c#visual studio 2017。

My code: ` 我的代码:

public Dictionary<int, List<Word>> GetPOSFromStandforNLP(string sent)
        {
            var pos = new Dictionary<int, List<Word>>();
            var jarRoot = @"../vendor/stanford-corenlp-3.8.0-models";

            // Annotation pipeline configuration
            var props = new Properties();
            // Annotation pipeline configuration
            var props = new Properties();
            props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
            props.setProperty("ner.useSUTime", "0");

            try
            {
                CultureInfo ci = new CultureInfo("en-US");
                Thread.CurrentThread.CurrentCulture = ci;
                Thread.CurrentThread.CurrentUICulture = ci;

                var curDir = Environment.CurrentDirectory;
                Directory.SetCurrentDirectory(jarRoot);   
                var pipeline = new StanfordCoreNLP(props);
                Directory.SetCurrentDirectory(curDir);
                // Annotation
                var annotation = new Annotation(text);
                pipeline.annotate(annotation);
                // Result - Pretty Print
                using (var stream = new ByteArrayOutputStream())
                {
                    pipeline.prettyPrint(annotation, new PrintWriter(stream));
                    Console.WriteLine(stream.toString());
                    stream.close();
                }

The error:

System.TypeInitializationException: The type initializer for 'edu.stanford.nlp.pipeline.AnnotationPipeline' threw an exception. ---> System.TypeInitializationException: The type initializer for 'edu.stanford.nlp.util.logging.Redwood' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.     at IKVM.Internal.AssemblyClassLoader.LoadCustomClassLoaderRedirects()    at IKVM.Internal.AssemblyClassLoader.GetCustomClassLoaderType()    at IKVM.Internal.AssemblyClassLoader.GetJavaClassLoader()    at java.lang.Class.getClassLoader(CallerID )    at java.lang.Class.desiredAssertionStatus()    at edu.stanford.nlp.util.logging.Redwood..cctor(

Stanford.NLP.NET is an IKVM project. Stanford.NLP.NETIKVM项目。 IKVM is a now defunkt Java virtual machine implementation in .NET. IKVM是.NET中现已失效的 Java虚拟机实现。 It is does not support .NET Standard 2.0, only .NET Framework and Mono. 它不支持.NET Standard 2.0,仅支持.NET Framework和Mono。

So your options are: 因此,您的选择是:

  1. Target .NET Framework or Mono 目标.NET Framework或Mono
  2. Port the Stanford.NLP.CoreNLP Java project to .NET Standard Stanford.NLP.CoreNLP Java项目移植到.NET Standard
  3. Port the IKVM.NET project to .NET Standard (and preferably open source it so others who need a quick path to running Java code in .NET Standard can do so) 将IKVM.NET项目移植到.NET Standard(最好将其开源),以便需要快速路径在.NET Standard中运行Java代码的其他人也可以这样做。
  4. Call Java using Pinvoke and a plain C-wrapper as a go-between that uses JNI to load the JVM and to expose functions that call into Java using JNI, as described here 使用Pinvoke和普通的C-包装器作为Java之间的中介,调用Java,以使用JNI加载JVM并使用JNI公开调用Java的函数,如此处所述
  5. Implement your application in Java or another language that Stanford.NLP.CoreNLP supports 用Java或Stanford.NLP.CoreNLP支持的另一种语言来实现您的应用程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM