将Stanford-NLP集成到ASP.Net Core C#应用程序中,收到以下错误消息:System.TypeInitializationException HResult = 0x80131534 Message ='edu.stanford.nlp.util.Timing'的类型初始值设定项引发异常。 Source = stanford-corenlp-3.9.1 StackTrace:位于edu.stanford的edu.stanford.nlp.pipeline.StanfordCoreNLP.construct(Properties,Boolean,AnnotatorImplementations)的edu.stanford.nlp.util.Timing..ctor()。 nlp.pipeline.StanfordCoreNLP..ctor(属性props,Boolean enforceRequirements,AnnotatorPool annotatorPool)位于edu.stanford.nlp.pipeline.StanfordCoreNLP的edu.stanford.nlp.pipeline.StanfordCoreNLP..ctor(Properties props,Boolean enforceRequirements)。 ctor(属性道具)位于G:\ VSProjects \ 3x32018 \ 3x32018 \ Utility \ SearchNLP.cs中的_3x32018.Utility.SearchNLP.ParseNLG(String sent2):第52行
内部异常1:TypeInitializationException:'java.util.ResourceBundle'的类型初始值设定项引发异常。
内部异常2:MissingMethodException:找不到方法:'Void System.IO.FileStream..ctor(System.String,System.IO.FileMode,System.Security.AccessControl.FileSystemRights,System.IO.FileShare,Int32,System.IO .FileOptions)”。
这是我的简单代码::
using edu.stanford.nlp.pipeline;
using java.util;
using System.Collections.Generic;
using System.Globalization;
using System.Threading;
namespace _3x32018.Utility
{
public class SearchNLP
{
public HashSet<string> ParseNLG(string sent2)
{
CultureInfo ci = new CultureInfo("en-US");
Thread.CurrentThread.CurrentCulture = ci;
Thread.CurrentThread.CurrentUICulture = ci;
Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, lemma,
ner, parse, dcoref");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
Annotation document = new Annotation(sent2);
pipeline.annotate(document);
}
}
}
任何想法为什么失败?
-Lester
您使用的是ASP.NET Core,它没有corenlp.net正在使用的FileStream构造函数(确切地说就是IKVM)。查看此页面,https://docs.microsoft.com/en-us/dotnet/api/system.io.filestream.-ctor?view=netcore-2.0。