How to extract chunks from BIO chunked sentences? - python
问题 Give an input sentence, that has BIO chunk tags: [('What', 'B-NP'), ('is', 'B-VP'), ('the', 'B-NP'), ('airspeed', 'I-NP'), ('of', 'B-PP'), ('an', 'B-NP'), ('unladen', 'I-NP'), ('swallow', 'I-NP'), ('?', 'O')] I would need to extract the relevant phrases out, e.g. if I want to extract 'NP' , I would need to extract the fragments of tuples that contains B-NP and I-NP . [out]: [('What', '0'), ('the airspeed', '2-3'), ('an unladen swallow', '5-6-7')] (Note: the numbers in the extract tuples