-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtext_transformer.py
More file actions
109 lines (91 loc) · 3.29 KB
/
text_transformer.py
File metadata and controls
109 lines (91 loc) · 3.29 KB
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
99
100
101
102
103
104
105
106
107
108
109
import demoji # for removing emoji
from art import text2art
class Kalimat:
def __init__(self, sentence):
self.sentence = sentence
self.excludedWords = ['2beer!', 'mksfess', '[askmf]', '[cm]', '[gmf]', 'tanyarl',
'/wal', '/rlt/', '/krt/', 'fess', 'brl!', 'yeet!', '/mahasantuy/', '(nyampah)', 'Brl!']
self.excludedChars = ['%']
def getSentence(self):
text = self.removeWords()
return text
def removeWords(self):
self.sentence = demoji.replace(self.sentence)
finalText = ''
invisibleChar = [u"\u2800", u"\u2063", u'\xe3', u'\xa4']
words = [i for j in self.sentence.split() for i in (j, ' ')][:-1]
for word in words:
word = word.lower()
# remove twt username, hashtag, and links
if word[0] == '@' or word[0] == '#' or word[0:4] == 'http':
word = word.replace(word, '')
if word[0:5] == '&':
word = word.replace(word, '&')
for ew in self.excludedWords: # remove unnecassary words
word = word.replace(ew, '')
for char in word:
if char in invisibleChar: # remove invisible char
char = char.replace(char, '')
if char in self.excludedChars: # remove unnecessary char
char = char.replace(char, '')
finalText += char
return finalText
def transform(self):
finalText = ''
text = self.removeWords()
for i, char in enumerate(text):
if i % 2 != 0:
char = char.replace(char, char.upper())
finalText += char
else:
finalText += char
return finalText
def trinsfirm(self):
finalText = ''
text = self.removeWords()
vokal = ['a', 'u', 'e', 'o']
for char in text:
if char in vokal:
char = char.replace(char, 'i')
finalText += char
else:
finalText += char
return finalText
def transformoji(self, emoji_type):
finalText = ''
text = self.removeWords()
text = text.split()
if emoji_type == "laugh":
for word in text:
word += "😂"
finalText += word
return finalText
elif emoji_type == "clap":
for word in text:
word += "👏"
finalText += word
return finalText
elif emoji_type == "vomit":
for word in text:
word += "🤮"
finalText += word
return finalText
elif emoji_type == "sick":
for word in text:
word += "🤢"
finalText += word
return finalText
elif emoji_type == "poop":
text = self.removeWords()
for char in text:
if char is not ' ':
char = char.replace(char, '💩')
finalText += char
else:
finalText += char
return finalText
def transformalay(self):
finalText = ''
text = self.removeWords()
finalText = text2art(text, 'mix')
return finalText