nltk.SennaChunkTagger.bio_to_chunks

SennaChunkTagger.bio_to_chunks(tagged_sent, chunk_type)[source]

Extracts the chunks in a BIO chunk-tagged sentence.

>>> from nltk.tag import SennaChunkTagger
>>> chktagger = SennaChunkTagger('/usr/share/senna-v2.0')
>>> sent = 'What is the airspeed of an unladen swallow ?'.split()
>>> tagged_sent = chktagger.tag(sent)
>>> tagged_sent
[('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')]
>>> list(chktagger.bio_to_chunks(tagged_sent, chunk_type='NP'))
[('What', '0'), ('the airspeed', '2-3'), ('an unladen swallow', '5-6-7')]
Parameters:
  • tagged_sent (str) – A list of tuples of word and BIO chunk tag.
  • tagged_sent – The chunk tag that users want to extract, e.g. ‘NP’ or ‘VP’
Returns:

An iterable of tuples of chunks that users want to extract and their corresponding indices.

Return type:

iter(tuple(str))