Created
June 26, 2019 04:40
-
-
Save shreydesai/2f246db5845de3c954b561fc8b31fb3d to your computer and use it in GitHub Desktop.
Preprocessing rules for Twitter data
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
def preprocess(raw): | |
if '>' in raw: | |
raw = raw.replace('>','>') | |
if '<' in raw: | |
raw = raw.replace('<','<') | |
if '&' in raw: | |
raw = raw.replace('&','&') | |
if '”' in raw or '“' in raw: | |
raw = raw.replace('“','"') | |
raw = raw.replace('”','"') | |
if '’' in raw: | |
raw = raw.replace('’',"'") | |
text = [x.text.strip() for x in nlp(raw) if len(x.text.strip())>0] | |
for i in range(len(text)): | |
if text[i].startswith('http'): | |
text[i] = '<link>' | |
elif text[i].startswith('@'): | |
text[i] = '<user>' | |
return ' '.join(text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment