日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2024/4/17 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 斯坦福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

總結

以上是生活随笔為你收集整理的斯坦福java下载_斯坦福解析器java错误的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。