Spaces:
Sleeping
Sleeping
Update convert.py
Browse files- convert.py +32 -23
convert.py
CHANGED
@@ -19,6 +19,7 @@ def braille_to_text(braille_unicode: str) -> str:
|
|
19 |
"""
|
20 |
# Braille to text mapping for basic alphabet
|
21 |
braille_to_text_map = {
|
|
|
22 |
'⠁': 'a', '⠃': 'b', '⠉': 'c', '⠙': 'd', '⠑': 'e',
|
23 |
'⠋': 'f', '⠛': 'g', '⠓': 'h', '⠊': 'i', '⠚': 'j',
|
24 |
'⠅': 'k', '⠇': 'l', '⠍': 'm', '⠝': 'n', '⠕': 'o',
|
@@ -26,19 +27,29 @@ def braille_to_text(braille_unicode: str) -> str:
|
|
26 |
'⠥': 'u', '⠧': 'v', '⠺': 'w', '⠭': 'x', '⠽': 'y',
|
27 |
'⠵': 'z',
|
28 |
|
29 |
-
#
|
30 |
-
'
|
31 |
-
'
|
|
|
|
|
|
|
|
|
32 |
|
33 |
# Common punctuation
|
34 |
'⠀': ' ', # space
|
35 |
'⠲': '.', '⠂': ',', '⠖': ';', '⠒': ':', '⠦': '?',
|
36 |
-
'
|
37 |
'⠣': '(', '⠜': ')',
|
38 |
|
39 |
-
# Special indicators
|
40 |
-
'⠼': '
|
41 |
-
'⠠': '', # capital indicator (
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
}
|
43 |
|
44 |
result = ""
|
@@ -62,28 +73,26 @@ def braille_to_text(braille_unicode: str) -> str:
|
|
62 |
continue
|
63 |
|
64 |
# Convert current character
|
65 |
-
if char in
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
}
|
72 |
-
result += number_map[char]
|
73 |
-
else:
|
74 |
-
text_char = braille_to_text_map[char]
|
75 |
if capitalize_next and text_char.isalpha():
|
76 |
result += text_char.upper()
|
77 |
capitalize_next = False
|
78 |
else:
|
79 |
result += text_char
|
80 |
-
|
81 |
-
# Reset number mode after non-number character
|
82 |
-
if char == '⠀' or not char in '⠁⠃⠉⠙⠑⠋⠛⠓⠊⠚':
|
83 |
-
number_mode = False
|
84 |
else:
|
85 |
-
# Unknown braille character
|
86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
|
88 |
i += 1
|
89 |
|
|
|
19 |
"""
|
20 |
# Braille to text mapping for basic alphabet
|
21 |
braille_to_text_map = {
|
22 |
+
# Basic alphabet (a-z)
|
23 |
'⠁': 'a', '⠃': 'b', '⠉': 'c', '⠙': 'd', '⠑': 'e',
|
24 |
'⠋': 'f', '⠛': 'g', '⠓': 'h', '⠊': 'i', '⠚': 'j',
|
25 |
'⠅': 'k', '⠇': 'l', '⠍': 'm', '⠝': 'n', '⠕': 'o',
|
|
|
27 |
'⠥': 'u', '⠧': 'v', '⠺': 'w', '⠭': 'x', '⠽': 'y',
|
28 |
'⠵': 'z',
|
29 |
|
30 |
+
# Additional common braille patterns
|
31 |
+
'⠪': 'u', # Alternative representation for 'u'
|
32 |
+
'⠳': 'ou', # Common digraph
|
33 |
+
'⠡': 'a', # Alternative 'a' pattern
|
34 |
+
'⠣': 'b', # Alternative 'b' pattern
|
35 |
+
'⠧': 'v', # Alternative 'v' pattern
|
36 |
+
'⠯': 'x', # Alternative 'x' pattern
|
37 |
|
38 |
# Common punctuation
|
39 |
'⠀': ' ', # space
|
40 |
'⠲': '.', '⠂': ',', '⠖': ';', '⠒': ':', '⠦': '?',
|
41 |
+
'⠄': "'", '⠤': '-', '⠌': '/',
|
42 |
'⠣': '(', '⠜': ')',
|
43 |
|
44 |
+
# Special indicators (will handle separately)
|
45 |
+
'⠼': '', # number indicator (ignore in output)
|
46 |
+
'⠠': '', # capital indicator (ignore in output)
|
47 |
+
}
|
48 |
+
|
49 |
+
# Numbers when preceded by ⠼
|
50 |
+
number_map = {
|
51 |
+
'⠁': '1', '⠃': '2', '⠉': '3', '⠙': '4', '⠑': '5',
|
52 |
+
'⠋': '6', '⠛': '7', '⠓': '8', '⠊': '9', '⠚': '0'
|
53 |
}
|
54 |
|
55 |
result = ""
|
|
|
73 |
continue
|
74 |
|
75 |
# Convert current character
|
76 |
+
if number_mode and char in number_map:
|
77 |
+
# Convert to numbers when in number mode
|
78 |
+
result += number_map[char]
|
79 |
+
elif char in braille_to_text_map:
|
80 |
+
text_char = braille_to_text_map[char]
|
81 |
+
if text_char: # Only add non-empty characters
|
|
|
|
|
|
|
|
|
82 |
if capitalize_next and text_char.isalpha():
|
83 |
result += text_char.upper()
|
84 |
capitalize_next = False
|
85 |
else:
|
86 |
result += text_char
|
|
|
|
|
|
|
|
|
87 |
else:
|
88 |
+
# Unknown braille character - try to handle it gracefully
|
89 |
+
# For debugging, you might want to see what character is causing issues
|
90 |
+
print(f"Unknown braille character: {char} (Unicode: {ord(char)})")
|
91 |
+
result += '?' # placeholder for unknown characters
|
92 |
+
|
93 |
+
# Reset number mode after space or punctuation
|
94 |
+
if char == '⠀' or char in '⠲⠂⠖⠒⠦⠄⠤⠌':
|
95 |
+
number_mode = False
|
96 |
|
97 |
i += 1
|
98 |
|