-
Notifications
You must be signed in to change notification settings - Fork 0
/
text.py
34 lines (22 loc) · 808 Bytes
/
text.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
import emoji
class Labels:
def __init__(self, text: str | None) -> None:
self.text = text
def __call__(self) -> list[str]:
return self.get_emoji_label()
def get_emoji_label(self) -> list[str]:
if self.text is None:
return []
emoji_count = len(emoji.emoji_list(self.text))
if emoji_count == 0:
return []
if emoji_count == 1:
return ['emoji']
if emoji_count == 2:
return ['two_emojies']
return ['three_or_more_emojies']
if __name__ == '__main__':
assert Labels('текст')() == []
assert Labels('текст😁')() == ['emoji']
assert Labels('😁текст😁')() == ['two_emojies']
assert Labels('😁😁😁текст')() == ['three_or_more_emojies']