首页 > 解决方案 > 在 C# 中使用 CoreNLP 时出现 SLF4J 错误

问题描述

我想将斯坦福 CoreNLP 包含在我的 Unity3D 项目中。我从 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# 项目中解决这个问题?

标签: c#stanford-nlpslf4j

解决方案


首先,转到 Visual Studio(我有 VS 2017)。然后转到“工具”菜单并选择“NuGet 包管理器”->“包管理器控制台”。包管理器控制台将出现。键入此命令:Install-Package slf4j-NetCommonLogging -Version 1.7.5.4 并按 Enter 键。VS 将为您的项目安装 slf4j-NetCommonLogging dll 文件,它将正常运行而不会出现任何错误或警告。享受。


推荐阅读