在斯坦福解析器中将树转换为SemanticGraph

时间:2015-09-24 00:25:17

标签: parsing stanford-nlp

我想在Stanford Parser中将树转换为SemanticGraph,如下所示:

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

String sentence="This is a sentence.";

List<CoreLabel> tokenizedSentence = tokenizerFactory.getTokenizer(new StringReader(sentence)).tokenize();
lpq.parse(tokenizedSentence);
Tree depTree = lpq.getBestParse();
SemanticGraph semanticGraph = ParserAnnotatorUtils.generateUncollapsedDependencies(depTree);

ParserAnnotatorUtils.generateUncollapsedDependencies(depTree)适用于2.0.4版。但它不适用于版本3.5.2。

1 个答案:

答案 0 :(得分:2)

您可以尝试以下内容:

Tree tree = ...
GrammaticalStructureFactory gsf = new UniversalEnglishGrammaticalStructureFactory();
SemanticGraph dependencyGraph = SemanticGraphFactory.generateCollapsedDependencies( gsf.newGrammaticalStructure(tree), GrammaticalStructure.Extras.NONE );