我的工作是在一个句子中找到一个查询(可以是noun+verb),然后提取对象。
例如:"coding is sometimes a tough work."我的查询应该是:"coding is"。
我得到的类型化依赖项是:
nsubj(work-6, coding-1)
cop(work-6, is-2)
advmod(work-6, sometimes-3)
det(work-6, a-4)
amod(work-6, tough-5)我的程序应该提取nsubj依赖项,将"coding"标识为查询并保存"work"。
这看起来可能很简单,但直到现在,我还没有找到能够提取特定类型依赖项的方法,我真的需要它来完成我的工作。
欢迎任何帮助,
发布于 2013-02-07 04:16:51
您可以通过以下代码查找依赖项:
Tree tree = sentence.get(TreeAnnotation.class);
// Get dependency tree
TreebankLanguagePack tlp = new PennTreebankLanguagePack();
GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory();
GrammaticalStructure gs = gsf.newGrammaticalStructure(tree);
Collection<TypedDependency> td = gs.typedDependenciesCollapsed();
System.out.println(td);
Object[] list = td.toArray();
System.out.println(list.length);
TypedDependency typedDependency;
for (Object object : list) {
typedDependency = (TypedDependency) object;
System.out.println("Depdency Name"typedDependency.dep().nodeString()+ " :: "+ "Node"+typedDependency.reln());
if (typedDependency.reln().getShortName().equals("something")) {
//your code
}发布于 2012-02-14 05:58:51
我不认为有一种方法可以告诉解析器提取给定单词周围的依存关系。但是,您可以只遍历每个句子的依存关系列表,搜索查询词出现在nsubj关系中的所有实例。
另外,你是如何存储句子的解析的?如果(我从你的问题中了解到)它在一个文本文件中,你可以只使用两个连续的grep,一个用于查询单词,另一个用于所需的关系,以获得相关的其他单词的列表。
https://stackoverflow.com/questions/5449098
复制相似问题