Spaces:
Runtime error
Runtime error
File size: 1,741 Bytes
5d0a311 e5fc5ba 0a0a388 e5fc5ba 5d0a311 0a0a388 e5fc5ba 5416d85 5d0a311 0a0a388 5d0a311 5416d85 5d0a311 e7339fb 5d0a311 8c97d69 5d0a311 e5fc5ba 5416d85 0a0a388 5416d85 |
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 |
from typing import Tuple
from modules.m_active_voice import ActiveVoice
from modules.m_htmlrender import HtmlRender
from modules.m_datetime import Datetime
class Connector:
def __init__(
self
) -> None:
self.date = Datetime()
self.avoice = ActiveVoice()
self.html = HtmlRender()
self.cache_sentence = None
self.cache_html_format = None
self.cache_str_format = None
def view_conversion(
self,
active_sent: str,
passive_sent: str
) -> None:
print(f".goat: {self.date.full()} - '{active_sent}' -> '{passive_sent}'")
def active2passive(
self,
sentence: str
) -> Tuple[str,str]:
if sentence == self.cache_sentence:
return self.cache_html_format, self.cache_str_format
try:
data = self.avoice.to_passive(sentence)
except Exception as e:
return self.html.error(str(e)), str(e)
subj = self.html.budget(data['subj'], 'subject', 'primary')
tobe = self.html.budget(data['tobe'],'to be','warning')
participle = self.html.budget(data['participle'],'participle','danger')
agent = self.html.budget(data['agent'],'agent','success')
compl = self.html.budget(data['compl'],'compl.','dark')
self.cache_sentence = sentence
self.cache_str_format = f"{data['subj']} {data['tobe']} {data['participle']} {data['agent']} {data['compl']}"
self.cache_html_format = self.html.output(f"{subj} {tobe} {participle} {agent} {compl}")
self.view_conversion(self.cache_sentence, self.cache_str_format)
return self.cache_html_format, self.cache_str_format |