在 C# 中使用 CoreNLP 时出现 SLF4J 错误



我想在我的Unity3D项目中加入Stanford CoreNLP。我从Nuget包含了CoreNLP,并从CoreNLP下载了NLP模型。然后我将 NLP 模型文件夹复制到project -> bin -> Debug文件夹中。

代码如下所示:

var jarRoot = @"stanford-corenlp-3.9.1-models";
const string text = "Kosgi Santosh sent an email to Stanford University. He didn't get a reply.";
var props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
props.setProperty("sutime.binders", "0");
var curDir = Environment.CurrentDirectory;
Directory.SetCurrentDirectory(jarRoot);
var pipeline = new StanfordCoreNLP(props);
Directory.SetCurrentDirectory(curDir);
// Annotation
var annotation = new Annotation(text);
pipeline.annotate(annotation);
var sentences = annotation.get(typeof(CoreAnnotations.SentencesAnnotation));
if (sentences == null)
{
return;
}
foreach (Annotation sentence in sentences as ArrayList)
{
System.Console.WriteLine(sentence);
}

运行后,我只得到了一些错误信息

SLF4J:无法加载类"org.slf4j.impl.StaticLoggerBinder"。

SLF4J:默认为无操作 (NOP( 记录器实现

SLF4J:请参阅 http://www.slf4j.org/codes.html#StaticLoggerBinder 更多细节。

我搜索了SLF4J网站,但该解决方案仅适用于Java项目。我应该如何在我的 C# 项目中解决这个问题?

首先,转到Visual Studio(我有VS 2017(。然后转到"工具"菜单并选择"NuGet 包管理器->包管理器控制台"。将出现程序包管理器控制台。键入以下命令:安装包slf4j-NetCommonLogging -Version 1.7.5.4,然后按回车键。VS将为您的项目安装slf4j-NetCommonLogging dll文件,它将正常运行,没有任何错误或警告。享受。

最新更新