nltk.tag.util module

nltk.tag.util.str2tuple(s, sep='/')[source]

Given the string representation of a tagged token, return the corresponding tuple representation. The rightmost occurrence of sep in s will be used to divide s into a word string and a tag string. If sep does not occur in s, return (s, None).

>>> from nltk.tag.util import str2tuple
>>> str2tuple('fly/NN')
('fly', 'NN')
Parameters
  • s (str) – The string representation of a tagged token.

  • sep (str) – The separator string used to separate word strings from tags.

nltk.tag.util.tuple2str(tagged_token, sep='/')[source]

Given the tuple representation of a tagged token, return the corresponding string representation. This representation is formed by concatenating the token’s word string, followed by the separator, followed by the token’s tag. (If the tag is None, then just return the bare word string.)

>>> from nltk.tag.util import tuple2str
>>> tagged_token = ('fly', 'NN')
>>> tuple2str(tagged_token)
'fly/NN'
Parameters
  • tagged_token (tuple(str, str)) – The tuple representation of a tagged token.

  • sep (str) – The separator string used to separate word strings from tags.

nltk.tag.util.untag(tagged_sentence)[source]

Given a tagged sentence, return an untagged version of that sentence. I.e., return a list containing the first element of each tuple in tagged_sentence.

>>> from nltk.tag.util import untag
>>> untag([('John', 'NNP'), ('saw', 'VBD'), ('Mary', 'NNP')])
['John', 'saw', 'Mary']