我正在尝试从其解析树中提取乔姆斯基范式(CNF) - 句子的语法产生:
(ROOT
(S
(NP (DT the) (NNS kids))
(VP (VBD opened)
(NP (DT the) (NN box))
(PP (IN on)
(NP (DT the) (NN floor))))))
我将整棵树放入一个名为 S 的字符串中,然后:
tree = Tree.fromstring(S)
tree.chomsky_normal_form()
for p in tree.productions():
print p
输出是
(1) NN -> 'box'
(2) PP -> IN NP
(3) DT -> 'the'
(4) ROOT -> S
(5) NP -> DT NN
(6) VBD -> 'opened'
(7) VP|<NP-PP> -> NP PP
(8) VP -> VBD VP|<NP-PP>
(9) NP -> DT NNS
(10) NN -> 'floor'
(11) IN -> 'on'
(12) NNS -> 'kids'
(13) S -> NP VP
但有些作品(7 号和 8 号)似乎不是 CNF!问题是什么?