问题描述
我有一个C#代码(尽管已复制)我在这条语句中得到错误-> varpipeline = new StanfordCoreNLP(props);(stanford-corenlp-3.7.0.dll中出现了类型为'java.lang.RuntimeException'的未处理异常
I have a c# code (though copied)im getting error at this statement ->var pipeline = new StanfordCoreNLP(props);(An unhandled exception of type 'java.lang.RuntimeException' occurred in stanford-corenlp-3.7.0.dll
其他信息:edu.stanford.nlp.io.RuntimeIOException:加载标记器模型时出错(可能缺少模型文件)
Additional information: edu.stanford.nlp.io.RuntimeIOException: Error while loading a tagger model (probably missing model file))
我的型号n核心nlp具有相同的版本斯坦福-corenlp-3.7.0-models.jarstanford-corenlp-3.7.0.jar
my models n core nlp are of same versionstanford-corenlp-3.7.0-models.jarstanford-corenlp-3.7.0.jar
任何帮助将不胜感激!
推荐答案
许多来源建议提取'stanford-corenlp-full-2017-06-09'(链接)文件夹,然后将提取的"stanford-corenlp-3.8.0-models.jar"添加到项目中.
Many sources advised to extract 'stanford-corenlp-full-2017-06-09'(link) folder and add extracted 'stanford-corenlp-3.8.0-models.jar' to the project.
我尝试了许多方法,以将其属性将操作构建为内容并将复制到输出目录设置更改为复制(如果较新)",但是找不到解决方案来对内部文件夹中的多个文件执行相同的操作.
I tried many methods, to change its properties 'Build Action to Content and the Copy to Output Directory setting to Copy if newer', but couldn't find a solution to perform the same for multiple files in inner folders.
所以,我要做的是:
提取"stanford-corenlp-3.8.0-models.jar"并将其复制到"bin/debug".我的代码如下:
Extracted 'stanford-corenlp-3.8.0-models.jar' and copied it to 'bin/debug'.And my code is as follows:
var jarRoot = @"stanford-corenlp-3.8.0-models\";
var props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, parse, sentiment");
props.setProperty("sutime.binders", "0");
var curDir = Environment.CurrentDirectory;
var modelsDirectory = curDir + "\\" + jarRoot + @"\edu\stanford\nlp\models";
Directory.SetCurrentDirectory(jarRoot);
// Loading POS Tagger
var tagger = new MaxentTagger(modelsDirectory + @"\pos-tagger\english-left3words\english-left3words-distsim.tagger");
var pipeline = new StanfordCoreNLP(props);
使用此设置和代码对我来说很好用.
Its working fine for me with this settings and code.
注意:应该进行版本更改. 同样在生产环境中,应该以不同的方式进行处理(而且我不知道该怎么做!!!).
Note: The version changes should be made. Also in production environment, it should be handled differently(and I dont know how!!!).
这篇关于斯坦福大学英语语言学院用于标记和情感分析的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!