-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
137 lines (100 loc) · 4.76 KB
/
app.py
File metadata and controls
137 lines (100 loc) · 4.76 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import j3mify as jeje
# * External Libraries for Terminal style customization 🌾✨
from rich import box
from rich.panel import Panel
from rich.prompt import Prompt
from rich.layout import Layout
from rich.console import Console
from rich.columns import Columns
from typing import Dict, Literal, List
console = Console()
layout = Layout(name="root")
ORIGINAL_COLOR: str = "#C3AD88"
NORMALIZED_CHAR_COLOR: str = "#AA5048"
TOKENIZATION_COLOR: str = "#E0A15E"
NORMALIZED_SENTENCE_COLOR: str = "#658963"
def display_debug_mode(original_sentence: str, normalized_characters: str, tokenization: str, normalized_sentence: str) -> None:
""" for j3mify debug mode """
# * For Original sentence
box1: Panel = Panel.fit(original_sentence, title="🐞 ORIGINAL",
title_align = "left", border_style = ORIGINAL_COLOR, padding = 2, box = box.ROUNDED)
# * For normalization of characters sentence
box2: Panel = Panel.fit(normalized_characters, title="♻️ NORMALIZED BY CHARACTERS",
title_align = "left", border_style= NORMALIZED_CHAR_COLOR, padding = 2, box = box.ROUNDED)
# * For tokenization
box3: Panel = Panel.fit(" | ".join(tokenization), title="✂️ TOKENIZATION",
title_align = "left", border_style = TOKENIZATION_COLOR, padding = 2, box = box.ROUNDED)
# * For normalized sentence which is done 👌
box4: Panel = Panel.fit(normalized_sentence, title = "🎉 NORMALIZED",
title_align = "left", border_style = NORMALIZED_SENTENCE_COLOR, padding = 2, box = box.ROUNDED)
console.print(Columns([box1, box2, box3, box4], equal=True))
console.print("\n\n\n")
def display_presentation_mode(original_sentence: str, normalized_sentence: str) -> None:
""" For j3mify presentation mode """
# * For Original sentence
box1: Panel = Panel.fit(original_sentence, title="🐞 ORIGINAL",
title_align="left", border_style=ORIGINAL_COLOR, padding=2, box=box.ROUNDED)
# * For normalized sentence which is done 👌
box2: Panel = Panel.fit(normalized_sentence, title = "🎉 NORMALIZED",
title_align = "left", border_style = NORMALIZED_SENTENCE_COLOR, padding = 2, box = box.ROUNDED)
console.print(Columns([box1, box2], equal=True))
console.print("\n\n\n")
def display_normal_mode(normalized_sentence: str) -> None:
""" For j3mify normal mode """
# * For normalized sentence which is done 👌
box1: Panel = Panel.fit(normalized_sentence, title="🎉 NORMALIZED",
title_align="left", border_style=NORMALIZED_SENTENCE_COLOR, padding=2, box=box.ROUNDED)
console.print(box1)
console.print("\n\n\n")
def choose(sentence: str, mode: Literal["presentation", "debug"] = None) -> None:
""" Wala nakong maisip na function description lmao """
reply: Dict[str, str] | str = jeje.j3j3niZ3d(sentence)
if mode == "debug":
display_debug_mode(
original_sentence = reply.get("original_sentence"),
normalized_characters = reply.get("character_normalization"),
tokenization = reply.get("tokenization"),
normalized_sentence = reply.get("normalized_sentence")
)
return
if mode == "presentation":
display_presentation_mode(
original_sentence = reply.get("original_sentence"),
normalized_sentence = reply.get("normalized_sentence")
)
return
display_normal_mode(sentence)
def validation(sentence: List[str] | str, mode: Literal["presentation", "debug"] = None) -> None:
""" For checking of parameters """
if isinstance(sentence, list):
for data in sentence:
choose(data, mode=mode)
return
if isinstance(sentence, str):
choose(sentence, mode = mode)
return
choose(sentence = sentence)
def display_j3j3m0Nizer(sentence: List[str] | str, mode: Literal["presentation", "debug"] = None, input: bool = False) -> None:
""" User interface of the j3mify """
if mode and mode not in ["presentation", "debug"]:
print("[ 🍒 ]: Invalid Mode Choice.")
return
while input:
sentence = Prompt.ask("[😎]: ")
if sentence == "quit":
break
if sentence == "--debug":
mode = "debug"
print("[🐞] Debug Mode Activated ")
continue
if sentence == "--presentation":
mode = "presentation"
print("[💖] Presentation Mode Activated ")
continue
if sentence == "--normal":
mode = None
print("[🌾] Normal Mode Activated ")
continue
validation(sentence, mode)
else:
validation(sentence, mode)