我想获得斯坦福大学的Collapsed Dependency解析器。所以这是我的代码:
import edu.stanford.nlp.ling.CoreLabel;
import edu.stanford.nlp.ling.Sentence;
import edu.stanford.nlp.parser.lexparser.LexicalizedParser;
import edu.stanford.nlp.trees.*;
import java.util.List;
class Parser{
public static void main(String[] args) {
LexicalizedParser lp = LexicalizedParser.loadModel("edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz");
lp.setOptionFlags(new String[] { "-maxLength", "80","-retainTmpSubcategories" });
String[] sent = { "This", "is", "an", "easy", "sentence", "." };
List<CoreLabel> rawWords = Sentence.toCoreLabelList(sent);
Tree parse = lp.apply(rawWords);
parse.pennPrint();
System.out.println();
TreebankLanguagePack tlp = new PennTreebankLanguagePack();
GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory();
GrammaticalStructure gs = gsf.newGrammaticalStructure(parse);
List<TypedDependency> tdl = gs.typedDependenciesCCprocessed();
System.out.println(tdl);
TreePrint tp = new TreePrint("penn,typedDependenciesCollapsed");
tp.printTree(parse);
}
}
在Netbeans中运行时,以下2个代码出现以下错误。
对,
LexicalizedParser lp = LexicalizedParser.loadModel("edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz");
我得到的错误信息是:
cannot find symbol, symbol: method loadModel(java.lang.String), location: class.LexicalizedParser lp = LexicalizedParser.loadModel("edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz"); "
而
lp.setOptionFlags(new String[] { "-maxLength", "80","-retainTmpSubcategories" });
显示以下错误消息。
setOptionFlags(java.lang.String..)is not public in edu.stanford.nlp.parser.lexparser.LexicalizedParser; cannot be accessed from outside package.
我已经导入&#34; stanford-corenlp-1.3.0.jar&#34;。我该如何解决这个问题呢?
答案 0 :(得分:0)