斯坦福解析器:如何提取依赖关系?

发布于 2024-10-27 16:56:51 字数 396 浏览 4 评论 0原文

我的工作包括在句子中查找查询(可以是名词+动词),然后提取对象。

示例:“编码有时是一项艰巨的工作。” 我的查询是:“编码是”

我得到的类型化依赖项是:

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 依赖项,将“coding”识别为查询并保存“work”。

也许这看起来很简单,但直到现在,我还没有找到能够提取特定类型依赖项的方法,我真的需要它来完成我的工作。

欢迎任何帮助,

My work consists in finding a query (can be noun+verb) in a sentence, then extract the object.

exemple: "coding is sometimes a tough work." My query would be: "coding is".

the typed dependencies i get are:

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)

My program should extract the nsubj dependency, identify "coding" as the query and save "work".

May be this seems simple, but until now, i didn't find a method able to extract a specific typed dependency, and I really need this to finish my work.

Any help is welcome,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心在旅行 2024-11-03 16:56:51

您可以通过以下代码查找依赖项:

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().nodeString()+ " :: "+ "Node"+typedDependency.reln());
if (typedDependency.reln().getShortName().equals("something")) {
   //your code
}

You can find dependencies by following code:

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().nodeString()+ " :: "+ "Node"+typedDependency.reln());
if (typedDependency.reln().getShortName().equals("something")) {
   //your code
}
耀眼的星火 2024-11-03 16:56:51

我认为没有办法告诉解析器提取给定单词的依赖关系。但是,您可以只运行每个句子的依赖关系列表,搜索查询词出现在 nsubj 关系中的所有实例。

另外,你如何存储句子的解析?如果(正如我从你的问题中收集到的)它在一个文本文件中,你可以使用 2 个连续的 grep,一个用于查询单词,一个用于你想要的关系,以获得相关其他单词的列表。

I don't think there's a way to tell the parser to extract the dependencies around a given word. However, you can just run through the list of dependencies for each sentence, searching for all instances in which the query word appears in an nsubj relationship.

Also, how are you storing the parses of the sentences? If (as I gather from your question) it's in a text file, you can just use 2 successive greps, one for the query word, and one for the relationship you desire, to get a list of relevant other words.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文