Skip to content

Commit 5eda0af

Browse files
authored
Merge pull request #1287 from PyThaiNLP/copilot/add-pythainlp-braille
Add pythainlp.braille module for Thai braille conversion
2 parents 8d908f6 + e524c80 commit 5eda0af

File tree

5 files changed

+774
-0
lines changed

5 files changed

+774
-0
lines changed

docs/api/braille.rst

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
.. currentmodule:: pythainlp.braille
2+
3+
pythainlp.braille
4+
=================
5+
The :mod:`pythainlp.braille` module provides Thai braille conversion functionality. It enables the conversion of Thai text into braille representation using Unicode braille characters, following international braille standards.
6+
7+
Modules
8+
-------
9+
10+
thai_word_braille
11+
~~~~~~~~~~~~~~~~~
12+
.. autofunction:: thai_word_braille
13+
14+
The `thai_word_braille` function converts a single Thai word into its braille representation. It handles Thai consonants, vowels, tone marks, numbers, and punctuation marks, transforming them into Unicode braille characters according to Thai braille standards.
15+
16+
thai_text_braille
17+
~~~~~~~~~~~~~~~~~
18+
.. autofunction:: thai_text_braille
19+
20+
The `thai_text_braille` function converts Thai text into braille representation by tokenizing the text into words and converting each word separately. It returns a list of braille strings corresponding to each token in the input text.
21+
22+
Braille Class
23+
~~~~~~~~~~~~~
24+
.. autoclass:: pythainlp.braille.core.Braille
25+
:members:
26+
27+
The `Braille` class handles the conversion of braille dot patterns to Unicode braille characters. It supports both reading braille (tobraille method) and printing braille with mirrored patterns (printbraille method) according to international braille standards.
28+
29+
Usage Examples
30+
--------------
31+
32+
Converting Thai words to braille:
33+
34+
.. code-block:: python
35+
36+
from pythainlp.braille import thai_word_braille
37+
38+
# Convert a simple Thai word
39+
thai_word_braille("กก")
40+
# Output: '⠛⠛'
41+
42+
# Convert a word with vowels
43+
thai_word_braille("น้ำ")
44+
# Output: '⠝⠲⠵'
45+
46+
# Convert a greeting
47+
thai_word_braille("สวัสดี")
48+
# Output: '⠎⠺⠜⠎⠙⠆'
49+
50+
Converting Thai text to braille:
51+
52+
.. code-block:: python
53+
54+
from pythainlp.braille import thai_text_braille
55+
56+
# Convert a sentence
57+
thai_text_braille("สวัสดี ครับ")
58+
# Output: ['⠎⠺⠜⠎⠙⠆', ' ', '⠥⠗⠜⠧']
59+
60+
Features
61+
--------
62+
63+
- **Complete Thai character support**: Handles all Thai consonants, vowels, tone marks, and special characters
64+
- **Number conversion**: Automatically adds number prefixes for digit sequences
65+
- **Complex vowel patterns**: Supports Thai vowel combinations and patterns through regex-based substitution
66+
- **Unicode braille output**: Generates standard Unicode braille characters (U+2800 to U+28FF)
67+
- **Edge case handling**: Properly handles empty strings and unmapped characters
68+
- **International standards**: Follows international braille dot numbering (dots 1-8)
69+
70+
The `pythainlp.braille` module provides comprehensive Thai braille conversion capabilities, making Thai text accessible in braille format for various applications including accessibility tools, educational materials, and text processing pipelines.

pythainlp/braille/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# SPDX-FileCopyrightText: 2016-2026 PyThaiNLP Project
2+
# SPDX-FileType: SOURCE
3+
# SPDX-License-Identifier: Apache-2.0
4+
"""Thai braille processing."""
5+
6+
__all__: list[str] = [
7+
"thai_text_braille",
8+
"thai_word_braille",
9+
]
10+
11+
from pythainlp.braille.core import thai_text_braille, thai_word_braille

0 commit comments

Comments
 (0)