Skip to content

Commit ed1968a

Browse files
committed
prevent div by zero in cit common phase %; comparing to whitespace
1 parent 154c4bf commit ed1968a

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/academic_tracker/helper_functions.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -672,8 +672,8 @@ def _compute_common_phrase_percent(prev_citation, new_citation, characters_to_re
672672
((int, int)|None): if either citation is None, then return None, else the percentage of common to uncommon phrase length for each citation.
673673
"""
674674
if prev_citation and new_citation:
675-
citation_strip_regex = "|".join([f"\\{char}" for char in characters_to_remove])
676-
# citation_strip_regex = r"\.|,|;|\(|\)|\[|\]|\{|\}"
675+
citation_strip_regex = "|".join([f"\{char}" for char in characters_to_remove])
676+
# citation_strip_regex_old = r"\.|,|;|\(|\)|\[|\]|\{|\}"
677677
stripped_prev_citation = re.sub(citation_strip_regex, "", prev_citation.lower())
678678
stripped_new_citation = re.sub(citation_strip_regex, "", new_citation.lower())
679679

@@ -690,7 +690,9 @@ def _compute_common_phrase_percent(prev_citation, new_citation, characters_to_re
690690
new_common_denom = len(common_base_string + new_citation_common_phrases_removed.strip())
691691

692692
if prev_common_denom == 0 or new_common_denom == 0:
693-
print(f"WARN: {prev_citation} vs. {new_citation} similarity divide by zero")
693+
print(f"WARN: similarity divide by zero")
694+
print(f"{prev_citation = }")
695+
print(f"{new_citation = }")
694696
print(f"\treturning None")
695697
return None
696698

0 commit comments

Comments
 (0)