def nltk_parse_clause(sentence):
"""
Natural Language Toolkit: code_cascaded_chunker
http://www.nltk.org/book/ch07.html#code-cascaded-chunker
"""
grammar = r"""
NP: {<DT|JJ|NN.*>+} # Chunk sequences of DT, JJ, NN
PP: {<IN><NP>} # Chunk prepositions followed by NP
VP: {<VB.*><NP|PP|CLAUSE>+$} # Chunk verbs and their arguments
CLAUSE: {<NP><VP>} # Chunk NP, VP
"""
cp = nltk.RegexpParser(grammar)
#sentence = [("Mary", "NN"), ("saw", "VBD"), ("the", "DT"), ("cat", "NN"), ("sit", "VB"), ("on", "IN"), ("the", "DT"), ("mat", "NN")]
parsed_sentence = cp.parse(sentence)
#print('parsed_sentence=', parsed_sentence)
评论列表
文章目录