-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPreProcess.py
98 lines (72 loc) · 3.02 KB
/
PreProcess.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<<<<<<< HEAD
# sequence of characters that forms a search pattern
import re
def pre_processing(tweet):
s = ""
# URL Removal
tweet = re.sub(r'http\S+', '', tweet)
# Smile -- :), : ), :-), (:, ( :, (-:, :')
tweet = re.sub(r'(:\s?\)|:-\)|\(\s?:|\(-:|:\'\))', '', tweet)
# Laugh -- :D, : D, :-D, xD, x-D, XD, X-D
tweet = re.sub(r'(:\s?D|:-D|x-?D|X-?D)', '', tweet)
# Love -- <3, :*, 💙
tweet = re.sub(r'(<3|:\*|💙)', '', tweet)
tweet = re.sub(r'(🥰|💓|💖|💗|💞|💘|💘|💓|❤|💚|🧡|🧡|💞|💓|💖|💕|💘|💞|öö|🙃|👀|👇|🔵)', '', tweet)
# Wink -- ;-), ;), ;-D, ;D, (;, (-;
tweet = re.sub(r'(;-?\)|;-?D|\(-?;)', '', tweet)
# Sad -- :-(, : (, :(, ):, )-, :
tweet = re.sub(r'(:\s?\(|:-\(|\)\s?:|\)-:)', '', tweet)
# Cry -- :,(, :'(, :"(
tweet = re.sub(r'(:,\(|:\'\(|:"\()', '', tweet)
# username removal
tweet = re.sub('@[^/s]+', '', tweet)
# Numbers removing
pattern = '[0-9]'
tweet = [re.sub(pattern, '', i) for i in tweet]
tweet = s.join(tweet)
# Convert more than 2 letter repetitions to 2 letter
# funnnnny --> funny
tweet = re.sub(r'(.)\1+', r'\1\1', tweet)
# Remove All the QWERTY Symbols
tweet = re.sub(r'(-|\'|\?|\/|\\|\`|\!|\`|\#|\$|\%|\^|\&|\*)', '', tweet)
tweet = re.sub(r'(\*|\(|\)|\_|\+|\=|\.|\,|\<|\>|\{|\[|\}|\]|\"|\;|\:|\~)', '', tweet)
# multiple whitespace removal
tweet = " ".join(tweet.split())
tweet = str(tweet.lower())
=======
# sequence of characters that forms a search pattern
import re
def pre_processing(tweet):
s = ""
# URL Removal
tweet = re.sub(r'http\S+', '', tweet)
# Smile -- :), : ), :-), (:, ( :, (-:, :')
tweet = re.sub(r'(:\s?\)|:-\)|\(\s?:|\(-:|:\'\))', '', tweet)
# Laugh -- :D, : D, :-D, xD, x-D, XD, X-D
tweet = re.sub(r'(:\s?D|:-D|x-?D|X-?D)', '', tweet)
# Love -- <3, :*, 💙
tweet = re.sub(r'(<3|:\*|💙)', '', tweet)
tweet = re.sub(r'(🥰|💓|💖|💗|💞|💘|💘|💓|❤|💚|🧡|🧡|💞|💓|💖|💕|💘|💞|öö|🙃|👀|👇|🔵)', '', tweet)
# Wink -- ;-), ;), ;-D, ;D, (;, (-;
tweet = re.sub(r'(;-?\)|;-?D|\(-?;)', '', tweet)
# Sad -- :-(, : (, :(, ):, )-, :
tweet = re.sub(r'(:\s?\(|:-\(|\)\s?:|\)-:)', '', tweet)
# Cry -- :,(, :'(, :"(
tweet = re.sub(r'(:,\(|:\'\(|:"\()', '', tweet)
# username removal
tweet = re.sub('@[^/s]+', '', tweet)
# Numbers removing
pattern = '[0-9]'
tweet = [re.sub(pattern, '', i) for i in tweet]
tweet = s.join(tweet)
# Convert more than 2 letter repetitions to 2 letter
# funnnnny --> funny
tweet = re.sub(r'(.)\1+', r'\1\1', tweet)
# Remove All the QWERTY Symbols
tweet = re.sub(r'(-|\'|\?|\/|\\|\`|\!|\`|\#|\$|\%|\^|\&|\*)', '', tweet)
tweet = re.sub(r'(\*|\(|\)|\_|\+|\=|\.|\,|\<|\>|\{|\[|\}|\]|\"|\;|\:|\~)', '', tweet)
# multiple whitespace removal
tweet = " ".join(tweet.split())
tweet = str(tweet.lower())
>>>>>>> a8eac8957e283fe23b26e99d32eac0ba302a4a04
return tweet