Skip to content

Commit

Permalink
remove nltk dependency on stopwords
Browse files Browse the repository at this point in the history
  • Loading branch information
mosesmc52 committed Dec 26, 2021
1 parent 03fd295 commit a4daed9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ idna==2.8
importlib-metadata==1.6.0
kombu==4.6.8
lxml==4.6.3
nltk==3.4.5
numpy==1.18.1
oauthlib==3.1.0
pandas==0.25.3
Expand Down
22 changes: 17 additions & 5 deletions utils/utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import json
import re
from nltk.corpus import stopwords
import requests

def remove_stopwords(input):
word_list = input.split(" ")
return ' '.join([word.lower() for word in word_list if word.lower() not in stopwords.words('english')]) # remove stop words

def hasPhrase(phrases = [], text = ''):
return any([phrase for phrase in phrases if phrase.lower() in text.lower() ])

Expand Down Expand Up @@ -113,3 +108,20 @@ def get_census_block(lat, long):
if len(data['results']):
return data['results'][0]['county_fips']
return ''

def get_stopwords():
return ['i ', 'me', 'my', 'myself', 'we', 'our', 'ours', 'ourselves', 'you', 'your', 'yours', 'yourself', 'yourselves', 'he', 'him', 'his', 'himself', 'she', 'her', 'hers', 'herself', 'it', 'its', 'itself', 'they', 'them', 'their', 'theirs', 'themselves', 'what', 'which', 'who', 'whom', 'this', 'that', 'these', 'those', 'am', 'is', 'are', 'was', 'were', 'be', 'been', 'being', 'have', 'has', 'had', 'having', 'do', 'does', 'did', 'doing', 'a', 'an', 'the', 'and', 'but', 'if', 'or', 'because', 'as', 'until', 'while', 'of', 'at', 'by', 'for', 'with', 'about', 'against', 'between', 'into', 'through', 'during', 'before', 'after', 'above', 'below', 'to', 'from', 'up', 'down', 'in', 'out', 'on', 'off', 'over', 'under', 'again', 'further', 'then', 'once', 'here', 'there', 'when', 'where', 'why', 'how', 'all', 'any', 'both', 'each', 'few', 'more', 'most', 'other', 'some', 'such', 'no', 'nor', 'not', 'only', 'own', 'same', 'so', 'than', 'too', 'very', 's', 't', 'can', 'will', 'just', 'don', 'should', 'now']

def remove_stopwords(input):
word_list = input.split(" ")

# remove stop words
modified_string = ' '.join([word.lower() for word in word_list if word.lower() not in get_stopwords()]) # remove stop words

# remove words within parens
modified_string = re.sub(r"\([^()]*\)", "", modified_string)

# remove special characters
modified_string = re.sub(r'\W+', ' ', modified_string).strip()

return modified_string

0 comments on commit a4daed9

Please sign in to comment.