c# - Stanford CoreNLP 创建 edu.stanford.nlp.time.TimeExpressionExtractorImpl 时出错

标签 c# nlp stanford-nlp

我正在尝试学习 Stanford CoreNLP 库。我在发布的示例 ( https://sergeytihon.wordpress.com/2013/10/26/stanford-corenlp-is-available-on-nuget-for-fc-devs/ ) 中使用 C#。我通过 nuget 加载了包“Stanford.NLP.CoreNLP”(它添加了 IKVM.NET)并下载了代码。解压缩 .jar 模型。我的目录是正确的。我收到以下错误:

> edu.stanford.nlp.util.ReflectionLoading.ReflectionLoadingException was
> unhandled HResult=-2146233088 Message=Error creating
> edu.stanford.nlp.time.TimeExpressionExtractorImpl
> Source=stanford-corenlp-3.5.0 StackTrace: at
> edu.stanford.nlp.util.ReflectionLoading.loadByReflection(String
> className, Object[] arguments) at
> edu.stanford.nlp.time.TimeExpressionExtractorFactory.create(String
> className, String name, Properties props) at
> edu.stanford.nlp.time.TimeExpressionExtractorFactory.createExtractor(String
> name, Properties props) at
> edu.stanford.nlp.ie.regexp.NumberSequenceClassifier..ctor(Properties
> props, Boolean useSUTime, Properties sutimeProps) at
> edu.stanford.nlp.ie.NERClassifierCombiner..ctor(Boolean
> applyNumericClassifiers, Boolean useSUTime, Properties nscProps,
> String[] loadPaths) at
> edu.stanford.nlp.pipeline.AnnotatorImplementations.ner(Properties
> properties) at edu.stanford.nlp.pipeline.AnnotatorFactories.6.create()
> at edu.stanford.nlp.pipeline.AnnotatorPool.get(String name) at
> edu.stanford.nlp.pipeline.StanfordCoreNLP.construct(Properties A_1,
> Boolean A_2, AnnotatorImplementations A_3) at
> edu.stanford.nlp.pipeline.StanfordCoreNLP..ctor(Properties props,
> Boolean enforceRequirements) at
> edu.stanford.nlp.pipeline.StanfordCoreNLP..ctor(Properties props) at
> ConsoleApplication1.Program.Main(String[] args) in
> d:\Programming_Code\VisualStudio\visual studio
> 2013\Projects\AutoWikify\ConsoleApplication1\ConsoleApplication1\Program.cs:line
> 30 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly,
> String[] args) at
> Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at
> System.Threading.ExecutionContext.RunInternal(ExecutionContext
> executionContext, ContextCallback callback, Object state, Boolean
> preserveSyncCtx) at
> System.Threading.ExecutionContext.Run(ExecutionContext
> executionContext, ContextCallback callback, Object state, Boolean
> preserveSyncCtx) at
> System.Threading.ExecutionContext.Run(ExecutionContext
> executionContext, ContextCallback callback, Object state) at
> System.Threading.ThreadHelper.ThreadStart() InnerException:
> edu.stanford.nlp.util.MetaClass.ClassCreationException
> HResult=-2146233088 Message=MetaClass couldn’t create public
> edu.stanford.nlp.time.TimeExpressionExtractorImpl(java.lang.String,java.util.Properties)
> with args [sutime, {sutime.binders=0, annotators=tokenize, ssplit,
> pos, lemma, ner, parse, dcoref}] Source=stanford-corenlp-3.5.0
> StackTrace: at
> edu.stanford.nlp.util.MetaClass.ClassFactory.createInstance(Object[]
> params) at edu.stanford.nlp.util.MetaClass.createInstance(Object[]
> objects) at
> edu.stanford.nlp.util.ReflectionLoading.loadByReflection(String
> className, Object[] arguments) InnerException:
> java.lang.reflect.InvocationTargetException HResult=-2146233088
> Message=”” Source=stanford-corenlp-3.5.0 StackTrace: at __(Object[] )
> at
> Java_sun_reflect_ReflectionFactory.FastConstructorAccessorImpl.newInstance(Object[]
> args) at java.lang.reflect.Constructor.newInstance(Object[] initargs,
> CallerID ) at
> edu.stanford.nlp.util.MetaClass.ClassFactory.createInstance(Object[]
> params) InnerException:

这是我的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using java.util;
using java.io;
using edu.stanford.nlp.pipeline;
using Console = System.Console;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
// Path to the folder with models extracted from `stanford-corenlp-3.4-models.jar`
var jarRoot = @”D:\Programming_SDKs\stanford-corenlp-full-2015-01-30\stanford-corenlp-3.5.1-models\”;

// Text for processing
var text = “Kosgi Santosh sent an email to Stanford University. He didn't get a reply.”;

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

// We should change current directory, so StanfordCoreNLP could find all the model files automatically
var curDir = Environment.CurrentDirectory;
System.IO.Directory.SetCurrentDirectory(jarRoot);
var pipeline = new StanfordCoreNLP(props);
System.IO.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();
}
}
}
}

最佳答案

添加 props.setProperty("ner.useSUTime", "false") 为我解决了这个问题。

关于c# - Stanford CoreNLP 创建 edu.stanford.nlp.time.TimeExpressionExtractorImpl 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28389564/

相关文章:

java - java -cp "*"是什么意思?

stanford-nlp - 训练 NER 模型避免内存不足错误

c# - 每次按下回车键时如何防止突出显示datagridview中的下一行?

当从一台计算机部署但从另一台计算机部署时,C# Web 应用程序会在 Azure 中导致 404 错误

python - 无法理解 Theano 如何在 RNN NLP 中进行分类

java - 根据调查构建人类可读的句子

nlp - 如何使用 spacy 或 nltk 检索句子的主要意图?

nlp - 限制斯坦福 NER 中的迭代次数

c# - 跟踪在 C# 中不起作用

c# - MVVM 基金会 : Assertion Failed Error: Invalid Property Name