Merge: Fix: Refactor for clean code and portfolio presentation.
This commit is contained in:
5
business_objects/__init__.py
Normal file
5
business_objects/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
@author: Edward Middleton-Smith
|
||||
"""
|
||||
|
||||
BIN
business_objects/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
business_objects/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
business_objects/__pycache__/attribute_abstract.cpython-312.pyc
Normal file
BIN
business_objects/__pycache__/attribute_abstract.cpython-312.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
business_objects/__pycache__/character_braille.cpython-312.pyc
Normal file
BIN
business_objects/__pycache__/character_braille.cpython-312.pyc
Normal file
Binary file not shown.
BIN
business_objects/__pycache__/character_braille.cpython-38.pyc
Normal file
BIN
business_objects/__pycache__/character_braille.cpython-38.pyc
Normal file
Binary file not shown.
BIN
business_objects/__pycache__/translation_braille.cpython-312.pyc
Normal file
BIN
business_objects/__pycache__/translation_braille.cpython-312.pyc
Normal file
Binary file not shown.
BIN
business_objects/__pycache__/translation_braille.cpython-38.pyc
Normal file
BIN
business_objects/__pycache__/translation_braille.cpython-38.pyc
Normal file
Binary file not shown.
55
business_objects/attribute_abstract.py
Normal file
55
business_objects/attribute_abstract.py
Normal file
@@ -0,0 +1,55 @@
|
||||
|
||||
"""
|
||||
@author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
"""
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from prettytable import PrettyTable
|
||||
|
||||
|
||||
class Attribute_Abstract(ABC):
|
||||
@abstractmethod
|
||||
def get_defaults():
|
||||
pass
|
||||
@abstractmethod
|
||||
def get_list_headings():
|
||||
pass
|
||||
@abstractmethod
|
||||
def as_row(self):
|
||||
pass
|
||||
|
||||
def input_from_console(cls):
|
||||
options = cls.get_defaults()
|
||||
count_options = len(options)
|
||||
table_output = PrettyTable()
|
||||
table_output.field_names = ['index'] + cls.get_list_headings()
|
||||
for index_option in range(count_options):
|
||||
option = options[index_option]
|
||||
table_output.add_row([index_option + 1] + option.as_row())
|
||||
print()
|
||||
print("Please select product configuration from below: ")
|
||||
print(table_output)
|
||||
while True:
|
||||
option = str(input("Product configuration (by index): "))
|
||||
print(option + " selected")
|
||||
if option == "#!ERRORCODE!#": exit()
|
||||
for index_option in range(count_options):
|
||||
if option == str(index_option + 1):
|
||||
return options[index_option]
|
||||
|
||||
def input_many_from_console(cls):
|
||||
selected = []
|
||||
print(f'Inputting many {cls.__name__} objects')
|
||||
print()
|
||||
while True:
|
||||
try:
|
||||
count_inputs = int(input(f'Quantity of {cls.__name__} objects to enter: '))
|
||||
except: continue
|
||||
for index_input in range(count_inputs):
|
||||
print(f'Inputting {cls.__name__} object {index_input + 1}')
|
||||
selected_new = cls.input_from_console(cls)
|
||||
selected.append(selected_new)
|
||||
break
|
||||
return selected
|
||||
|
||||
32
business_objects/braille_proficiency_level.py
Normal file
32
business_objects/braille_proficiency_level.py
Normal file
@@ -0,0 +1,32 @@
|
||||
"""
|
||||
@author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
"""
|
||||
|
||||
from business_objects.attribute_abstract import Attribute_Abstract
|
||||
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class Braille_Proficiency_Level(Enum):
|
||||
ALPHABET_PUNCTUATION = 1
|
||||
SIMPLE_WORD_AND_GROUPSIGNS = 2
|
||||
LOWER_CONTRACTIONS = 3
|
||||
def minimum():
|
||||
return min([e.value for e in Braille_Proficiency_Level])
|
||||
def maximum():
|
||||
return max([e.value for e in Braille_Proficiency_Level])
|
||||
@staticmethod
|
||||
def get_defaults():
|
||||
return [Braille_Proficiency_Level(e) for e in range(Braille_Proficiency_Level.minimum(), Braille_Proficiency_Level.maximum() + 1)]
|
||||
@staticmethod
|
||||
def get_list_headings():
|
||||
return ['Braille Proficiency Level']
|
||||
def as_row(self):
|
||||
return [self.name]
|
||||
@staticmethod
|
||||
def input_from_console():
|
||||
return Attribute_Abstract.input_from_console(Braille_Proficiency_Level)
|
||||
@staticmethod
|
||||
def input_many_from_console():
|
||||
return Attribute_Abstract.input_many_from_console(Braille_Proficiency_Level)
|
||||
39
business_objects/character_braille.py
Normal file
39
business_objects/character_braille.py
Normal file
@@ -0,0 +1,39 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
@author: Edward Middleton-Smith
|
||||
"""
|
||||
|
||||
|
||||
from typing import Optional, List
|
||||
from pydantic import BaseModel, field_validator
|
||||
|
||||
|
||||
class Character_Braille(BaseModel):
|
||||
plaintext: str
|
||||
list_dots_braille: List[bool]
|
||||
|
||||
def __init__(self, plaintext, list_dots_braille):
|
||||
super().__init__(plaintext=plaintext, list_dots_braille=list_dots_braille)
|
||||
|
||||
@field_validator('list_dots_braille')
|
||||
def validate_list_dots_braille(cls, value):
|
||||
if (len(value) != 6):
|
||||
raise ValueError('List must have rows of 6 colunns')
|
||||
if not all(isinstance(dot, bool) for dot in value):
|
||||
raise ValueError('List must contain only boolean values')
|
||||
return value
|
||||
|
||||
@field_validator('plaintext')
|
||||
def validate_plaintext(cls, value):
|
||||
"""
|
||||
known_translations = Character_Braille.get_Translation_Brailles()
|
||||
if not known_translations['Character_Braille'].apply(lambda x: x.plaintext == value).any():
|
||||
raise ValueError('Plaintext not in known translations')
|
||||
"""
|
||||
return value
|
||||
|
||||
def get_blank_character_Braille():
|
||||
return Character_Braille("BLANK_SPACE", [0, 0, 0, 0, 0, 0])
|
||||
|
||||
def __repr__(self):
|
||||
return f'plaintext = {self.plaintext}, list_dots_braille = {self.list_dots_braille}'
|
||||
290
business_objects/translation_braille.py
Normal file
290
business_objects/translation_braille.py
Normal file
@@ -0,0 +1,290 @@
|
||||
"""
|
||||
@author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
"""
|
||||
|
||||
from business_objects.character_braille import Character_Braille
|
||||
# from business_objects.attribute_abstract import Attribute_Abstract
|
||||
from business_objects.braille_proficiency_level import Braille_Proficiency_Level
|
||||
|
||||
import pandas as pd
|
||||
from typing import Optional, List, ClassVar
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
|
||||
class Translation_Braille(BaseModel):
|
||||
DF_COLUMNS: ClassVar = ['plaintext', 'translation_proficiency_level', 'lists_dots_braille', 'search_key']
|
||||
plaintext: str
|
||||
translation_proficiency_level: Braille_Proficiency_Level
|
||||
braille_text: List[Character_Braille] = []
|
||||
search_key: Optional[str] = None
|
||||
|
||||
def __init__(self, plaintext, translation_proficiency_level, braille_text=[], search_key= None):
|
||||
super().__init__(plaintext=plaintext, translation_proficiency_level=translation_proficiency_level, braille_text=braille_text, search_key=search_key)
|
||||
self.plaintext = self.plaintext.upper()
|
||||
if braille_text == []:
|
||||
self.braille_text = self.translate_text_to_Braille()
|
||||
if search_key is None:
|
||||
self.search_key = plaintext
|
||||
|
||||
def __repr__(self):
|
||||
return f"{self.plaintext} - {self.translation_proficiency_level} - {self.braille_text}"
|
||||
|
||||
def translate_text_to_Braille(self):
|
||||
known_translations = Translation_Braille.get_defaults_DataFrame()
|
||||
# delimiters = Translation_Braille.get_delimiters()
|
||||
braille_text = []
|
||||
max_key_length = known_translations.apply(lambda x: len(x.iloc[3]), axis=1).max()
|
||||
length_plaintext = len(self.plaintext)
|
||||
index_key_start = 0
|
||||
while index_key_start < length_plaintext:
|
||||
found_key = False
|
||||
for key_length in range(min(max_key_length, length_plaintext - index_key_start), 0, -1):
|
||||
key = self.plaintext[index_key_start : index_key_start + key_length]
|
||||
"""if key in delimiters:
|
||||
character_braille = Character_Braille.get_blank_Character_Braille()
|
||||
character_braille.plaintext = delimiters[key]
|
||||
braille_text.append(character_braille)
|
||||
index_key_start += key_length
|
||||
continue
|
||||
el"""
|
||||
if key == "@?NOTHING":
|
||||
index_key_start += key_length
|
||||
found_key = True
|
||||
break
|
||||
elif key == "@?NEWLINE":
|
||||
character_braille = Character_Braille("NEWLINE", [0, 0, 0, 0, 0, 0])
|
||||
braille_text.append(character_braille)
|
||||
index_key_start += key_length
|
||||
found_key = True
|
||||
break
|
||||
if known_translations.apply(lambda x: x.iloc[3] == key and x.iloc[1].value <= self.translation_proficiency_level.value, axis=1).any():
|
||||
translation_Braille = known_translations.apply(lambda x: x if (x.iloc[3] == key and x.iloc[1].value <= self.translation_proficiency_level.value) else None, axis=1).dropna().values.tolist()[0]
|
||||
braille_text.append(translation_Braille.iloc[2])
|
||||
index_key_start += key_length
|
||||
found_key = True
|
||||
break
|
||||
if not found_key:
|
||||
raise KeyError("Key not found starting from: ", key)
|
||||
return braille_text
|
||||
|
||||
def get_delimiters():
|
||||
return {
|
||||
"@?NUM" : "NUMBER",
|
||||
"@?NOTHING" : "",
|
||||
#" " : "",
|
||||
'"@?BO' : '"',
|
||||
'"@?BC' : '"',
|
||||
"-@?S" : "-",
|
||||
"-@?L" : "-",
|
||||
"/@?B" : "/",
|
||||
"[@?BPH" : "[",
|
||||
"]@?BPH" : "]",
|
||||
"[@?BSQ" : "[",
|
||||
"]@?BSQ" : "]",
|
||||
"'@?BO" : "'",
|
||||
"'@?BC" : "'",
|
||||
"@?LET" : "LET",
|
||||
"@?CAPS" : "CAPS",
|
||||
"@?EMPH" : "EMPH",
|
||||
"@?ABBREV1" : "ABBREV",
|
||||
"@?ABBREV2" : "ABBREV",
|
||||
"@?ABBREV3" : "ABBREV",
|
||||
"@?ABBREV4" : "ABBREV",
|
||||
}
|
||||
|
||||
def get_defaults_DataFrame():
|
||||
df = pd.DataFrame(data=[
|
||||
["A", Braille_Proficiency_Level(1), [[1, 0, 0, 0, 0, 0]], None],
|
||||
["B", Braille_Proficiency_Level(1), [[1, 1, 0, 0, 0, 0]], None],
|
||||
["C", Braille_Proficiency_Level(1), [[1, 0, 0, 1, 0, 0]], None],
|
||||
["D", Braille_Proficiency_Level(1), [[1, 0, 0, 1, 1, 0]], None],
|
||||
["E", Braille_Proficiency_Level(1), [[1, 0, 0, 0, 1, 0]], None],
|
||||
["F", Braille_Proficiency_Level(1), [[1, 1, 0, 1, 0, 0]], None],
|
||||
["G", Braille_Proficiency_Level(1), [[1, 1, 0, 1, 1, 0]], None],
|
||||
["H", Braille_Proficiency_Level(1), [[1, 1, 0, 0, 1, 0]], None],
|
||||
["I", Braille_Proficiency_Level(1), [[0, 1, 0, 1, 0, 0]], None],
|
||||
["J", Braille_Proficiency_Level(1), [[0, 1, 0, 1, 1, 0]], None],
|
||||
["K", Braille_Proficiency_Level(1), [[1, 0, 1, 0, 0, 0]], None],
|
||||
["L", Braille_Proficiency_Level(1), [[1, 1, 1, 0, 0, 0]], None],
|
||||
["M", Braille_Proficiency_Level(1), [[1, 0, 1, 1, 0, 0]], None],
|
||||
["N", Braille_Proficiency_Level(1), [[1, 0, 1, 1, 1, 0]], None],
|
||||
["O", Braille_Proficiency_Level(1), [[1, 0, 1, 0, 1, 0]], None],
|
||||
["P", Braille_Proficiency_Level(1), [[1, 1, 1, 1, 0, 0]], None],
|
||||
["Q", Braille_Proficiency_Level(1), [[1, 1, 1, 1, 1, 0]], None],
|
||||
["R", Braille_Proficiency_Level(1), [[1, 1, 1, 0, 1, 0]], None],
|
||||
["S", Braille_Proficiency_Level(1), [[0, 1, 1, 1, 0, 0]], None],
|
||||
["T", Braille_Proficiency_Level(1), [[0, 1, 1, 1, 1, 0]], None],
|
||||
["U", Braille_Proficiency_Level(1), [[1, 0, 1, 0, 0, 1]], None],
|
||||
["V", Braille_Proficiency_Level(1), [[1, 1, 1, 0, 0, 1]], None],
|
||||
["W", Braille_Proficiency_Level(1), [[0, 1, 0, 1, 1, 1]], None],
|
||||
["X", Braille_Proficiency_Level(1), [[1, 0, 1, 1, 0, 1]], None],
|
||||
["Y", Braille_Proficiency_Level(1), [[1, 0, 1, 1, 1, 1]], None],
|
||||
["Z", Braille_Proficiency_Level(1), [[1, 0, 1, 0, 1, 1]], None],
|
||||
['NUMBER', Braille_Proficiency_Level(1), [[0, 0, 1, 1, 1, 1]], "@?NUM"],
|
||||
#" ", Braille_Proficiency_Level(1), [[0, 0, 0, 0, 0, 0]], None],
|
||||
[",", Braille_Proficiency_Level(1), [[0, 1, 0, 0, 0, 0]], None],
|
||||
[";", Braille_Proficiency_Level(1), [[0, 1, 1, 0, 0, 0]], None],
|
||||
[":", Braille_Proficiency_Level(1), [[0, 1, 0, 0, 1, 0]], None],
|
||||
[".", Braille_Proficiency_Level(1), [[0, 1, 0, 0, 1, 1]], None],
|
||||
["!", Braille_Proficiency_Level(1), [[0, 1, 1, 0, 1, 0]], None],
|
||||
["(", Braille_Proficiency_Level(1), [[0, 1, 1, 0, 1, 1]], None],
|
||||
[")", Braille_Proficiency_Level(1), [[0, 1, 1, 0, 1, 1]], None],
|
||||
["?", Braille_Proficiency_Level(1), [[0, 1, 1, 0, 0, 1]], None],
|
||||
['"', Braille_Proficiency_Level(1), [[0, 1, 1, 0, 0, 1]], '"@?BO'],
|
||||
['"', Braille_Proficiency_Level(1), [[0, 0, 1, 0, 1, 1]], '"@?BC'],
|
||||
["'", Braille_Proficiency_Level(1), [[0, 0, 1, 0, 0, 0]], None],
|
||||
["ABBREV", Braille_Proficiency_Level(1), [[0, 0, 0, 1, 0, 0]], "@?ABBREV1"],
|
||||
["ABBREV", Braille_Proficiency_Level(1), [[0, 0, 0, 1, 1, 0]], "@?ABBREV2"],
|
||||
["ABBREV", Braille_Proficiency_Level(1), [[0, 0, 0, 1, 1, 1]], "@?ABBREV3"],
|
||||
["ABBREV", Braille_Proficiency_Level(1), [[0, 0, 0, 0, 1, 0]], "@?ABBREV4"],
|
||||
["...", Braille_Proficiency_Level(1), [[0, 0, 1, 0, 0, 0], [0, 0, 1, 0, 0, 0], [0, 0, 1, 0, 0, 0]], None],
|
||||
["-", Braille_Proficiency_Level(1), [[0, 0, 1, 0, 0, 1]], None],
|
||||
["-", Braille_Proficiency_Level(1), [[0, 0, 1, 0, 0, 1], [0, 0, 1, 0, 0, 1]], "-@?S"],
|
||||
["-", Braille_Proficiency_Level(1), [[0, 0, 1, 0, 0, 1], [0, 0, 1, 0, 0, 1], [0, 0, 1, 0, 0, 1], [0, 0, 1, 0, 0, 1]], "-@?L"],
|
||||
["/", Braille_Proficiency_Level(1), [[0, 0, 0, 1, 0, 0], [0, 1, 1, 0, 1, 1]], "/@?B"],
|
||||
["\\", Braille_Proficiency_Level(1), [[0, 0, 0, 1, 0, 0], [0, 1, 1, 0, 1, 1]], "\\@?B"],
|
||||
["[", Braille_Proficiency_Level(1), [[0, 0, 0, 1, 1, 0], [0, 1, 1, 0, 1, 1]], "[@?BPH"],
|
||||
["]", Braille_Proficiency_Level(1), [[0, 0, 0, 1, 1, 0], [0, 1, 1, 0, 1, 1]], "]@?BPH"],
|
||||
["<", Braille_Proficiency_Level(1), [[0, 0, 0, 1, 1, 1], [0, 1, 1, 0, 1, 1]], None],
|
||||
[">", Braille_Proficiency_Level(1), [[0, 0, 0, 1, 1, 1], [0, 1, 1, 0, 1, 1]], None],
|
||||
["/", Braille_Proficiency_Level(1), [[0, 0, 0, 1, 1, 1], [0, 0, 1, 1, 0, 0]], None],
|
||||
["{", Braille_Proficiency_Level(1), [[0, 0, 0, 1, 0, 1], [0, 1, 1, 0, 1, 1]], None],
|
||||
["}", Braille_Proficiency_Level(1), [[0, 0, 0, 1, 0, 1], [0, 1, 1, 0, 1, 1]], None],
|
||||
["[", Braille_Proficiency_Level(1), [[0, 0, 0, 0, 0, 1], [0, 1, 1, 0, 1, 1]], "[@?BSQ"],
|
||||
["]", Braille_Proficiency_Level(1), [[0, 1, 1, 0, 1, 1], [0, 0, 0, 0, 0, 1]], "]@?BSQ"],
|
||||
["'", Braille_Proficiency_Level(1), [[0, 0, 0, 0, 0, 1], [0, 1, 1, 0, 0, 1]], "'@?BO"],
|
||||
["'", Braille_Proficiency_Level(1), [[0, 1, 1, 0, 0, 1], [0, 0, 0, 0, 0, 1]], "'@?BC"],
|
||||
# oldbrailledict_2 = {
|
||||
# Simple Upper Wordsigns
|
||||
["BUT", Braille_Proficiency_Level(2), [[1, 1, 0, 0, 0, 0]], None],
|
||||
["CAN", Braille_Proficiency_Level(2), [[1, 0, 0, 1, 0, 0]], None],
|
||||
["DO", Braille_Proficiency_Level(2), [[1, 0, 0, 1, 1, 0]], None],
|
||||
["EVERY", Braille_Proficiency_Level(2), [[1, 0, 0, 0, 1, 0]], None],
|
||||
["FROM", Braille_Proficiency_Level(2), [[1, 1, 0, 1, 0, 0]], None],
|
||||
["GO", Braille_Proficiency_Level(2), [[1, 1, 0, 1, 1, 0]], None],
|
||||
["HAVE", Braille_Proficiency_Level(2), [[1, 1, 0, 0, 1, 0]], None],
|
||||
["JUST", Braille_Proficiency_Level(2), [[0, 1, 0, 1, 1, 0]], None],
|
||||
["KNOWLEDGE", Braille_Proficiency_Level(2), [[1, 0, 1, 0, 0, 0]], None],
|
||||
["LIKE", Braille_Proficiency_Level(2), [[1, 1, 1, 0, 0, 0]], None],
|
||||
["MORE", Braille_Proficiency_Level(2), [[1, 0, 1, 1, 0, 0]], None],
|
||||
["NOT", Braille_Proficiency_Level(2), [[1, 0, 1, 1, 1, 0]], None],
|
||||
["PEOPLE", Braille_Proficiency_Level(2), [[1, 1, 1, 1, 0, 0]], None],
|
||||
["QUITE", Braille_Proficiency_Level(2), [[1, 1, 1, 1, 1, 0]], None],
|
||||
["RATHER", Braille_Proficiency_Level(2), [[1, 1, 1, 0, 1, 0]], None],
|
||||
["SO", Braille_Proficiency_Level(2), [[0, 1, 1, 1, 0, 0]], None],
|
||||
["THAT", Braille_Proficiency_Level(2), [[0, 1, 1, 1, 1, 0]], None],
|
||||
["US", Braille_Proficiency_Level(2), [[1, 0, 1, 0, 0, 1]], None],
|
||||
["VERY", Braille_Proficiency_Level(2), [[1, 1, 1, 0, 0, 1]], None],
|
||||
["WILL", Braille_Proficiency_Level(2), [[0, 1, 0, 1, 1, 1]], None],
|
||||
["IT", Braille_Proficiency_Level(2), [[1, 0, 1, 1, 0, 1]], None],
|
||||
["YOU", Braille_Proficiency_Level(2), [[1, 0, 1, 1, 1, 1]], None],
|
||||
["AS", Braille_Proficiency_Level(2), [[1, 0, 1, 0, 1, 1]], None],
|
||||
["CHILD", Braille_Proficiency_Level(2), [[1, 0, 0, 0, 0, 1]], None],
|
||||
["SHALL", Braille_Proficiency_Level(2), [[1, 0, 0, 1, 0, 1]], None],
|
||||
["THIS", Braille_Proficiency_Level(2), [[1, 0, 0, 1, 1, 1]], None],
|
||||
["WHICH", Braille_Proficiency_Level(2), [[1, 0, 0, 0, 1, 1]], None],
|
||||
["OUT", Braille_Proficiency_Level(2), [[1, 1, 0, 0, 1, 1]], None],
|
||||
["STILL", Braille_Proficiency_Level(2), [[0, 0, 1, 1, 0, 0]], None],
|
||||
# Simple Upper Groupsigns
|
||||
["AND", Braille_Proficiency_Level(2), [[1, 1, 1, 1, 0, 1]], None],
|
||||
["FOR", Braille_Proficiency_Level(2), [[1, 1, 1, 1, 1, 1]], None],
|
||||
["OF", Braille_Proficiency_Level(2), [[1, 1, 1, 0, 1, 1]], None],
|
||||
["THE", Braille_Proficiency_Level(2), [[0, 1, 1, 1, 0, 1]], None],
|
||||
["WITH", Braille_Proficiency_Level(2), [[0, 1, 1, 1, 1, 1]], None],
|
||||
["CH", Braille_Proficiency_Level(2), [[1, 0, 0, 0, 0, 1]], None],
|
||||
["GH", Braille_Proficiency_Level(2), [[1, 1, 0, 0, 0, 1]], None],
|
||||
["SH", Braille_Proficiency_Level(2), [[1, 0, 0, 1, 0, 1]], None],
|
||||
["TH", Braille_Proficiency_Level(2), [[1, 0, 0, 1, 1, 1]], None],
|
||||
["WH", Braille_Proficiency_Level(2), [[1, 0, 0, 0, 1, 1]], None],
|
||||
["ED", Braille_Proficiency_Level(2), [[1, 1, 0, 1, 0, 1]], None],
|
||||
["ER", Braille_Proficiency_Level(2), [[1, 1, 0, 1, 1, 1]], None],
|
||||
["OU", Braille_Proficiency_Level(2), [[1, 1, 0, 0, 1, 1]], None],
|
||||
["OW", Braille_Proficiency_Level(2), [[0, 1, 0, 1, 0, 1]], None],
|
||||
["ST", Braille_Proficiency_Level(2), [[0, 0, 1, 1, 0, 0]], None],
|
||||
["AR", Braille_Proficiency_Level(2), [[0, 0, 1, 1, 1, 0]], None],
|
||||
["ING", Braille_Proficiency_Level(2), [[0, 0, 1, 1, 0, 1]], None],
|
||||
["BLE", Braille_Proficiency_Level(2), [[0, 0, 1, 1, 1, 1]], None],
|
||||
# oldbrailledict_3 = {
|
||||
# Lower Contractions
|
||||
# Initial Groupsigns
|
||||
["BE", Braille_Proficiency_Level(3), [[0, 1, 1, 0, 0, 0]], None],
|
||||
["COM", Braille_Proficiency_Level(3), [[0, 0, 1, 0, 0, 1]], None],
|
||||
["CON", Braille_Proficiency_Level(3), [[0, 1, 0, 0, 1, 0]], None],
|
||||
["DIS", Braille_Proficiency_Level(3), [[0, 1, 0, 0, 1, 1]], None],
|
||||
# Initial-Medial-Terminal Groupsigns
|
||||
["EN", Braille_Proficiency_Level(3), [[0, 1, 0, 0, 0, 1]], None],
|
||||
["IN", Braille_Proficiency_Level(3), [[0, 0, 1, 0, 1, 0]], None],
|
||||
# Medial Groupsigns
|
||||
["EA", Braille_Proficiency_Level(3), [[0, 1, 0, 0, 0, 0]], None],
|
||||
["BB", Braille_Proficiency_Level(3), [[0, 1, 1, 0, 0, 0]], None],
|
||||
["CC", Braille_Proficiency_Level(3), [[0, 1, 0, 0, 1, 0]], None],
|
||||
["DD", Braille_Proficiency_Level(3), [[0, 1, 0, 0, 1, 1]], None],
|
||||
["FF", Braille_Proficiency_Level(3), [[0, 1, 1, 0, 1, 0]], None],
|
||||
["GG", Braille_Proficiency_Level(3), [[0, 1, 1, 0, 1, 1]], None],
|
||||
# Wordsigns
|
||||
["ENOUGH", Braille_Proficiency_Level(3), [[0, 1, 0, 0, 0, 1]], None],
|
||||
["TO", Braille_Proficiency_Level(3), [[0, 1, 1, 0, 1, 0]], None],
|
||||
["WERE", Braille_Proficiency_Level(3), [[0, 1, 1, 0 , 1, 1]], None],
|
||||
["HIS", Braille_Proficiency_Level(3), [[0, 1, 1, 0, 0, 1]], None],
|
||||
["INTO", Braille_Proficiency_Level(3), [[0, 0, 1, 0, 1, 0], [0, 1, 1, 0, 1, 0]], None], #(sequenced)
|
||||
["BY", Braille_Proficiency_Level(3), [[0, 0, 1, 0, 1, 1]], None], #(sequenced)
|
||||
["WAS", Braille_Proficiency_Level(3), [[0, 0 , 1, 0 , 1, 1]], None],
|
||||
|
||||
# Modifiers
|
||||
["LET", Braille_Proficiency_Level(3), [[0, 0, 0, 0, 1, 1]], "@?LET"],
|
||||
["CAPS", Braille_Proficiency_Level(3), [[0, 0, 0, 0, 0, 1]], "@?CAPS"],
|
||||
["EMPH", Braille_Proficiency_Level(3), [[0, 0, 0, 1, 0, 1]], "@?EMPH"],
|
||||
[" ", Braille_Proficiency_Level(1), [[0, 0, 0, 0, 0, 0]], "@?BLANK_SPACE"],
|
||||
], columns=Translation_Braille.DF_COLUMNS) # Translation_Braille.__name__])
|
||||
df.loc[df["search_key"].isnull(), "search_key"] = df["plaintext"]
|
||||
return df
|
||||
|
||||
@staticmethod
|
||||
def get_defaults():
|
||||
defaults_dataframe = Translation_Braille.get_defaults_DataFrame()
|
||||
return defaults_dataframe # pd.DataFrame(data={Translation_Braille.__name__: defaults_dataframe.apply(lambda x: Translation_Braille(x.iloc[0], x.iloc[1], [Character_Braille(x.iloc[0] if index_y == 0 else '', x.iloc[2][index_y]) for index_y in range(len(x.iloc[2]))], x.iloc[3]), axis=1)})
|
||||
|
||||
@staticmethod
|
||||
def get_list_headings():
|
||||
return [str.replace(heading, '_', ' ') for heading in Translation_Braille.DF_COLUMNS]
|
||||
|
||||
def as_row(self):
|
||||
return [self.plaintext, self.translation_proficiency_level, self.braille_text, self.search_key]
|
||||
|
||||
@staticmethod
|
||||
def input_from_console():
|
||||
print()
|
||||
print("Braille Translation Options:")
|
||||
while True:
|
||||
plaintext = str(input("Enter plaintext: "))
|
||||
if plaintext == "#!ERRORCODE!#": exit()
|
||||
try:
|
||||
temp = Translation_Braille(plaintext, Braille_Proficiency_Level(1))
|
||||
translation_proficiency_level = Braille_Proficiency_Level.input_from_console()
|
||||
try:
|
||||
return Translation_Braille(plaintext, translation_proficiency_level)
|
||||
except:
|
||||
print("Invalid. Please try again.")
|
||||
except:
|
||||
print("Invalid. Please try again.")
|
||||
|
||||
def print(self):
|
||||
print(f'''Translation:
|
||||
- Plaintext = {self.plaintext}
|
||||
- Proficiency level = {self.translation_proficiency_level.name}
|
||||
- Braille = {self.braille_text}
|
||||
''')
|
||||
|
||||
'''
|
||||
@classmethod
|
||||
def from_DataFrame_tuple(cls, dataframe_tuple):
|
||||
index, row_tuple = dataframe_tuple
|
||||
# plaintext, translation_proficiency_level, braille, search_key = index
|
||||
return row_tuple # cls(plaintext, translation_proficiency_level, braille, search_key)
|
||||
'''
|
||||
@classmethod
|
||||
def from_Series(cls, series):
|
||||
print(series.tolist())
|
||||
return cls(series.iloc[0], series.iloc[1], series.iloc[2], series.iloc[3])
|
||||
Reference in New Issue
Block a user