如何从分块结果中删除部分语音标签? 我正在使用NLTK来做到这一点。目前,我只能使用以下代码迭代到块:
for i in sent_list:
tagged = nltk.pos_tag(i)
ChunkGram = r"""Chunk: {<VB.?>+<JJ.?>*<NN.?>}"""
ChunkParser = nltk.RegexpParser(ChunkGram)
chunked = ChunkParser.parse(tagged)
for subtree in chunked.subtrees(filter=lambda t: t.label() == 'Chunk'):
print(subtree)
让我说我的结果是这样的
(Chunk routing/VBG rework/NN build/NN)
(Chunk build/VBP instruction/NN schedule/NN lot/NN)
(Chunk based/VBN firm/NN plan/NN)
预期结果:
'routing','rework','build'
OR
'routing rework build'
是否可以这样做?否则请向我建议我该怎么做才能提取这些短语。
答案 0 :(得分:0)
我找到了这段代码,可以帮助我实现所需的结果。
for subtree in chunked.subtrees(filter=lambda t: t.label() == 'Verb'):
verblist.append(" ".join([a for (a,b) in subtree.leaves()]))