我是Java开发的新手.
有人可以使用Stanfords的自然语言处理Lexical Parser-开源Java代码详细阐述如何获得"语法关系"吗?
谢谢!
请参阅我的代码中第一个文件的第88行,以编程方式运行Stanford Parser
GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory();
GrammaticalStructure gs = gsf.newGrammaticalStructure(parse);
Collection tdl = gs.typedDependenciesCollapsed();
System.out.println("words: "+words);
System.out.println("POStags: "+tags);
System.out.println("stemmedWordsAndTags: "+stems);
System.out.println("typedDependencies: "+tdl);
Run Code Online (Sandbox Code Playgroud)
集合tdl是这些类型依赖项的列表.如果你在javadoc上查看TypedDependency,你会发现使用.reln()方法可以获得语法关系.
我的代码中第三个文件的第311-318行显示了如何使用该类型依赖项列表.我碰巧得到了关系的名称,但你可以得到关系本身,这将是GrammaticalRelation类.
for( Iterator<TypedDependency> iter = tdl.iterator(); iter.hasNext(); ) {
TypedDependency var = iter.next();
TreeGraphNode dep = var.dep();
TreeGraphNode gov = var.gov();
// All useful information for a node in the tree
String reln = var.reln().getShortName();
Run Code Online (Sandbox Code Playgroud)
不要心疼,我花了一两天的时间试图弄清楚如何使用解析器.我不知道文档是否有所改进,但是当我使用它时它们非常可怕.
| 归档时间: |
|
| 查看次数: |
2397 次 |
| 最近记录: |