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

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

        self.apvoice = APVoice()
        
            # <center>{}</center>
        self.__out_template = """
        <html lang="en">
        <head>
            <meta charset="utf-8">
            <meta name="viewport" content="width=device-width, initial-scale=1">
            <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
        </head>
        <body>
            <center><div class="btn-group btn-group-sm" role="group">{}</div></center>
            <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
        </body>
        </html>
        """
        self.__error_template = "<center><b>{}</b></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, error = "", ""
        try:
            subject, tobe, participle, agent, complement = self.apvoice.active2passive(sentence)
            verb = f"""
            """
            passive_sentece = f"""
                {self.create_category(subject, 'subject','primary')}
                {self.create_category(tobe,'to be','warning')}
                {self.create_category(participle,'participle','danger')}
                {self.create_category(agent,'agent','info')}
                {self.create_category(complement,'compl.','dark')}
            """
            out = self.__out_template.format(passive_sentece)

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

        return error, out