Created
December 20, 2020 04:12
-
-
Save alinazhanguwo/efe316b842f3c6ea691f162a1f2e0b0d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
STOPWORDS = stopwords.words('english') | |
STOPWORDS = set(STOPWORDS) | |
def text_prepare(text, STOPWORDS): | |
""" | |
text: a string | |
return: a clean string | |
""" | |
REPLACE_BY_SPACE_RE = re.compile('[\n\"\'/(){}\[\]\|@,;#]') | |
text = re.sub(REPLACE_BY_SPACE_RE, ' ', text) | |
text = re.sub(' +', ' ', text) | |
text = text.lower() | |
# delete stopwords from text | |
text = ' '.join([word for word in text.split() if word not in STOPWORDS]) | |
text = text.strip() | |
return text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment