我的目标是测试此代码,以确保正确安装Stanford Core NLP。首先,我使用NuGet软件包管理器安装了StanfordCOreNLP软件包,然后下载了一个压缩文件,其中包含需要使用jar -xf
命令安装的jar文件,然后运行代码。
在(var pipeline = new StanfordCoreNLP(props);)
我收到一条错误消息:
edu.stanford.nlp.io.RuntimeIOException:加载标记器模型时出错(可能缺少模型文件)“
内部异常IOException:无法将“ edu / stanford / nlp / models / pos-tagger / english-left3words / english-left3words-distsim.tagger”作为类路径,文件名或URL打开
var jarRoot = @"D:/VisualStudioProjects/C#MachineLearningProjects/Chapter3TwiterSentiment/CoreNLPTest2/CoreNLPTest2/edu/stanford/nlp/models/pos-tagger";
var text = "We're going to test our CoreNLP instalation!!";
Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
props.setProperty("ner.useSUTime", "0");
var curDir = Environment.CurrentDirectory;
Directory.SetCurrentDirectory(jarRoot);
var pipeline = new StanfordCoreNLP(props);
Directory.SetCurrentDirectory(curDir);
var annotation = new Annotation(text);
pipeline.annotate(annotation);
using (var stream = new ByteArrayOutputStream())
{
pipeline.prettyPrint(annotation, new PrintWriter(stream));
Console.WriteLine(stream.toString());
stream.close();
}
Console.ReadKey();
请执行以下步骤:
步骤1:下载Core NLP步骤2:解压缩d:\ stanford-corenlp-full-2018-10-05步骤3:解压缩d:\ stanford-corenlp-full-2018-10-05 \ stanford-corenlp-3.9.2-models.jar步骤4:更改var jarRoot = @“ d:/stanford-corenlp-full-2018-10-05/stanford-corenlp-3.9.2-models”;步骤5:更改props.setProperty(“ ner.useSUTime”,“ 0”);到props.setProperty(“ sutime.binders”,“ 0”)