如何通过 nltk python 中的标签获取树中的节点?
How to get a node in a tree by its label in nltk python?
我有一棵树:
(S
(WH-QUERY Which)
(FLIGHT-NP
(FLIGHT-CNP
(FLIGHT-CNP (FLIGHT-N flight))
(FLIGHT-DEST to (CITY-NP (CITY-NAME Hue) (CITY-N city)))))
(FLIGHT-VP
(FLIGHT-V arrives)
(FLIGHT-TIME (P-TIME at) (TIME-MOD 20:00HR))))
我想通过 nltk 中的标签获取特定节点。例如,我有标签"CITY-NAME",我想获取节点(CITY-NAM Hue)。我怎样才能做到这一点?
查看函数中的_get_node方法
一种方法是遍历树搜索匹配的节点:
for subtree in tree.subtrees():
if subtree.label() == 'CITY-NAME':
print subtree.leaves()
我有一棵树:
(S
(WH-QUERY Which)
(FLIGHT-NP
(FLIGHT-CNP
(FLIGHT-CNP (FLIGHT-N flight))
(FLIGHT-DEST to (CITY-NP (CITY-NAME Hue) (CITY-N city)))))
(FLIGHT-VP
(FLIGHT-V arrives)
(FLIGHT-TIME (P-TIME at) (TIME-MOD 20:00HR))))
我想通过 nltk 中的标签获取特定节点。例如,我有标签"CITY-NAME",我想获取节点(CITY-NAM Hue)。我怎样才能做到这一点?
查看函数中的_get_node方法
一种方法是遍历树搜索匹配的节点:
for subtree in tree.subtrees():
if subtree.label() == 'CITY-NAME':
print subtree.leaves()