斯坦福JavaNLP中如何获取父节点?

发布于 2024-08-30 02:35:28 字数 529 浏览 6 评论 0原文

假设我有这样的一句话:

(NP
      (NP (DT A) (JJ single) (NN page))
      (PP (IN in)
        (NP (DT a) (NN wiki) (NN website))))

在某个时刻我有一个对 (JJ single) 的引用,并且我想获得 NP 节点绑定 单页。如果我猜对了,NP 是节点的父节点,Apage 是它的兄弟节点,并且它没有子节点(?) 。当我尝试使用树的 .parent() 方法时,我总是得到 null。 API 说这是因为实现不知道如何确定父节点。另一个感兴趣的方法是 .ancestor(int height, Tree root),但我不知道如何获取节点的根。在这两种情况下,由于解析器知道如何缩进和分组树,它必须知道“父”树,对吧?我怎样才能得到它?谢谢

Suppose I have such chunk of a sentence:

(NP
      (NP (DT A) (JJ single) (NN page))
      (PP (IN in)
        (NP (DT a) (NN wiki) (NN website))))

At a certain moment of time I have a reference to (JJ single) and I want to get the NP node binding A single page. If I get it right, that NP is the parent of the node, A and page are its siblings and it has no children (?). When I try to use the .parent() method of a tree, I always get null. The API says that's because the implementation doesn't know how to determine the parent node. Another method of interest is .ancestor(int height, Tree root), but I don't know how to get the root of the node. In both cases, since the parser knows how to indent and group trees, it must know the "parent" tree, right? How can I get it? Thanks

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

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

发布评论

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

评论(2

断桥再见 2024-09-06 02:35:28

看起来 Tree 本身永远不会返回节点的父节点,因为它是硬编码在 Tree 源中的。同时 TreeGraphNode 覆盖该方法并且运行良好。将树更改为 TreeGraphNode 非常简单

TreeGraphNode sentence = new TreeGraph(tree).root();

It looks like the Tree itself will never return the parent of the node, since it's hardcoded in the Tree sources. Meanwhile TreeGraphNode overrides that method and works well. Changing a Tree to a TreeGraphNode is as easy as

TreeGraphNode sentence = new TreeGraph(tree).root();
睫毛溺水了 2024-09-06 02:35:28

如果保留对树根的引用,则可以使用方法 parent(Tree root) 来获取树中任何节点的父节点。假设树根称为root,JJ节点称为jjTree,则jjTree.parent(root)将返回父 NP 节点。

If you keep a reference to the root of the tree, then you can use method parent(Tree root) to get the parent of any node in the tree. Assume that the tree root is referred to as root, and that the JJ node is referred to as jjTree, then jjTree.parent(root) will return the parent NP node.

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