Skip to content

Fix indexerror when texts are same by adding if clause #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 29 additions & 28 deletions text_matcher/matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,34 +247,35 @@ def extend_matches(self, cutoff=0.4):
extended = False
for match in self.healed_matches:
# Look one word before.
wordA = self.textAgrams[(match.a - 1)][0]
wordB = self.textBgrams[(match.b - 1)][0]
if self.edit_ratio(wordA, wordB) < cutoff:
if self.silent is not True:
print('Extending match backwards with words: %s %s' %
(wordA, wordB))
match.a -= 1
match.b -= 1
match.sizeA += 1
match.sizeB += 1
match.extendedBackwards += 1
extended = True
# Look one word after.
idxA = match.a + match.sizeA + 1
idxB = match.b + match.sizeB + 1
if idxA > len(self.textAgrams) - 1 or idxB > len(self.textBgrams) - 1:
# We've gone too far, and we're actually at the end of the text.
continue
wordA = self.textAgrams[idxA][-1]
wordB = self.textBgrams[idxB][-1]
if self.edit_ratio(wordA, wordB) < cutoff:
if self.silent is not True:
print('Extending match forwards with words: %s %s' %
(wordA, wordB))
match.sizeA += 1
match.sizeB += 1
match.extendedForwards += 1
extended = True
if match.a > 0 and match.b > 0:
wordA = self.textAgrams[(match.a - 1)][0]
wordB = self.textBgrams[(match.b - 1)][0]
if self.edit_ratio(wordA, wordB) < cutoff:
if self.silent is not True:
print('Extending match backwards with words: %s %s' %
(wordA, wordB))
match.a -= 1
match.b -= 1
match.sizeA += 1
match.sizeB += 1
match.extendedBackwards += 1
extended = True
# Look one word after.
idxA = match.a + match.sizeA + 1
idxB = match.b + match.sizeB + 1
if idxA > len(self.textAgrams) - 1 or idxB > len(self.textBgrams) - 1:
# We've gone too far, and we're actually at the end of the text.
continue
wordA = self.textAgrams[idxA][-1]
wordB = self.textBgrams[idxB][-1]
if self.edit_ratio(wordA, wordB) < cutoff:
if self.silent is not True:
print('Extending match forwards with words: %s %s' %
(wordA, wordB))
match.sizeA += 1
match.sizeB += 1
match.extendedForwards += 1
extended = True

if extended:
# If we've gone through the whole list and there's nothing
Expand Down