forked from azk0019/CourseProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTEXT_PREPROCESSING.py
More file actions
33 lines (28 loc) · 921 Bytes
/
TEXT_PREPROCESSING.py
File metadata and controls
33 lines (28 loc) · 921 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import emoji
import nltk
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize
nltk.download('stopwords')
nltk.download('punkt')
import string
import re
def preprocess_text(input_data):
data = input_data
# Removing tags
#data = tf.strings.regex_replace(input_data, "@USER", " ")
#data = tf.strings.regex_replace(data, "<URL>", " ")
# Process emojis
#data = emoji.demojize(data, delimiters=(" ", " "))
# Remove stopwords/emojis
stop_words = set(stopwords.words("english"))
emojis = set(emoji.UNICODE_EMOJI_ALIAS)
word_tokens = word_tokenize(data)
data = []
for w in word_tokens:
# Modify below for stopwords and/or emojis
if w not in emojis:
data.append(w)
data = (" ").join(data)
# Remove non alpha-numeric characters (not sure if a good idea)
#data = re.sub(r'[^\w'+' .'+']', '', data)
return data