我想在斯坦福依赖解析器中找到一些节点,例如:
句子:微软的广告说 Mac 对它的客户来说太酷了。
依赖关系:
- 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")) {
????
}
}
}
}
}
最佳答案
关于java - 从依赖解析器中提取特殊节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33408092/