Created
January 26, 2020 08:36
-
-
Save mohdsanadzakirizvi/79d16de3c9c3dac3cde87bd37affbde5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import nltk | |
nltk.download('stopwords') | |
# download stopwords list from nltk | |
from nltk.corpus import stopwords | |
stop_words = set(stopwords.words('english')) | |
def clean_text(text): | |
# converting to lowercase | |
newString = text.lower() | |
# removing links | |
newString = re.sub(r'(https|http)?:\/\/(\w|\.|\/|\?|\=|\&|\%)*\b', '', newString) | |
# fetching alphabetic characters | |
newString = re.sub("[^a-zA-Z]", " ", newString) | |
# removing stop words | |
tokens = [w for w in newString.split() if not w in stop_words] | |
# removing short words | |
long_words=[] | |
for i in tokens: | |
if len(i)>=4: | |
long_words.append(i) | |
return (" ".join(long_words)).strip() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment