谁能告诉我如何从以下输出中仅提取名词:
我已经使用以下程序基于给定的语法对字符串“给我电影评论”进行了标记化和解析: –
sent=nltk.word_tokenize(msg)
parser=nltk.ChartParser(grammar)
trees=parser.nbest_parse(sent)
for tree in trees:
print tree
tokens=find_all_NP(tree)
tokens1=nltk.word_tokenize(tokens[0])
print tokens1
并获得以下输出:
>>>
(S
(VP (V Give) (Det me))
(NP (Det the) (N review) (PP (P of) (N movie))))
(S
(VP (V Give) (Det me))
(NP (Det the) (N review) (NP (PP (P of) (N movie)))))
['the', 'review', 'of', 'movie']
>>>
现在我只想获得名词.我怎么做?