Skip to content
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

Update extract_keywords.py #54

Merged
merged 1 commit into from
Feb 28, 2024
Merged
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
13 changes: 11 additions & 2 deletions exorde/extract_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ def is_valid_keyword(word):
isalpha_count = sum(1 for char in word if char.isalpha())
total_chars = len(word)
punctuation = re.compile(r'[^\w\s,]')
return (uppercase_count / total_chars >= 0.3) and (punctuation.search(word) is not None) and (isalpha_count>1)
# Prevent division by zero
if total_chars > 0:
return (uppercase_count / total_chars >= 0.3) and (punctuation.search(word) is not None) and (isalpha_count>1)
else:
return False


words = nltk.word_tokenize(text)
filtered_words = filter(is_valid_keyword, words)
Expand Down Expand Up @@ -138,7 +143,11 @@ def is_valid_acronym(word):
uppercase_count = sum(1 for char in word if char.isupper())
isalpha_count = sum(1 for char in word if char.isalpha())
total_chars = len(word)
return (uppercase_count / total_chars >= 0.3) and (isalpha_count>=1) and len(word) >= 2
# Prevent division by zero
if total_chars > 0:
return (uppercase_count / total_chars >= 0.3) and (isalpha_count>=1) and len(word) >= 2
else:
return False

# split by space and special punctuation: comma, point, period
# not nltk tokenize
Expand Down
Loading