braillebase 0.3.0__tar.gz → 0.3.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: braillebase
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: A complete and extensible Unicode Braille processing library.
5
5
  Author: Nagao Yuji
6
6
  License: MIT
@@ -34,19 +34,128 @@ To support this flexibility, the Braille Base API provides several methods for m
34
34
  </p>
35
35
 
36
36
  ### Group Identification
37
- The methods in this group include an argument called type, which determines which map the operation will target. Each value corresponds to a specific group, as described below:
37
+ The methods in this group include an argument called collection, which determines which map the operation will target. Each value corresponds to a specific group, as described below:
38
38
 
39
39
  <p>
40
40
  <h4>0 — Default</h4>
41
41
  The central registry and translation base of Braille Base. All records are stored in this group. The other groups act as auxiliary rule-identification mechanisms, allowing the engine to determine in advance which processing rules should be applied to each character or expression.
42
42
  <h4>1 — Uppercase</h4>
43
43
  Used to register uppercase letters, allowing the engine to identify when translation requires the application of an uppercase indicator.
44
- <h4>2 — CJK</h4>
44
+ <h4>2 — Syllabic</h4>
45
45
  Used to register characters and writing systems that follow syllabic rules, such as Hiragana, Jamul, and Pinyin.
46
46
  <h4>3 — RTL</h4>
47
47
  Used to register languages whose writing systems follow a right-to-left (RTL) direction.
48
48
  <h4>4 — Symbol</h4>
49
- Used to register symbols, characters, and special expressions that take priority over all other interpretation rules. It allows complete expressions to be recognized as a single translation unit, preventing their individual characters from being interpreted separately.</p>
49
+ Used to register symbols, characters, and special expressions that take priority over all other interpretation rules. It allows complete expressions to be recognized as a single translation unit, preventing their individual characters from being interpreted separately.
50
+ </p>
51
+
52
+ ### Registry Group Constants
53
+ ```python
54
+ bbDEFAULT = 0
55
+ bbUPPERCASE = 1
56
+ bbSYLLABIC = 2
57
+ bbRTL = 3
58
+ bbSYMBOL = 4
59
+ ```
60
+
61
+ As described earlier, registry groups are identified by indices ranging from 0 to 4. However, there is no need to memorize these values. Braille Base exposes predefined constants that map directly to each registry group. For example, use bbUPPERCASE instead of 1.
62
+
63
+ - In practice, both the numeric identifier and its corresponding constant can be used interchangeably when registering or editing Braille entries. However, using constants is recommended because it improves code readability and makes maintenance easier.
64
+
65
+ ```python
66
+ from braillebase import BrailleBase
67
+
68
+ class BrailleBaseMyLanguage(BrailleBase):
69
+ def __init__(self):
70
+
71
+ self.append_braille_letter("CH", ["⠡"], bbUPPERCASE)
72
+ self.append_braille_letter("SH", ["⠩"], bbUPPERCASE)
73
+ self.append_braille_letter("TH", ["⠹"], 1)
74
+ self.append_braille_letter("WH", ["⠱"], 1)
75
+ self.append_braille_letter("あ", ["⠁"],bbSYLLABIC)
76
+ self.append_braille_letter("い", ["⠃"],bbSYLLABIC)
77
+ self.append_braille_letter("う", ["⠉"],2)
78
+
79
+ self.edit_braille_letter("え", ["⠋"],bbSYLLABIC)
80
+ self.edit_braille_letter("お", ["⠊"],2)
81
+ ```
82
+
83
+ - The methods in Registry Group (0001) are intuitive and self-explanatory. Nevertheless, the following section provides a brief overview of each method signature.
84
+ ```python
85
+ Registers a new letter and its Braille representation. Return: None
86
+ def append_braille_letter(self, letter: str, braille_list: list, collection = bbDEFAULT):​‌
87
+ ```
88
+ ```python
89
+ Retrieves all Braille cells associated with a letter. Return: list
90
+ def get_brailles_with_letter(self, letter: str):​‌
91
+ ```
92
+ ```python
93
+ Checks whether a letter is registered. Return: bool
94
+ def has_letter(self, letter: str, collection = bbDEFAULT) -> bool:​‌
95
+ ```
96
+ ```python
97
+ Removes a registered letter. Return: bool (True if removed)
98
+ def remove_letter(self, letter: str, collection = bbDEFAULT) -> bool:​‌
99
+ ```
100
+ ```python
101
+ Returns all registered letters from a group. Return: list
102
+ def get_registered_letters(self, collection = bbDEFAULT):​‌
103
+ ```
104
+ ```python
105
+ Registers multiple letters at once. Return: None
106
+ def append_multiple_braille_letters(self, letter_braillelist_pattern: list):​‌
107
+ ```
108
+ ```python
109
+ Imports letter registrations from a data source. Return: None
110
+ def append_braille_letter_IO(self, target_data_path: str):​‌
111
+ ```
112
+ ```python
113
+ Updates the Braille representation of a registered letter. Return: None
114
+ def edit_braille_letter(self, letter: str, new_braille_list: list, collection = bbDEFAULT):
115
+ ```
116
+ ### append_braille_letter_IO
117
+ - The append_braille_letter_IO method accepts only one argument, which is the path to the file containing the data. The API supports only three data formats: JSON, XML, and CSV.
118
+
119
+ ```json
120
+ JSON
121
+ [
122
+ {
123
+ "letter": "a",
124
+ "braille": "⠁,⠁",
125
+ "pattern": 0
126
+ },
127
+ {
128
+ "letter": "b",
129
+ "braille": "⠟,⠟,⠟",
130
+ "pattern": 0
131
+ }
132
+ ]
133
+ ```
134
+
135
+ ```xml
136
+ XML
137
+ <?xml version="1.0" encoding="utf-8"?>
138
+ <braille_append>
139
+ <item>
140
+ <letter>a</letter>
141
+ <braille>⠁,⠁</braille>
142
+ <pattern>0</pattern>
143
+ </item>
144
+
145
+ <item>
146
+ <letter>b</letter>
147
+ <braille>⠟,⠟,⠟</braille>
148
+ <pattern>0</pattern>
149
+ </item>
150
+ </braille_append>
151
+ ```
152
+ ```csv
153
+ CSV
154
+ a,"⠁,⠁",0
155
+ b,"⠟,⠟,⠟",0
156
+ ```
157
+ - The file data does not contain a header. You must provide the character, the Braille representation, and the group using its numeric identifier, following the format demonstrated in the examples. The group field cannot be omitted, so make sure to specify the correct group for each entry.
158
+ - For more information on how to create JSON, XML, or CSV files, please refer directly to the BrailleBaseIO documentation.
50
159
 
51
160
  # documentation under development.# Braille Base
52
161
  # Old Doc
@@ -15,19 +15,128 @@ To support this flexibility, the Braille Base API provides several methods for m
15
15
  </p>
16
16
 
17
17
  ### Group Identification
18
- The methods in this group include an argument called type, which determines which map the operation will target. Each value corresponds to a specific group, as described below:
18
+ The methods in this group include an argument called collection, which determines which map the operation will target. Each value corresponds to a specific group, as described below:
19
19
 
20
20
  <p>
21
21
  <h4>0 — Default</h4>
22
22
  The central registry and translation base of Braille Base. All records are stored in this group. The other groups act as auxiliary rule-identification mechanisms, allowing the engine to determine in advance which processing rules should be applied to each character or expression.
23
23
  <h4>1 — Uppercase</h4>
24
24
  Used to register uppercase letters, allowing the engine to identify when translation requires the application of an uppercase indicator.
25
- <h4>2 — CJK</h4>
25
+ <h4>2 — Syllabic</h4>
26
26
  Used to register characters and writing systems that follow syllabic rules, such as Hiragana, Jamul, and Pinyin.
27
27
  <h4>3 — RTL</h4>
28
28
  Used to register languages whose writing systems follow a right-to-left (RTL) direction.
29
29
  <h4>4 — Symbol</h4>
30
- Used to register symbols, characters, and special expressions that take priority over all other interpretation rules. It allows complete expressions to be recognized as a single translation unit, preventing their individual characters from being interpreted separately.</p>
30
+ Used to register symbols, characters, and special expressions that take priority over all other interpretation rules. It allows complete expressions to be recognized as a single translation unit, preventing their individual characters from being interpreted separately.
31
+ </p>
32
+
33
+ ### Registry Group Constants
34
+ ```python
35
+ bbDEFAULT = 0
36
+ bbUPPERCASE = 1
37
+ bbSYLLABIC = 2
38
+ bbRTL = 3
39
+ bbSYMBOL = 4
40
+ ```
41
+
42
+ As described earlier, registry groups are identified by indices ranging from 0 to 4. However, there is no need to memorize these values. Braille Base exposes predefined constants that map directly to each registry group. For example, use bbUPPERCASE instead of 1.
43
+
44
+ - In practice, both the numeric identifier and its corresponding constant can be used interchangeably when registering or editing Braille entries. However, using constants is recommended because it improves code readability and makes maintenance easier.
45
+
46
+ ```python
47
+ from braillebase import BrailleBase
48
+
49
+ class BrailleBaseMyLanguage(BrailleBase):
50
+ def __init__(self):
51
+
52
+ self.append_braille_letter("CH", ["⠡"], bbUPPERCASE)
53
+ self.append_braille_letter("SH", ["⠩"], bbUPPERCASE)
54
+ self.append_braille_letter("TH", ["⠹"], 1)
55
+ self.append_braille_letter("WH", ["⠱"], 1)
56
+ self.append_braille_letter("あ", ["⠁"],bbSYLLABIC)
57
+ self.append_braille_letter("い", ["⠃"],bbSYLLABIC)
58
+ self.append_braille_letter("う", ["⠉"],2)
59
+
60
+ self.edit_braille_letter("え", ["⠋"],bbSYLLABIC)
61
+ self.edit_braille_letter("お", ["⠊"],2)
62
+ ```
63
+
64
+ - The methods in Registry Group (0001) are intuitive and self-explanatory. Nevertheless, the following section provides a brief overview of each method signature.
65
+ ```python
66
+ Registers a new letter and its Braille representation. Return: None
67
+ def append_braille_letter(self, letter: str, braille_list: list, collection = bbDEFAULT):​‌
68
+ ```
69
+ ```python
70
+ Retrieves all Braille cells associated with a letter. Return: list
71
+ def get_brailles_with_letter(self, letter: str):​‌
72
+ ```
73
+ ```python
74
+ Checks whether a letter is registered. Return: bool
75
+ def has_letter(self, letter: str, collection = bbDEFAULT) -> bool:​‌
76
+ ```
77
+ ```python
78
+ Removes a registered letter. Return: bool (True if removed)
79
+ def remove_letter(self, letter: str, collection = bbDEFAULT) -> bool:​‌
80
+ ```
81
+ ```python
82
+ Returns all registered letters from a group. Return: list
83
+ def get_registered_letters(self, collection = bbDEFAULT):​‌
84
+ ```
85
+ ```python
86
+ Registers multiple letters at once. Return: None
87
+ def append_multiple_braille_letters(self, letter_braillelist_pattern: list):​‌
88
+ ```
89
+ ```python
90
+ Imports letter registrations from a data source. Return: None
91
+ def append_braille_letter_IO(self, target_data_path: str):​‌
92
+ ```
93
+ ```python
94
+ Updates the Braille representation of a registered letter. Return: None
95
+ def edit_braille_letter(self, letter: str, new_braille_list: list, collection = bbDEFAULT):
96
+ ```
97
+ ### append_braille_letter_IO
98
+ - The append_braille_letter_IO method accepts only one argument, which is the path to the file containing the data. The API supports only three data formats: JSON, XML, and CSV.
99
+
100
+ ```json
101
+ JSON
102
+ [
103
+ {
104
+ "letter": "a",
105
+ "braille": "⠁,⠁",
106
+ "pattern": 0
107
+ },
108
+ {
109
+ "letter": "b",
110
+ "braille": "⠟,⠟,⠟",
111
+ "pattern": 0
112
+ }
113
+ ]
114
+ ```
115
+
116
+ ```xml
117
+ XML
118
+ <?xml version="1.0" encoding="utf-8"?>
119
+ <braille_append>
120
+ <item>
121
+ <letter>a</letter>
122
+ <braille>⠁,⠁</braille>
123
+ <pattern>0</pattern>
124
+ </item>
125
+
126
+ <item>
127
+ <letter>b</letter>
128
+ <braille>⠟,⠟,⠟</braille>
129
+ <pattern>0</pattern>
130
+ </item>
131
+ </braille_append>
132
+ ```
133
+ ```csv
134
+ CSV
135
+ a,"⠁,⠁",0
136
+ b,"⠟,⠟,⠟",0
137
+ ```
138
+ - The file data does not contain a header. You must provide the character, the Braille representation, and the group using its numeric identifier, following the format demonstrated in the examples. The group field cannot be omitted, so make sure to specify the correct group for each entry.
139
+ - For more information on how to create JSON, XML, or CSV files, please refer directly to the BrailleBaseIO documentation.
31
140
 
32
141
  # documentation under development.# Braille Base
33
142
  # Old Doc
@@ -8,17 +8,17 @@ class BrailleBase:
8
8
 
9
9
 
10
10
  # self.__letter_brailles: dict[str, list[str]]
11
- # self.__letter_special_braille_rules_simbol: dict[str, list[str]]
11
+ # self.__letter_special_braille_rules_symbol: dict[str, list[str]]
12
12
  # self.__letter_special_braille_rules_uppercase: dict[str, list[str]]
13
- # self.__letter_special_braille_rules_CJK: dict[str, list[str]]
13
+ # self.__letter_special_braille_rules_syllabic: dict[str, list[str]]
14
14
  # self.__letter_special_braille_rules_RTL: dict[str, list[str]]
15
15
 
16
16
 
17
- # self.__braille_rules_simbol: str
17
+ # self.__braille_rules_symbol: str
18
18
  # self.__braille_rules_uppercase: str
19
19
  # self.__multi_braille_rules_uppercase: str
20
20
  # self.__braille_rules_lowcase: str
21
- # self.__braille_rules_CJK: str
21
+ # self.__braille_rules_syllabic: str
22
22
  # self.__braille_rules_RTL: str
23
23
 
24
24
  # self.__BrailleIndex: dict[str, int]
@@ -32,26 +32,34 @@ class BrailleBase:
32
32
  # self.__DotNumberingStringList: list[str]
33
33
  # self.__ReverseBrailleList: list[str]
34
34
 
35
+ bbDEFAULT = 0
36
+ bbUPPERCASE = 1
37
+ bbSYLLABIC = 2
38
+ bbRTL = 3
39
+ bbSYMBOL = 4
40
+
35
41
  #0000
36
42
  def __init__(self):
37
43
  """
38
44
  0000
39
45
  """
40
46
  #Tokenize
41
- #self.configure_token(20)
42
- self._token_size = 14
47
+ self.configure_token(14)
43
48
 
44
49
  self.__letter_brailles: dict[str, list[str]] = {}
45
- #rules simbol
46
- self.__letter_special_braille_rules_simbol: dict[str, list[str]] = {}
47
- self.setting_braille_rules_simbol("")
48
- #rules uppercase
50
+ #SYMBOL
51
+ self.__letter_special_braille_rules_symbol: dict[str, list[str]] = {}
52
+ self.setting_braille_rules_symbol("")
53
+
54
+ #UPPERCASE
49
55
  self.__letter_special_braille_rules_uppercase: dict[str, list[str]] = {}
50
56
  self.setting_braille_rules_uppercase("⠠", "⠠⠠", "⠠⠄")
51
- #rules CJK: China, Japan, Korea
52
- self.__letter_special_braille_rules_CJK: dict[str, list[str]] = {}
53
- self.setting_braille_rules_CJK("")
54
- #rules RTL: Right-to-Left
57
+
58
+ #SYLLABIC
59
+ self.__letter_special_braille_rules_syllabic: dict[str, list[str]] = {}
60
+ self.setting_braille_rules_syllabic("")
61
+
62
+ #RTL: Right-to-Left
55
63
  self.__letter_special_braille_rules_RTL: dict[str, list[str]] = {}
56
64
  self.setting_braille_rules_RTL("")
57
65
 
@@ -65,16 +73,15 @@ class BrailleBase:
65
73
  #---------------------------------------- Registry group (0001) ----------------------------------------
66
74
  #-----Append----------------------------------------------------------------------------------------
67
75
  #0001-AA
68
- def append_braille_letter(self, letter: str, braille_list: list, type = 0):
76
+ def append_braille_letter(self, letter: str, braille_list: list, collection = bbDEFAULT):
69
77
  """
70
- 0001-AA
71
78
  Registers a letter and its associated braille list. If the letter already exists, its mapping is overwritten.
72
79
 
73
- default: 0
74
- rules_uppercase: 1
75
- CJK: 2
80
+ DEFAULT: 0
81
+ UPPERCASE: 1
82
+ SYLLABIC: 2
76
83
  RTL: 3
77
- simbol: 4
84
+ SYMBOL: 4
78
85
  """
79
86
 
80
87
  if not isinstance(letter, str):
@@ -85,21 +92,20 @@ class BrailleBase:
85
92
  self.__validate_braille_list(braille_list)
86
93
  self.__letter_brailles[letter] = braille_list
87
94
 
88
- match type:
95
+ match collection:
89
96
  case 1:
90
97
  self.__letter_special_braille_rules_uppercase[letter] = braille_list
91
98
  case 2:
92
- self.__letter_special_braille_rules_CJK[letter] = braille_list
99
+ self.__letter_special_braille_rules_syllabic[letter] = braille_list
93
100
  case 3:
94
101
  self.__letter_special_braille_rules_RTL[letter] = braille_list
95
102
  case 4:
96
- self.__letter_special_braille_rules_simbol[letter] = braille_list
103
+ self.__letter_special_braille_rules_symbol[letter] = braille_list
97
104
 
98
105
  #-----Get-------------------------------------------------------------------------------------------
99
106
  #0001-B
100
107
  def get_brailles_with_letter(self, letter: str):
101
108
  """
102
- 0001-B
103
109
  This method is the core of the application: it receives a letter* and returns the list of braille symbols associated with it.
104
110
  If the letter* is not registered, an error is raised.
105
111
  """
@@ -111,99 +117,95 @@ class BrailleBase:
111
117
 
112
118
  #-----Has-------------------------------------------------------------------------------------------
113
119
  #0001-CA
114
- def has_letter(self, letter: str, type = 0) -> bool:
120
+ def has_letter(self, letter: str, collection = bbDEFAULT) -> bool:
115
121
  """
116
- 0001-CA
117
122
  Checks whether the given letter is registered in the internal mapping. Returns True or False.
118
123
 
119
- default: 0
120
- rules_uppercase: 1
121
- CJK: 2
124
+ DEFAULT: 0
125
+ UPPERCASE: 1
126
+ SYLLABIC: 2
122
127
  RTL: 3
123
- simbol: 4
128
+ SYMBOL: 4
124
129
  """
125
- match type:
130
+ match collection:
126
131
  case 0:
127
132
  return letter in self.__letter_brailles
128
133
  case 1:
129
134
  return letter in self.__letter_special_braille_rules_uppercase
130
135
  case 2:
131
- return letter in self.__letter_special_braille_rules_CJK
136
+ return letter in self.__letter_special_braille_rules_syllabic
132
137
  case 3:
133
138
  return letter in self.__letter_special_braille_rules_RTL
134
139
  case 4:
135
- return letter in self.__letter_special_braille_rules_simbol
140
+ return letter in self.__letter_special_braille_rules_symbol
136
141
 
137
142
  #-----Remove----------------------------------------------------------------------------------------
138
143
  #0001-D
139
- def remove_letter(self, letter: str, type = 0) -> bool:
144
+ def remove_letter(self, letter: str, collection = bbDEFAULT) -> bool:
140
145
  """
141
- 0001-D
142
146
  Removes the given letter from the internal mapping. Returns True if the letter existed and was removed, otherwise returns False.
143
147
 
144
- default: 0
145
- rules_uppercase: 1
146
- CJK: 2
148
+ DEFAULT: 0
149
+ UPPERCASE: 1
150
+ SYLLABIC: 2
147
151
  RTL: 3
148
- simbol: 4
152
+ SYMBOL: 4
149
153
  """
150
154
  if letter in self.__letter_brailles:
151
155
  del self.__letter_brailles[letter]
152
156
 
153
- match type:
157
+ match collection:
154
158
  case 1:
155
159
  if letter in self.__letter_special_braille_rules_uppercase:
156
160
  del self.__letter_special_braille_rules_uppercase[letter]
157
161
  case 2:
158
- if letter in self.__letter_special_braille_rules_CJK:
159
- del self.__letter_special_braille_rules_CJK[letter]
162
+ if letter in self.__letter_special_braille_rules_syllabic:
163
+ del self.__letter_special_braille_rules_syllabic[letter]
160
164
  case 3:
161
165
  if letter in self.__letter_special_braille_rules_RTL:
162
166
  del self.__letter_special_braille_rules_RTL[letter]
163
167
  case 4:
164
- if letter in self.__letter_special_braille_rules_simbol:
165
- del self.__letter_special_braille_rules_simbol[letter]
168
+ if letter in self.__letter_special_braille_rules_symbol:
169
+ del self.__letter_special_braille_rules_symbol[letter]
166
170
 
167
171
  return True
168
172
  return False
169
173
 
170
174
  #-----Get Registered--------------------------------------------------------------------------------
171
175
  #0001-EA
172
- def get_registered_letters(self, type = 0):
176
+ def get_registered_letters(self, collection = bbDEFAULT):
173
177
  """
174
- 0001-EA
175
178
  Returns a list containing all letters currently registered in the internal mapping.
176
179
 
177
- default: 0
178
- rules_uppercase: 1
179
- CJK: 2
180
+ DEFAULT: 0
181
+ UPPERCASE: 1
182
+ SYLLABIC: 2
180
183
  RTL: 3
181
- simbol: 4
184
+ SYMBOL: 4
182
185
  """
183
186
 
184
- match type:
187
+ match collection:
185
188
  case 0:
186
189
  return list(self.__letter_brailles.keys())
187
190
  case 1:
188
191
  return list(self.__letter_special_braille_rules_uppercase.keys())
189
192
  case 2:
190
- return list(self.__letter_special_braille_rules_CJK.keys())
193
+ return list(self.__letter_special_braille_rules_syllabic.keys())
191
194
  case 3:
192
195
  return list(self.__letter_special_braille_rules_RTL.keys())
193
196
  case 4:
194
- return list(self.__letter_special_braille_rules_simbol.keys())
197
+ return list(self.__letter_special_braille_rules_symbol.keys())
195
198
 
196
199
  #0001-FA
197
200
  def append_multiple_braille_letters(self, letter_braillelist_pattern: list):
198
201
  """
199
- 0001-F
200
202
  Registers multiple letter-to-braille mappings at once. Each entry is validated and added individually.
201
203
 
202
- default: 0
203
- rules_uppercase: 1
204
- CJK: 2
204
+ DEFAULT: 0
205
+ UPPERCASE: 1
206
+ SYLLABIC: 2
205
207
  RTL: 3
206
- simbol: 4
208
+ SYMBOL: 4
207
209
  """
208
210
  if not isinstance(letter_braillelist_pattern, list):
209
211
  raise TypeError("Invalid: append_multiple_braille_letters - #0001-F")
@@ -217,16 +219,15 @@ class BrailleBase:
217
219
 
218
220
 
219
221
  #0001-G
220
- def edit_braille_letter(self, letter: str, new_braille_list: list, type = 0):
222
+ def edit_braille_letter(self, letter: str, new_braille_list: list, collection = bbDEFAULT):
221
223
  """
222
- 0001-G
223
224
  Edits the braille list associated with the given letter. Raises an error if the letter is not registered.
224
225
 
225
- default: 0
226
- rules_uppercase: 1
227
- CJK: 2
226
+ DEFAULT: 0
227
+ UPPERCASE: 1
228
+ SYLLABIC: 2
228
229
  RTL: 3
229
- simbol: 4
230
+ SYMBOL: 4
230
231
  """
231
232
  if letter not in self.__letter_brailles:
232
233
  raise KeyError(f"letter '{letter}' not registered")
@@ -234,21 +235,20 @@ class BrailleBase:
234
235
  self.__validate_braille_list(new_braille_list)
235
236
  self.__letter_brailles[letter] = new_braille_list
236
237
 
237
- match type:
238
+ match collection:
238
239
  case 1:
239
240
  self.__letter_special_braille_rules_uppercase[letter] = new_braille_list
240
241
  case 2:
241
- self.__letter_special_braille_rules_CJK[letter] = new_braille_list
242
+ self.__letter_special_braille_rules_syllabic[letter] = new_braille_list
242
243
  case 3:
243
244
  self.__letter_special_braille_rules_RTL[letter] = new_braille_list
244
245
  case 4:
245
- self.__letter_special_braille_rules_simbol[letter] = new_braille_list
246
+ self.__letter_special_braille_rules_symbol[letter] = new_braille_list
246
247
 
247
248
  #---------------------------------------- Mapping group (0003) ----------------------------------------
248
249
  #0003-A
249
250
  def get_braille_to_index(self, braille: str) -> int:
250
251
  """
251
- 0003-A
252
252
  Receives a character (string), which must be a valid braille symbol,
253
253
  and returns an integer (int) that represents its position in the Unicode braille table (U+2800 to U+283F).
254
254
 
@@ -267,14 +267,12 @@ class BrailleBase:
267
267
  #0003-C
268
268
  def get_index_to_braille(self, index: int) -> str:
269
269
  """
270
- 0003-C
271
270
  """
272
271
  return self.__BrailleList[index]
273
272
 
274
273
  #0003-B
275
274
  def get_braille_list_to_index_list(self, braille_list: list[str]) -> list[int]:
276
275
  """
277
- 0003-B
278
276
  Receives multiple characters (strings), each of which must be a valid braille symbol, and returns a list of integers (int),
279
277
  where each value represents the position of the corresponding symbol in the Unicode braille table (U+2800 to U+283F).
280
278
  """
@@ -475,16 +473,16 @@ class BrailleBase:
475
473
 
476
474
  return result
477
475
 
478
- #----------------------------Prepare Special 04: Simbol ---------------------------
479
- def prepare_special_braille_rules_simbol(self, tokens: list[str]) -> list[str]:
476
+ #----------------------------Prepare Special 04: symbol ---------------------------
477
+ def prepare_special_braille_rules_symbol(self, tokens: list[str]) -> list[str]:
480
478
  result = []
481
479
  previous = False
482
480
 
483
481
  for token in tokens:
484
- is_special = token in self.__letter_special_braille_rules_simbol
482
+ is_special = token in self.__letter_special_braille_rules_symbol
485
483
 
486
484
  if is_special and not previous:
487
- result.append(self.__braille_rules_simbol)
485
+ result.append(self.__braille_rules_symbol)
488
486
 
489
487
  result.append(token)
490
488
  previous = is_special
@@ -492,8 +490,8 @@ class BrailleBase:
492
490
  return result
493
491
 
494
492
 
495
- def setting_braille_rules_simbol(self, braille: str):
496
- self.__braille_rules_simbol = braille
493
+ def setting_braille_rules_symbol(self, braille: str):
494
+ self.__braille_rules_symbol = braille
497
495
 
498
496
  #----------------------------Prepare Special 01: Roma Letter---------------------------
499
497
  def prepare_special_braille_rules_uppercase(self, tokens: list[str]) -> list[str]:
@@ -536,23 +534,23 @@ class BrailleBase:
536
534
 
537
535
  #----------------------------Prepare Special 02---------------------------
538
536
 
539
- def prepare_special_braille_rules_CJK(self, tokens: list[str]) -> list[str]:
537
+ def prepare_special_braille_rules_syllabic(self, tokens: list[str]) -> list[str]:
540
538
  result = []
541
539
  previous = False
542
540
 
543
541
  for token in tokens:
544
- is_special = token in self.__letter_special_braille_rules_CJK
542
+ is_special = token in self.__letter_special_braille_rules_syllabic
545
543
 
546
544
  if is_special and not previous:
547
- result.append(self.__braille_rules_CJK)
545
+ result.append(self.__braille_rules_syllabic)
548
546
 
549
547
  result.append(token)
550
548
  previous = is_special
551
549
 
552
550
  return result
553
551
 
554
- def setting_braille_rules_CJK(self, braille: str):
555
- self.__braille_rules_CJK = braille
552
+ def setting_braille_rules_syllabic(self, braille: str):
553
+ self.__braille_rules_syllabic = braille
556
554
 
557
555
  #----------------------------Prepare Special 02---------------------------
558
556
 
@@ -575,8 +573,45 @@ class BrailleBase:
575
573
  self.__braille_rules_RTL = braille
576
574
 
577
575
  #----------------------------Token---------------------------
576
+ def configure_token(self, token_size: int):
577
+ """
578
+ Defines the maximum token size analyzed by tokenize_text().
579
+
580
+ Higher values allow longer tokens to be recognized, but require
581
+ more checks during tokenization. To use all records from
582
+ BrailleBaseUniversalSet, it is recommended to keep this value
583
+ equal to or greater than the length of the longest registered token.
584
+
585
+ Parameters:
586
+ token_size (int): Maximum token size to analyze.
587
+ """
588
+ self._token_size = token_size
589
+
590
+ def get_token_size(self) -> int:
591
+ """
592
+ Returns the maximum token size used by tokenize_text().
593
+
594
+ This value defines the character limit analyzed during
595
+ tokenization and directly affects methods that depend on
596
+ the token recognition process.
597
+
598
+ Returns:
599
+ int
600
+ """
601
+ return self._token_size
578
602
 
579
603
  def tokenize_text(self, text: str) -> list[str]:
604
+ """
605
+ Converts a text into a list of registered tokens.
606
+
607
+ The method prioritizes the longest possible token at the current
608
+ position in the text. The maximum token size is defined through
609
+ the configure_token() method.
610
+
611
+ Returns:
612
+ list[str]
613
+ """
614
+
580
615
  tokens = []
581
616
  i = 0
582
617
  max_len = self._token_size
@@ -598,16 +633,14 @@ class BrailleBase:
598
633
 
599
634
  return tokens
600
635
 
601
- # def tokenize_text(self, text: str) -> list[str]:
602
636
  def confidence_test(self, text: str) -> dict:
603
637
  iToken = 0
604
638
 
605
-
606
639
  tokens = self.tokenize_text(text)
607
640
 
608
- tokens = self.prepare_special_braille_rules_simbol(tokens)
641
+ tokens = self.prepare_special_braille_rules_symbol(tokens)
609
642
  tokens = self.prepare_special_braille_rules_uppercase(tokens)
610
- tokens = self.prepare_special_braille_rules_CJK(tokens)
643
+ tokens = self.prepare_special_braille_rules_syllabic(tokens)
611
644
  tokens = self.prepare_special_braille_rules_RTL(tokens)
612
645
  tokens = self.prepare_number_braille(tokens)
613
646
 
@@ -623,8 +656,7 @@ class BrailleBase:
623
656
  iToken += 1
624
657
  return result
625
658
 
626
- def configure_token(self, token_size: int):
627
- self._token_size = token_size
659
+
628
660
  #----------------------------Constructor ---------------------------
629
661
 
630
662
  def __constructor_all_table(self):
@@ -655,5 +687,3 @@ class BrailleBase:
655
687
 
656
688
  def __constructor_map_braille(self):
657
689
  self.append_multiple_braille_letters(BrailleBaseBniversalSet.braille_base_universal_set())
658
-
659
-
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: braillebase
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: A complete and extensible Unicode Braille processing library.
5
5
  Author: Nagao Yuji
6
6
  License: MIT
@@ -34,19 +34,128 @@ To support this flexibility, the Braille Base API provides several methods for m
34
34
  </p>
35
35
 
36
36
  ### Group Identification
37
- The methods in this group include an argument called type, which determines which map the operation will target. Each value corresponds to a specific group, as described below:
37
+ The methods in this group include an argument called collection, which determines which map the operation will target. Each value corresponds to a specific group, as described below:
38
38
 
39
39
  <p>
40
40
  <h4>0 — Default</h4>
41
41
  The central registry and translation base of Braille Base. All records are stored in this group. The other groups act as auxiliary rule-identification mechanisms, allowing the engine to determine in advance which processing rules should be applied to each character or expression.
42
42
  <h4>1 — Uppercase</h4>
43
43
  Used to register uppercase letters, allowing the engine to identify when translation requires the application of an uppercase indicator.
44
- <h4>2 — CJK</h4>
44
+ <h4>2 — Syllabic</h4>
45
45
  Used to register characters and writing systems that follow syllabic rules, such as Hiragana, Jamul, and Pinyin.
46
46
  <h4>3 — RTL</h4>
47
47
  Used to register languages whose writing systems follow a right-to-left (RTL) direction.
48
48
  <h4>4 — Symbol</h4>
49
- Used to register symbols, characters, and special expressions that take priority over all other interpretation rules. It allows complete expressions to be recognized as a single translation unit, preventing their individual characters from being interpreted separately.</p>
49
+ Used to register symbols, characters, and special expressions that take priority over all other interpretation rules. It allows complete expressions to be recognized as a single translation unit, preventing their individual characters from being interpreted separately.
50
+ </p>
51
+
52
+ ### Registry Group Constants
53
+ ```python
54
+ bbDEFAULT = 0
55
+ bbUPPERCASE = 1
56
+ bbSYLLABIC = 2
57
+ bbRTL = 3
58
+ bbSYMBOL = 4
59
+ ```
60
+
61
+ As described earlier, registry groups are identified by indices ranging from 0 to 4. However, there is no need to memorize these values. Braille Base exposes predefined constants that map directly to each registry group. For example, use bbUPPERCASE instead of 1.
62
+
63
+ - In practice, both the numeric identifier and its corresponding constant can be used interchangeably when registering or editing Braille entries. However, using constants is recommended because it improves code readability and makes maintenance easier.
64
+
65
+ ```python
66
+ from braillebase import BrailleBase
67
+
68
+ class BrailleBaseMyLanguage(BrailleBase):
69
+ def __init__(self):
70
+
71
+ self.append_braille_letter("CH", ["⠡"], bbUPPERCASE)
72
+ self.append_braille_letter("SH", ["⠩"], bbUPPERCASE)
73
+ self.append_braille_letter("TH", ["⠹"], 1)
74
+ self.append_braille_letter("WH", ["⠱"], 1)
75
+ self.append_braille_letter("あ", ["⠁"],bbSYLLABIC)
76
+ self.append_braille_letter("い", ["⠃"],bbSYLLABIC)
77
+ self.append_braille_letter("う", ["⠉"],2)
78
+
79
+ self.edit_braille_letter("え", ["⠋"],bbSYLLABIC)
80
+ self.edit_braille_letter("お", ["⠊"],2)
81
+ ```
82
+
83
+ - The methods in Registry Group (0001) are intuitive and self-explanatory. Nevertheless, the following section provides a brief overview of each method signature.
84
+ ```python
85
+ Registers a new letter and its Braille representation. Return: None
86
+ def append_braille_letter(self, letter: str, braille_list: list, collection = bbDEFAULT):​‌
87
+ ```
88
+ ```python
89
+ Retrieves all Braille cells associated with a letter. Return: list
90
+ def get_brailles_with_letter(self, letter: str):​‌
91
+ ```
92
+ ```python
93
+ Checks whether a letter is registered. Return: bool
94
+ def has_letter(self, letter: str, collection = bbDEFAULT) -> bool:​‌
95
+ ```
96
+ ```python
97
+ Removes a registered letter. Return: bool (True if removed)
98
+ def remove_letter(self, letter: str, collection = bbDEFAULT) -> bool:​‌
99
+ ```
100
+ ```python
101
+ Returns all registered letters from a group. Return: list
102
+ def get_registered_letters(self, collection = bbDEFAULT):​‌
103
+ ```
104
+ ```python
105
+ Registers multiple letters at once. Return: None
106
+ def append_multiple_braille_letters(self, letter_braillelist_pattern: list):​‌
107
+ ```
108
+ ```python
109
+ Imports letter registrations from a data source. Return: None
110
+ def append_braille_letter_IO(self, target_data_path: str):​‌
111
+ ```
112
+ ```python
113
+ Updates the Braille representation of a registered letter. Return: None
114
+ def edit_braille_letter(self, letter: str, new_braille_list: list, collection = bbDEFAULT):
115
+ ```
116
+ ### append_braille_letter_IO
117
+ - The append_braille_letter_IO method accepts only one argument, which is the path to the file containing the data. The API supports only three data formats: JSON, XML, and CSV.
118
+
119
+ ```json
120
+ JSON
121
+ [
122
+ {
123
+ "letter": "a",
124
+ "braille": "⠁,⠁",
125
+ "pattern": 0
126
+ },
127
+ {
128
+ "letter": "b",
129
+ "braille": "⠟,⠟,⠟",
130
+ "pattern": 0
131
+ }
132
+ ]
133
+ ```
134
+
135
+ ```xml
136
+ XML
137
+ <?xml version="1.0" encoding="utf-8"?>
138
+ <braille_append>
139
+ <item>
140
+ <letter>a</letter>
141
+ <braille>⠁,⠁</braille>
142
+ <pattern>0</pattern>
143
+ </item>
144
+
145
+ <item>
146
+ <letter>b</letter>
147
+ <braille>⠟,⠟,⠟</braille>
148
+ <pattern>0</pattern>
149
+ </item>
150
+ </braille_append>
151
+ ```
152
+ ```csv
153
+ CSV
154
+ a,"⠁,⠁",0
155
+ b,"⠟,⠟,⠟",0
156
+ ```
157
+ - The file data does not contain a header. You must provide the character, the Braille representation, and the group using its numeric identifier, following the format demonstrated in the examples. The group field cannot be omitted, so make sure to specify the correct group for each entry.
158
+ - For more information on how to create JSON, XML, or CSV files, please refer directly to the BrailleBaseIO documentation.
50
159
 
51
160
  # documentation under development.# Braille Base
52
161
  # Old Doc
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "braillebase"
7
- version = "0.3.0"
7
+ version = "0.3.2"
8
8
  description = "A complete and extensible Unicode Braille processing library."
9
9
  authors = [
10
10
  { name = "Nagao Yuji" }
File without changes
File without changes