[英]extracting special nodes from dependency parser
我想在斯坦福依赖解析器中找到一些节点,例如:
句子: Microsoft ad says that Macs are too cool for its customers.
依赖项:
- compound(ad-2, Microsoft-1)
- nsubj(says-3, ad-2)
- root(ROOT-0, says-3)
- mark(cool-8, that-4)
- nsubj(cool-8, Macs-5)
- cop(cool-8, are-6)
- advmod(cool-8, too-7)
- ccomp(says-3, cool-8)
- case(customers-11, for-9)
- nmod:poss(customers-11, its-10)
- nmod:for(cool-8, customers-11)
我想捕获以下结构:
p1={Node with two outgoing edges with labels "nsubj" and "ccomp"},
In its dependency tree, `says` satisfies this condition, so p1={says}
和
s1={ n1={Node that connected to the p1 by an edge with label "nsubj"},
Node connected to n1 by an edge with label "nn" or "quantmod"}
In its dependency tree s1={n1=ad, Microsoft}
我不知道如何提取这些节点,我尝试了这种结构来提取广告,但它也提取了 Mac!。 我不知道提取其他节点! 任何帮助将不胜感激。
typedDependency.reln().getShortName().equals("nsubj")
这是我的代码:
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().toString()+ " :: "+ "Node "+typedDependency.reln());
if (typedDependency.reln().getShortName().equals("nsubj")) {
????
}
}
}
}
}
每个类型的依赖连接一个依赖和一个头部。 对于第一个构造,您需要遍历类型化依赖项并记录那些具有标签“nsubj”和“ccomp”的依赖项以及它们的头部 id。 类型依赖项的头部 id 的访问方式如下:
typedDependency.dep().index()
然后只需检查哪对 nsubj 和 ccomp 指向同一个头部。 在您的示例中,一个头将对应于“说”。
对于第二个构造,您还可以使用类型化依赖项中头部的 id 来跟踪连接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.