JonathanReeve/text-matcher

IndexError: list index out of range

hemanthadawale opened this issue · 6 comments

After lots and lots of extended matches, index error occurred. It has occurred in getLocations function. Can you please help? Have shared an error log.

Extending match backwards with words: adv adv
Extending match backwards with words: car car
Extending match backwards with words: find find
INFO:werkzeug:127.0.0.1 - - [09/Jan/2020 23:28:24] "�[1m�[35mPOST /submit_lists HTTP/1.1�[0m" 500 -
Traceback (most recent call last):
  File "C:\Users\Hemant\.conda\envs\grey\lib\site-packages\flask\app.py", line 2328, in __call__
    return self.wsgi_app(environ, start_response)
  File "C:\Users\Hemant\.conda\envs\grey\lib\site-packages\flask\app.py", line 2314, in wsgi_app
    response = self.handle_exception(e)
  File "C:\Users\Hemant\.conda\envs\grey\lib\site-packages\flask\app.py", line 1760, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "C:\Users\Hemant\.conda\envs\grey\lib\site-packages\flask\_compat.py", line 36, in reraise
    raise value
  File "C:\Users\Hemant\.conda\envs\grey\lib\site-packages\flask\app.py", line 2311, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\Users\Hemant\.conda\envs\grey\lib\site-packages\flask\app.py", line 1834, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "C:\Users\Hemant\.conda\envs\grey\lib\site-packages\flask\app.py", line 1737, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "C:\Users\Hemant\.conda\envs\grey\lib\site-packages\flask\_compat.py", line 36, in reraise
    raise value
  File "C:\Users\Hemant\.conda\envs\grey\lib\site-packages\flask\app.py", line 1832, in full_dispatch_request
    rv = self.dispatch_request()
  File "C:\Users\Hemant\.conda\envs\grey\lib\site-packages\flask\app.py", line 1818, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "C:\Users\Hemant\Desktop\Web Scraping\content_matching\Match_app.py", line 146, in Input_Page
    complete = match_pair(list_A, list_B)
  File "C:\Users\Hemant\Desktop\Web Scraping\content_matching\Match_app.py", line 106, in match_pair
    a,b,c,out_all = matcher.Matcher(STR1, STR2).match()
  File "C:\Users\Hemant\Desktop\Web Scraping\content_matching\matcher.py", line 279, in match
    out_dict = self.getMatch(match)
  File "C:\Users\Hemant\Desktop\Web Scraping\content_matching\matcher.py", line 176, in getMatch
    spansA = self.getLocations(textA, match.a, lengthA)
  File "C:\Users\Hemant\Desktop\Web Scraping\content_matching\matcher.py", line 167, in getLocations
    locations = (spans[0][0], spans[-1][-1])
IndexError: list index out of range

I just wrapped that code in a try/except that should fix that, I hope. Could you pull the latest version (from here on GitHub), and try again, and let me know if it works?

Yup it handled error there, but it goes into an infinite loop in extend_matches() function. Keeps printing same set of "Extending match backwards with words: xyz". And after lot of time IndexError at:

IndexError
IndexError: list index out of range
File "/home/ec2-user/content_matcher/matcher.py", line 269, in extend_matches
self.extend_matches()
File "/home/ec2-user/content_matcher/matcher.py", line 269, in extend_matches
self.extend_matches()
File "/home/ec2-user/content_matcher/matcher.py", line 269, in extend_matches
self.extend_matches()
File "/home/ec2-user/content_matcher/matcher.py", line 239, in extend_matches
wordA = self.textAgrams[(match.a - 1)][0]
IndexError: list index out of range

Please can you help me with this?

Sure. Could you give me a copy of the text pairs you're using that cause the error? I'm having difficulty reproducing the error myself, using my test texts.

Sure. Could you give me a copy of the text pairs you're using that cause the error? I'm having difficulty reproducing the error myself, using my test texts.

Have sent the strings to reproduce error. Let me know if it doesn't produce error.
I have mailed it at jon.reeve@gmail.com, is it okay?

The issue was due to identical strings. When both strings are 100% identical it raises an error. Handled it using try except again. Also the sample which i mailed you , i later found that they were not correct.
Anyways, Great work, coding style and its depth. Loved it!!!.
Thank you so much.

Ok, glad it worked out! Let me know if you encounter any other errors. Also, I'm going to use this program a lot myself in the upcoming weeks, so I'll probably release a new version or two then.