在斯坦福 coreNLP 中使用依赖解析器
我正在使用斯坦福 coreNLP ( http://nlp.stanford.edu/software/corenlp.shtml< /a> )以解析句子并提取单词之间的依赖关系。
我已成功创建依赖关系图,如提供的链接中的示例所示,但我不知道如何使用它。我可以使用 toString() 方法打印整个图表,但我遇到的问题是搜索图表中某些单词的方法(例如 getChildList)需要IndexedWord 对象作为参数。现在,很清楚为什么他们这样做,因为图表的节点是 IndexedWord 类型,但我不清楚如何创建这样的对象来搜索特定节点。
例如:我想找到我的句子中代表单词“问题”的节点的子节点。如何创建一个代表单词“问题”的 IndexWord 对象,以便我可以在图表中搜索它?
I am using the Stanford coreNLP ( http://nlp.stanford.edu/software/corenlp.shtml ) in order to parse sentences and extract dependencies between the words.
I have managed to create the dependencies graph like in the example in the supplied link, but I don't know how to work with it. I can print the entire graph using the toString()
method, but the problem I have is that the methods that search for certain words in the graph, such as getChildList
, require an IndexedWord object as a parameter. Now, it is clear why they do because the nodes of the graph are of IndexedWord type, but it's not clear to me how I create such an object in order to search for a specific node.
For example: I want to find the children of the node that represents the word "problem" in my sentence. How I create an IndexWord object that represents the word "problem" so I can search for it in the graph?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般来说,您不应该创建自己的 IndexedWord 对象。 (这些用于表示“单词标记”,即文本中的特定单词,而不是“单词类型”,因此询问单词“问题”——单词类型——并不真正有效;特别是,一个句子可以有多个该单词类型的标记。)
有几个方便的方法可以让您做您想做的事情:
第一个是一点危险,因为它只返回与模式匹配的第一个 IndexedWord,如果没有则返回 null。但这是您最直接的要求。
其他一些可以开始的方法是:
通常,这些方法会让您迭代节点。实际上,前两个 get...Node... 方法只是为您进行迭代。
In general, you shouldn't be creating your own IndexedWord objects. (These are used to represent "word tokens", i.e., particular words in a text, not "word types", and so asking for the word "problem" -- a word type -- isn't really valid; in particular, a sentence could have multiple tokens of this word type.)
There are a couple of convenience methods that let you do what you want:
The first is a little dangerous, since it just returns the first IndexedWord matching the pattern, or null if there are none. But it's most directly what you asked for.
Some other methods to start from are:
Commonly these methods leave you iterating through nodes. Really, the first two get...Node... methods just do the iteration for you.