Stanford nlp 使用stanford语法分析器解析汉语

Stanford nlp 使用stanford语法分析器解析汉语,stanford-nlp,Stanford Nlp,这是我的代码,大部分来自演示。程序运行得很好,但结果却大错特错。它没有把字弄乱。 多谢各位 public static void main(String[] args) { LexicalizedParser lp = LexicalizedParser.loadModel("edu/stanford/nlp/models/lexparser/xinhuaFactored.ser.gz"); demoAPI(lp); } public static void demoAPI(Lex

这是我的代码,大部分来自演示。程序运行得很好,但结果却大错特错。它没有把字弄乱。 多谢各位

public static void main(String[] args) {
 LexicalizedParser lp = LexicalizedParser.loadModel("edu/stanford/nlp/models/lexparser/xinhuaFactored.ser.gz");

  demoAPI(lp);

}


public static void demoAPI(LexicalizedParser lp) {


// This option shows loading and using an explicit tokenizer
String sent2 = "我爱你";
TokenizerFactory<CoreLabel> tokenizerFactory =
    PTBTokenizer.factory(new CoreLabelTokenFactory(), "");
Tokenizer<CoreLabel> tok =
    tokenizerFactory.getTokenizer(new StringReader(sent2));
List<CoreLabel> rawWords2 = tok.tokenize();

Tree parse = lp.apply(rawWords2);

TreebankLanguagePack tlp = new PennTreebankLanguagePack();
GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory();
GrammaticalStructure gs = gsf.newGrammaticalStructure(parse);
List<TypedDependency> 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);
}
publicstaticvoidmain(字符串[]args){
LexicalizedParser lp=LexicalizedParser.loadModel(“edu/stanford/nlp/models/lexparser/xinhuaFactored.ser.gz”);
德莫阿皮(有限合伙);
}
公共静态void demoAPI(LexicalizedParser lp){
//此选项显示加载和使用显式标记器
字符串sent2=”我爱你";
TokenizerFactory TokenizerFactory=
PTBTokenizer.factory(新的CoreLabelTokenFactory(),“”);
标记器=
getTokenizer(新的StringReader(sent2));
List rawWords2=tok.tokenize();
树解析=lp.apply(rawWords2);
TreebankLanguagePack tlp=新的PennTreebankLanguagePack();
语法结构工厂gsf=tlp.grammaticStructureFactory();
语法结构gs=gsf.newgrammaticstructure(parse);
List tdl=gs.typedDependenciescpProcessed();
系统输出打印LN(tdl);
System.out.println();
//还可以使用TreePrint对象打印树和依赖项
TreePrint tp=新的TreePrint(“penn,TypedPendenciesCollapsed”);
打印树(parse);
}

您确定要对单词进行分段吗?例如,请尝试使用“我 爱 你.我相信从命令行解析器会自动分段,但是我不确定它在Java中做了什么