斯坦福java下载_斯坦福解析器java错误

我正在研究NLP,我想用斯坦福解析器从文本中提取名词短语,我使用的解析器版本是3.4.1

这是我使用的示例代码

package stanfordparser;

import java.util.Collection;

import java.util.List;

import java.io.StringReader;

import edu.stanford.nlp.process.Tokenizer;

import edu.stanford.nlp.process.TokenizerFactory;

import edu.stanford.nlp.process.CoreLabelTokenFactory;

import edu.stanford.nlp.process.DocumentPreprocessor;

import edu.stanford.nlp.process.PTBTokenizer;

import edu.stanford.nlp.ling.CoreLabel;

import edu.stanford.nlp.ling.HasWord;

import edu.stanford.nlp.ling.Sentence;

import edu.stanford.nlp.trees.*;

import edu.stanford.nlp.parser.lexparser.LexicalizedParser;

class ParserDemo {

public static void main(String[] args) {

LexicalizedParser lp = LexicalizedParser.loadModel("edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz");

if (args.length > 0) {

demoDP(lp, args[0]);

} else {

demoAPI(lp);

}

}

public static void demoDP(LexicalizedParser lp, String filename) {

TreebankLanguagePack tlp = new PennTreebankLanguagePack();

GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory();

for (List sentence : new DocumentPreprocessor(filename)) {

Tree parse = lp.apply(sentence);

parse.pennPrint();

System.out.println();

GrammaticalStructure gs = gsf.newGrammaticalStructure(parse);

Collection tdl = gs.typedDependenciesCCprocessed();

System.out.println(tdl);

System.out.println();

}

}

public static void demoAPI(LexicalizedParser lp) {

// This option shows parsing a list of correctly tokenized words

String[] sent = { "This", "is", "an", "easy", "sentence", "." };

List rawWords = Sentence.toCoreLabelList(sent);

Tree parse = lp.apply(rawWords);

parse.pennPrint();

System.out.println();

// This option shows loading and using an explicit tokenizer

String sent2 = "This is another sentence.";

TokenizerFactory tokenizerFactory =

PTBTokenizer.factory(new CoreLabelTokenFactory(), "");

Tokenizer tok =

tokenizerFactory.getTokenizer(new StringReader(sent2));

List rawWords2 = tok.tokenize();

parse = lp.apply(rawWords2);

TreebankLanguagePack tlp = new PennTreebankLanguagePack();

GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory();

GrammaticalStructure gs = gsf.newGrammaticalStructure(parse);

List tdl = gs.typedDependenciesCCprocessed();

System.out.println(tdl);

System.out.println();

// You can also use a TreePrint object to print trees and dependencies

TreePrint tp = new TreePrint("penn,typedDependenciesCollapsed");

tp.printTree(parse);

}

private ParserDemo() {} // static methods only

}

但是当我运行此代码时,我得到以下错误

java.io.IOException: Unable to resolve "edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz" as either class path, filename or URL

at edu.stanford.nlp.io.IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(IOUtils.java:446)

at edu.stanford.nlp.io.IOUtils.readStreamFromString(IOUtils.java:380)

at edu.stanford.nlp.parser.lexparser.LexicalizedParser.getParserFromSerializedFile(LexicalizedParser.java:628)

at edu.stanford.nlp.parser.lexparser.LexicalizedParser.getParserFromFile(LexicalizedParser.java:423)

at edu.stanford.nlp.parser.lexparser.LexicalizedParser.loadModel(LexicalizedParser.java:182)

at edu.stanford.nlp.parser.lexparser.LexicalizedParser.loadModel(LexicalizedParser.java:161)

at stanfordparser.ParserDemo.main(ParserDemo.java:29)

我认为加载模型文件的问题,

任何人都可以帮我解决问题吗?

谢谢

更新:(1)我已经包含了cornlp模型罐

更新:(2)我正在使用Netbeans

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值