gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 00:01:23 30 4
gpt4 key购买 nike

我正在尝试学习 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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com