我有一棵树:
(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)。我怎样才能做到这一点?
答案 0 :(得分:2)
一种方法是走树搜索匹配的节点:
for subtree in tree.subtrees():
if subtree.label() == 'CITY-NAME':
print subtree.leaves()
答案 1 :(得分:0)
查看函数中的_get_node方法。