gpt4 book ai didi

c# - 使用 nugetpackages 加载标记器模型时出现不可恢复的错误

转载 作者:行者123 更新时间:2023-11-30 12:42:55 28 4
gpt4 key购买 nike

我一直在尝试使用 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 包时,我都会收到一条错误消息,指出类注释在两个 dll 中被引用。)

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

如能帮助我克服运行时错误,以便我可以继续进一步分析示例文本,我们将不胜感激。谢谢。

附上图片以供引用。(显然我需要更多的声誉才能发布图片,但如果可以的话我会立即这样做:)编辑我现在已经添加了图片:)

行异常的堆栈跟踪如下:

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:\Users\Justin\Documents\Visual Studio 2013\Projects\ConApplicationSabrinaNLP\ConApplicationSabrinaNLP\TestClass.cs:line 28
at ConApplicationSabrinaNLP.Program.Main(String[] args) in c:\Users\Justin\Documents\Visual Studio 2013\Projects\ConApplicationSabrinaNLP\ConApplicationSabrinaNLP\Program.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, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, 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*\bin\Debug", string.Empty);
}

public void testTagger()
{
var jarRoot = Path.Combine(GetAppFolder(), @"packages\stanford-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));
}
}
}
}

关于c# - 使用 nugetpackages 加载标记器模型时出现不可恢复的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32300233/

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