79 lines
3.2 KiB
Python
79 lines
3.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
Created on 29/05/2024
|
|
@author: Edward Middleton-Smith
|
|
"""
|
|
|
|
import pandas as pd
|
|
from typing import Optional, List
|
|
from pydantic import BaseModel, conlist, validator, field_validator, validator
|
|
from enum import Enum
|
|
# import argument_validation as av
|
|
import sys
|
|
|
|
|
|
class Character_Braille(BaseModel):
|
|
plaintext: str # English plaintext key
|
|
list_dots_braille: List[bool] # braille: list # list[list[int]] # Braille translation of plaintext
|
|
|
|
def __init__(self, plaintext, list_dots_braille):
|
|
super().__init__(plaintext=plaintext, list_dots_braille=list_dots_braille)
|
|
|
|
@validator('list_dots_braille')
|
|
def validate_list_dots_braille(cls, value):
|
|
"""
|
|
if (len(value) != 6):
|
|
raise ValueError('List must have 6 elements')
|
|
for row in 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
|
|
|
|
@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
|
|
"""
|
|
@validator('matrix_braille_dots')
|
|
def validate_matrix_braille_dots(cls, value):
|
|
if (len(value) != 3):
|
|
raise ValueError('Matrix must have 3 rows')
|
|
for row in value:
|
|
if (len(row) != 2):
|
|
raise ValueError('Matrix must have rows of 2 colunns')
|
|
if not all(isinstance(item, bool) for item in row):
|
|
raise ValueError('Matrix must contain only boolean values')
|
|
return value
|
|
|
|
@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]) # , Enum_Braille_Proficiency_Level(0)
|
|
|
|
def __repr__(self):
|
|
# return f"key = {self.key}, level = {self.level}, braille = {self.braille}, plaintext = {self.plaintext}"
|
|
return f'plaintext = {self.plaintext}, list_dots_braille = {self.list_dots_braille}' # , translation_proficiency_level = {self.translation_proficiency_level}
|
|
|
|
# def query_lvl(self):
|
|
# return ' & '.join(["{}=='{}'".format(key, value)
|
|
# for key, value in self.__dict__.items()
|
|
# if not value is None])
|
|
"""
|
|
def as_dict(self):
|
|
# return {'key': self.key, 'level': self.level, 'braille': self.braille, 'plaintext': self.plaintext}
|
|
return {'plaintext': self.plaintext, 'translation_proficiency_level': self.translation_proficiency_level, 'matrix_dots_braille': self.matrix_dots_braille}
|
|
"""
|