加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 使用nugetpackages加载标记器模型时出现无法恢复的错误

发布时间:2020-12-15 22:19:27 所属栏目:百科 来源:网络整理
导读:我一直在尝试使用stanford-corenlp-3.5.2 nugetpackage创建并运行一个简单的程序. 但是在查找了一些初学者代码后,我发现了以下代码props.setProperty(“annotators”,“tokenize,ssplit,pos,lemma,ner,parse,dcoref”);(链接到代码示例:http://sergey-tihon
我一直在尝试使用stanford-corenlp-3.5.2 nugetpackage创建并运行一个简单的程序.

但是在查找了一些初学者代码后,我发现了以下代码props.setProperty(“annotators”,“tokenize,ssplit,pos,lemma,ner,parse,dcoref”);(链接到代码示例:http://sergey-tihon.github.io/Stanford.NLP.NET/StanfordCoreNLP.html)

但是,每当控制台应用程序加载pos时,它就会触发运行时错误,指出它无法加载标记器.

我想知道我是否缺少任何nugetpackages或如果有额外的设置我必须通过. (注意.任何时候我试图添加说postagger nuget包然后得到一个错误,说两个dlls引用类Annotation.)

我发现,如果我删除一些属性,应用程序将正确运行,所以新行看起来像这样
“props.setProperty(”annotators“,”tokenize,ssplit“);

任何有助于超越运行时错误以帮助我继续进一步分析示例文本的帮助将不胜感激.谢谢.

附图片供参考.(显然我需要更多的声誉才能发布图片但我什么时候可以立即发布:)编辑我现在添加了图片:)

enter image description here

行异常的堆栈跟踪如下:

at edu.stanford.nlp.pipeline.AnnotatorFactories.4.create()
at edu.stanford.nlp.pipeline.AnnotatorPool.get(String name)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.construct(Properties,Boolean,AnnotatorImplementations )
at edu.stanford.nlp.pipeline.StanfordCoreNLP..ctor(Properties props,Boolean enforceRequirements)
at edu.stanford.nlp.pipeline.StanfordCoreNLP..ctor(Properties props)
at ConApplicationSabrinaNLP.TestClass.donlp() in c:UsersJustinDocumentsVisual Studio 2013ProjectsConApplicationSabrinaNLPConApplicationSabrinaNLPTestClass.cs:line 28
at ConApplicationSabrinaNLP.Program.Main(String[] args) in c:UsersJustinDocumentsVisual Studio 2013ProjectsConApplicationSabrinaNLPConApplicationSabrinaNLPProgram.cs:line 20
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly,String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile,Evidence assemblySecurity,String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext,ContextCallback callback,Object state,Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext,Object state)
at System.Threading.ThreadHelper.ThreadStart()

解决方法

问题是您没有下载模型. Nuget包本身不起作用.
你必须在这里下载最新的版本 POS-Tagger

完成后,将其放入项目目录中.然后将代码指向它.在“3.6.0 2015-12-09更新的兼容性”版本中,标记器具有不同的名称,例如“english-bidirectional-distsim.tagger”.
确保将代码指向正确的文件夹和文件,它将起作用.

以下是我的Windows窗体项目中的一个工作示例.

using java.io;
using java.util;
using edu.stanford.nlp.ling;
using edu.stanford.nlp.tagger.maxent;
using Console = System.Console;
using System.IO;
using System.Windows.Forms;

namespace Stanford.NLP.POSTagger.CSharp
{
    class PosTagger

    {
        // get the base folder for the project
        public static string GetAppFolder()
        {
            return Path.GetDirectoryName(Application.ExecutablePath).Replace(@"*your project directory here*binDebug",string.Empty);
        }

        public void testTagger()
        {
            var jarRoot = Path.Combine(GetAppFolder(),@"packagesstanford-postagger-2015-12-09");
            Console.WriteLine(jarRoot.ToString());
            var modelsDirectory = jarRoot + @"models";

            // Loading POS Tagger
            var tagger = new MaxentTagger(modelsDirectory + @"english-bidirectional-distsim.tagger");

            // Text for tagging
            var text = "A Part-Of-Speech Tagger (POS Tagger) is a piece of software that reads text"
                       + "in some language and assigns parts of speech to each word (and other token),"
                       + " such as noun,verb,adjective,etc.,although generally computational "
                       + "applications use more fine-grained POS tags like 'noun-plural'.";

            var sentences = MaxentTagger.tokenizeText(new java.io.StringReader(text)).toArray();
            foreach (ArrayList sentence in sentences)
            {
                var taggedSentence = tagger.tagSentence(sentence);
                Console.WriteLine(Sentence.listToString(taggedSentence,false));
            }
        }
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读