Python和NLTK并分析句子语法?

时间:2019-02-16 20:18:13

标签: nltk

我有这段代码,应该根据定义的语法显示句子的句法结构。但是,它返回一个空的[]。我想念什么或做错什么了?

sent = [['i', 'do', 'not', 'notice', 'my', 'animal', 'be', 'ugly', 'than', 'yours', '!'], ['i', 'be', 'sorry', '...']]

grammar = nltk.CFG.fromstring("""
CLAUS -> SN-CHUNK VBD ATTRIB ST-BRK
SV -> SN-CHUNK VB-DO VB SV EX-BRK |SN-CHUNK VBD N-CHUNK
SP-CHUNK -> IN SN-CHUNK
SN-CHUNK -> PRPS N-CHUNK |PRPS | PRP
N-CHUNK -> JJR SP-CHUNK | NNS 
VB-DO -> VBD ADV
EX-BRK -> FAT
ST-BRK -> FS
ADV -> RB
ATTRIB -> JJ
JJR -> 'ugly'
IN -> 'than'
PRPS -> 'yours' | 'my'
VBD -> 'do' | 'be'
VB -> 'notice'
PRP -> 'i'
RB -> 'not'
NNS -> 'animal'
FAT -> '!'
FS -> '...'
JJ -> 'sorry'
""")

parser = nltk.ChartParser(grammar)
for sentences in Lemmas2:
     for tree in parser.parse(sentences):
        print(tree,'\n')
        tree.draw()

0 个答案:

没有答案
相关问题