-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtext_functions.py
More file actions
37 lines (26 loc) · 818 Bytes
/
text_functions.py
File metadata and controls
37 lines (26 loc) · 818 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
34
35
36
37
import model_loader as ml
# To detect spam
def isspam(string: str) -> bool:
"""Checks for spam in the given string
Args:
string: A string to be checked
Returns:
Boolean
"""
string = [string]
sen_trans = ml.spam_vect.transform(string)
prediction = ml.spam_model.predict(sen_trans)[0] # 0->ham 1->spam
return True if prediction else False
# -----------------------------------------------#
# To detect hate speech
def ishate(string: str) -> bool:
"""Checks for hate speech in the given string
Args:
string: A string to be checked
Returns:
Boolean
"""
string = [string]
sen_trans = ml.hate_vect.transform(string)
prediction = ml.hate_model.predict(sen_trans)[0] # 0->normal 1->toxic
return True if prediction else False