我想在斯坦福依赖分析器中找到一些节点,例如:
句子: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")) {
????
}
}
}
}
}发布于 2015-10-29 09:47:44
你看过Semgrex上的幻灯片了吗?
它们可在这里获得:
http://nlp.stanford.edu/software/Semgrex.ppt
有关Semgrex的更多信息:
http://nlp.stanford.edu/software/tregex.shtml
发布于 2015-10-31 14:44:48
每个类型的依赖项连接一个依赖项和一个头。对于第一个构造,您需要迭代类型化依赖项,并记录那些具有标签"nsubj“和"ccomp”以及它们头的ids的依赖项。类型化依赖项的头的id按如下方式访问:
typedDependency.dep().index()然后检查哪对nsubj和ccomp指向同一个头部。在你的例子中,一个头对应于“说”。
对于第二个构造,还可以使用类型化依赖项中的头的in来跟踪连接。
https://stackoverflow.com/questions/33408092
复制相似问题