首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从依赖关系解析器中提取特定节点

从依赖关系解析器中提取特定节点
EN

Stack Overflow用户
提问于 2015-10-29 07:19:31
回答 2查看 259关注 0票数 2

我想在斯坦福依赖分析器中找到一些节点,例如:

句子:Microsoft ad says that Macs are too cool for its customers.

依赖关系:

代码语言:javascript
复制
 - 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)

我想捕捉以下构造:

代码语言:javascript
复制
p1={Node with two outgoing edges with labels "nsubj" and "ccomp"},

In its dependency tree, `says` satisfies this condition, so p1={says}

代码语言:javascript
复制
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")

这是我的代码:

代码语言:javascript
复制
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")) {

                ????

}
         }
        }
    }
    }
EN

回答 2

Stack Overflow用户

发布于 2015-10-29 09:47:44

你看过Semgrex上的幻灯片了吗?

它们可在这里获得:

http://nlp.stanford.edu/software/Semgrex.ppt

有关Semgrex的更多信息:

http://nlp.stanford.edu/software/tregex.shtml

票数 1
EN

Stack Overflow用户

发布于 2015-10-31 14:44:48

每个类型的依赖项连接一个依赖项和一个头。对于第一个构造,您需要迭代类型化依赖项,并记录那些具有标签"nsubj“和"ccomp”以及它们头的ids的依赖项。类型化依赖项的头的id按如下方式访问:

代码语言:javascript
复制
typedDependency.dep().index()

然后检查哪对nsubj和ccomp指向同一个头部。在你的例子中,一个头对应于“说”。

对于第二个构造,还可以使用类型化依赖项中的头的in来跟踪连接。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33408092

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档