Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stanford CoreNLP Error creating edu.stanford.nlp.time.TimeExpressionExtractorImpl

I am trying to learn the Stanford CoreNLP library. I am using C# with the posted example (https://sergeytihon.wordpress.com/2013/10/26/stanford-corenlp-is-available-on-nuget-for-fc-devs/). I loaded the package “Stanford.NLP.CoreNLP” (it added IKVM.NET) via nuget and downloaded the code. Unzipped the .jar models. My directory is correct. I get the following error:

> 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:

Here is my code:

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();
}
}
}
}
like image 765
bulltorious Avatar asked Dec 04 '22 04:12

bulltorious


1 Answers

Adding props.setProperty("ner.useSUTime", "false") fixed this for me.

like image 188
runmarkets Avatar answered Dec 29 '22 17:12

runmarkets