File size: 1,675 Bytes
5d0a311
 
 
 
 
 
 
 
 
 
 
 
b1aa3b5
5d0a311
b1aa3b5
5d0a311
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b1aa3b5
5d0a311
b1aa3b5
 
 
 
 
 
 
5d0a311
b1aa3b5
5d0a311
 
b1aa3b5
5d0a311
b1aa3b5
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
from typing import Tuple
from modules.m_apvoice import APVoice

class Connector:
    def __init__(
        self
    ) -> None:

        self.apvoice = APVoice()
        
        self.__out_template = """
            <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
            <center>{}</center>
        """
        self.__error_template = "<center><h3><b>{}</b></h3></center>"

    def create_category(
        self,
        text: str,
        category: str,
        color: str
    ) -> str:

        html = f"""
            <div type="button" title="{category}" class="btn btn-{color} btn-sm p-2">
            <b>{text}</b><br> 
            <span class="badge text-bg-light">{category}</span>
            </div>
        """
        return html if text != "" else ""

    def active2passive(
        self,
        sentence: str
    ) -> Tuple[str,str]:

        out = ""
        try:
            out = self.apvoice.active2passive(sentence)
            out = f"""
                {self.create_category(out['subject'], 'subject','primary')}
                {self.create_category(out['tobe'],'to be','warning')}
                {self.create_category(out['participle'],'participle','danger')}
                {self.create_category(out['agent'],'agent','info')}
                {self.create_category(out['complement'],'compl.','dark')} 
            """
            out = self.__out_template.format(out)

        except Exception as e:
            out = self.__error_template.format(str(e))

        return out