C#:stanford corenlp情绪不起作用

时间:2018-08-26 05:20:46

标签: c# stanford-nlp

我正在使用下面的示例代码来尝试情感分析,但是它返回以下错误。 “标记”注释器正在工作,但是当我添加“情感”注释器时,它会向我返回错误。

我已经尝试使用其他版本的模型,例如3.8和3.9,但是问题仍然存在。我还尝试过更改从NuGet安装的版本。请帮助我解决此问题或提供任何链接,以讨论如何正确逐步安装软件包。.谢谢

using System;
using System.IO;
using java.util;
using java.io;
using edu.stanford.nlp.pipeline;
using Console = System.Console;

namespace Stanford.NLP.CoreNLP.CSharp
{
    class Program
    {
        static void Main()
        {
            // Path to the folder with models extracted from `stanford-corenlp-3.7.0-models.jar`
            var jarRoot = @"C:\Users\CarloDp\Documents\NLP\Core\stanford-corenlp-full-2016-10-31\edu\stanford\nlp\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, sentiment");
            props.setProperty("ner.useSUTime", "0");

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

SLF4J:无法加载类“ org.slf4j.impl.StaticLoggerBinder”。   SLF4J:默认为无操作(NOP)记录器实现SLF4J:   有关更多信息,请参见http://www.slf4j.org/codes.html#StaticLoggerBinder   详细信息。

     

未处理的异常:edu.stanford.nlp.io.RuntimeIOException:   java.io.IOException:无法打开   将“ edu / stanford / nlp / models / sentiment / sentiment.ser.gz”设为第a类,   文件名或URL ---> java.io.IOException:无法打开   将“ edu / stanford / nlp / models / sentiment / sentiment.ser.gz”作为类路径,   文件名或网址为   edu.stanford.nlp.io.IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(S   tring textFileOrUrl)   edu.stanford.nlp.io.IOUtils.readObjectFromURLOrClasspathOrFileSystem(Strin   g文件名)   edu.stanford.nlp.sentiment.SentimentModel.loadSerialized(字符串路径)   ---内部异常堆栈跟踪的结尾---在edu.stanford.nlp.sentiment.SentimentModel.loadSerialized(String path)   在edu.stanford.nlp.pipeline.SentimentAnnotator..ctor(字符串名称,   属性道具)   edu.stanford.nlp.pipeline.AnnotatorImplementations.sentiment(属性   pr operties,字符串名称)位于   edu.stanford.nlp.pipeline.StanfordCoreNLP.lambda $ getNamedAnnotators $ 55(Pro   perties,AnnotatorImplementations)在   edu.stanford.nlp.pipeline.StanfordCoreNLP。 <> Anon17.apply(Object,   对象)位于   edu.stanford.nlp.pipeline.StanfordCoreNLP.lambda $ null $ 69(Entry,   属性(AnnotatorImplementations)在   edu.stanford.nlp.pipeline.StanfordCoreNLP。 <> Anon38.get()在   edu.stanford.nlp.util.Lazy.3.compute()在   edu.stanford.nlp.util.Lazy.get()在   edu.stanford.nlp.pipeline.AnnotatorPool.get(String name)在   edu.stanford.nlp.pipeline.StanfordCoreNLP.construct(Properties,   布尔值,AnnotatorImplementations)位于   edu.stanford.nlp.pipeline.StanfordCoreNLP..ctor(属性道具,   布尔值forceRequirements,AnnotatorPool和annotatorPool)位于   edu.stanford.nlp.pipeline.StanfordCoreNLP..ctor(属性道具,   布尔值forceRequirements),位于   edu.stanford.nlp.pipeline.StanfordCoreNLP..ctor(Properties props)
  在Stanford.NLP.CoreNLP.CSharp.Program.Main()中   C:\ Users \ CarloDp \ Documents \ V isual Studio   2015 \ Projects \ coreNLP \ coreNLP \ Program.cs:第28行

0 个答案:

没有答案