Search code examples
pythonregexpos-tagger

'_sre.SRE_Pattern' object is not iterable in Python 3.4


When I use Brill Tagger, I get this error.

TypeError: '_sre.SRE_Pattern' object is not iterable
WARNING:root:2016-04-05 00:05:37.503718 is when this event was logged.
ERROR:root:'_sre.SRE_Pattern' object is not iterable
Traceback (most recent call last):
  File "D:\Dropbox\VCL\MyWrapper.py", line 137, in run_alg
    CLC_POS.tag_file(input_utf8, path_out + '.pos', file_encoding, CLC_POS.load_tagger('pos_tbl_86943.model'), '')
  File "D:\Dropbox\VCL\CLC_POS.py", line 277, in tag_file
    token_tag = tagger.tag(word_list)
  File "C:\Python34\lib\site-packages\nltk\tag\brill.py", line 264, in tag
    tagged_tokens = self._initial_tagger.tag(tokens)
  File "C:\Python34\lib\site-packages\nltk\tag\sequential.py", line 61, in tag
    tags.append(self.tag_one(tokens, i, tags))
  File "C:\Python34\lib\site-packages\nltk\tag\sequential.py", line 81, in tag_one
    tag = tagger.choose_tag(tokens, index, history)
  File "C:\Python34\lib\site-packages\nltk\tag\sequential.py", line 546, in choose_tag
    for regexp, tag in self._regexs:
TypeError: '_sre.SRE_Pattern' object is not iterable

In sequential.py, I get error when it comes to for loop.

def choose_tag(self, tokens, index, history):
    for regexp, tag in self._regexs:
        if re.match(regexp, tokens[index]):
            return tag
    return None

I run this same code a month ago and there was no error. sequential.py belongs to nltk files, does that means I should mess with it?

What have I done wrong? Please provide a fix if possible.


Solution

  • The solution is quite simple.

    We just need to train the data again to get new model.

    I think problem is some changes in NLTK, but not sure where it is. Besides, this only affects Brill Tagger, not CRF Tagger.