Skip to content

Commit

Permalink
Merge pull request #6 from ianzur/citation-common-phrase-div-by-zero
Browse files Browse the repository at this point in the history
Citation common phrase div by zero
  • Loading branch information
ptth222 authored May 13, 2024
2 parents aeec310 + d838bec commit c424a93
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/academic_tracker/helper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ def _compute_common_phrase_percent(prev_citation, new_citation, characters_to_re
min_len (int): the minimum length of a subphrase.
Returns:
((int, int)|None): if either citation is None, then return None, else the percentage of common to uncommon phrase length for each citation.
((int, int)|None): if either citation is None or empty after character removal and stripping, then return None, else the percentage of common to uncommon phrase length for each citation.
"""
if prev_citation and new_citation:
citation_strip_regex = "|".join([f"\{char}" for char in characters_to_remove])
Expand All @@ -685,8 +685,12 @@ def _compute_common_phrase_percent(prev_citation, new_citation, characters_to_re
prev_citation_common_phrases_removed = prev_citation_common_phrases_removed.replace(phrase.strip(), "")
new_citation_common_phrases_removed = new_citation_common_phrases_removed.replace(phrase.strip(), "")
common_base_string = "".join(common_subphrases)
prev_common_percentage = len(common_base_string) / len(common_base_string + prev_citation_common_phrases_removed.strip()) * 100
new_common_percentage = len(common_base_string) / len(common_base_string + new_citation_common_phrases_removed.strip()) * 100
prev_common_denom = len(common_base_string + prev_citation_common_phrases_removed.strip())
new_common_denom = len(common_base_string + new_citation_common_phrases_removed.strip())
if prev_common_denom == 0 or new_common_denom == 0:
return None
prev_common_percentage = len(common_base_string) / prev_common_denom * 100
new_common_percentage = len(common_base_string) / new_common_denom * 100

return prev_common_percentage, new_common_percentage
else:
Expand Down

0 comments on commit c424a93

Please sign in to comment.