我的工作在于在句子中查找查询(可以是名词动词),然后提取对象.
例如:“编码有时是一项艰巨的工作.”我的疑问是:“编码是”.
我得到的类型依赖是:
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依赖项,将“编码”识别为查询并保存“工作”.
可能这看起来很简单,但直到现在,我还没有找到能够提取特定类型依赖关系的方法,我真的需要这个来完成我的工作.
欢迎任何帮助,
您可以通过以下代码找到依赖项:
原文链接:https://www.f2er.com/javaschema/281560.htmlTree 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 }