bengali-nlp
它能做什么
这个工具可以帮助你处理孟加拉语(Bangla)文本。它能确保文本正确显示和存储,划分词语,并处理与该语言相关的数字和字符。
适用场景
- ✓当你需要分析孟加拉语文本时。
- ✓当你在开发面向孟加拉语使用者的应用时。
- ✓当你处理孟加拉语教育内容时。
技能链接
https://github.com/affaan-m/ECC/blob/main/pi/core/skills/bengali-nlp/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请帮我处理这段孟加拉语文本:“আমি বাংলায় গান গাই।””
每周 5 个新技能,1 分钟读完。
工作原理
工具会依据特定规则整理孟加拉字符,正确划分词语,并处理孟加拉数字。它还会确保文本采用标准格式,以避免出现问题。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Bengali (Bangla) NLP Patterns
Best practices for processing, storing, and displaying Bengali text in software applications and AI systems.
When to Activate
- Working with Bengali/Bangla text data
- Building apps targeting Bengali-speaking users
- Processing NCTB (National Curriculum and Textbook Board) educational content
- Implementing Bengali search, autocomplete, or text input
- Training or fine-tuning LLMs on Bengali data
- Building Bengali chatbots or conversational AI
- Handling mixed Bengali-English (Banglish) text
Bengali Unicode and Script Handling
Unicode Range
Bengali script occupies U+0980–U+09FF. Key character classes:
U+0981–U+0983 Chandrabindu, Anusvara, Visarga
U+0985–U+0994 Independent vowels (অ আ ই ঈ উ ঊ ঋ ঌ এ ঐ ও ঔ)
U+0995–U+09B0 Consonants (ক–র)
U+09B2 ল
U+09B6–U+09B9 শ ষ স হ
U+09DC, U+09DD, U+09DF Additional consonants (ড়, ঢ়, য়)
U+09BC Nukta
U+09BE–U+09C8 Dependent vowel signs (কার): া ি ী ু ূ ৃ ে ৈ
U+09CB–U+09CC Dependent vowel signs: ো ৌ
U+09CD Hasanta (virama) — forms conjuncts
U+09CE Khanda Ta (ৎ)
U+09D7 AU length mark
U+09E0–U+09E3 Extended vowels
U+09E6–U+09EF Bengali digits: ০১২৩৪৫৬৭৮৯
U+09F0–U+09F1 Assamese letters: ৰ (ra with middle diagonal), ৱ (ra with lower diagonal)
U+09F2–U+09F3 Rupee mark ৲ and rupee sign ৳
U+09F4–U+09F9 Historic currency numerators ৴ ৵ ৶ ৷ ৸ and denominator ৹
U+09FA Isshar ৺
Normalization
Always normalize Bengali text to NFC before comparison, storage, or search:
import unicodedata
def normalize_bangla(text: str) -> str:
"""Normalize Bengali text to NFC form."""
return unicodedata.normalize("NFC", text)
# NFC composes characters: base + combining marks -> precomposed
text_nfd = "ক\u09C7\u09BE" # decomposed form of "কো"
text_nfc = normalize_bangla(text_nfd)
assert text_nfc == "কো"
assert text_nfc == normalize_bangla(text_nfc) # idempotent
// JavaScript
function normalizeBangla(text) {
return text.normalize('NFC');
}
Conjunct Consonants (যুক্তবর্ণ)
Bengali conjuncts are formed with Hasanta (্) between consonants:
ক + ্ + ষ = ক্ষ (ksha)
স + ্ + ত = স্ত (sta)
ন + ্ + ত + ্ + র = ন্ত্র (ntra)
Never split strings in the middle of a conjunct. Use grapheme cluster boundaries:
import regex # pip install regex
def grapheme_length(text: str) -> int:
"""Count user-perceived characters (grapheme clusters)."""
return len(regex.findall(r"\X", text))
# "ক্ষ" is 1 grapheme but 3 code points (ক + ্ + ষ)
assert grapheme_length("ক্ষ") == 1
assert len("ক্ষ") == 3 # code point count — wrong for display
// JavaScript — use Intl.Segmenter for grapheme-safe operations
function graphemeLength(text) {
const segmenter = new Intl.Segmenter('bn', { granularity: 'grapheme' });
return [...segmenter.segment(text)].length;
}
Bengali Digits
Handle both Bengali (০-৯) and ASCII (0-9) digits:
BANGLA_DIGITS = "০১২৩৪৫৬৭৮৯"
ASCII_DIGITS = "0123456789"
def bangla_to_ascii_digits(text: str) -> str:
table = str.maketrans(BANGLA_DIGITS, ASCII_DIGITS)
return text.translate(table)
def ascii_to_bangla_digits(text: str) -> str:
table = str.maketrans(ASCII_DIGITS, BANGLA_DIGITS)
return text.translate(table)
Tokenization
Word Boundary Detection
Bengali uses spaces between words, but compound words and postpositions can complicate tokenization:
import re
def tokenize_bangla(text: str) -> list[str]:
"""Basic Bengali tokenizer — split on whitespace and punctuation."""
# Remove Bengali and ASCII punctuation, but preserve decimal points
text = re.sub(r'(?<!\d)\.|\.(?!\d)|[।,;:!?\-\'"()\[\]{}]', ' ', text)
return [token for token in text.split() if token]
# For production, use a trained tokenizer:
# - bnlp (pip install bnlp_toolkit)
# - stanza with Bengali model
# - spaCy with Bengali pipeline
Using bnlp Toolkit
from bnlp import NLTKTokenizer
tokenizer = NLTKTokenizer()
tokens = tokenizer.word_tokenize("আমি বাংলায় গান গাই।")
# ['আমি', 'বাংলায়', 'গান', 'গাই', '।']
Handling Postpositions and Case Markers
Bengali postpositions attach to nouns. Tokenizers should be aware of common suffixes:
-এর (possessive), -তে (locative), -কে (accusative)
-র (possessive after vowel), -য় (locative variant)
Text Processing Patterns
Script Detection
import re
def is_bangla(text: str) -> bool:
…
常见问题
什么是文本规范化?
规范化是指确保孟加拉语文本保持一致的格式,把那些写法不同但含义相同的字符组合统一起来。
什么是“连字”(conjuncts)?
连字是指几个孟加拉字母连在一起,构成一个单独的音或字符,比如“ক্ষ”。工具会确保这些字母被视为一个整体。
为什么我需要关注孟加拉数字?
孟加拉语有自己的数字(০১২৩৪৫৬৭৮৯)。这个工具可以把它们转换为我们常用的 0 到 9,必要时也能转换回来。
详情
作者的原始描述
Bengali (Bangla) text processing patterns including Unicode normalization, script detection, tokenization, conjunct handling, and Bangla-specific NLP best practices for AI applications.
repo: affaan-m/ECC
热度
- GitHub 星标
- 280k
- 排名
- #143
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …
同一仓库的更多技能
accessibility
280k帮你的智能体创建人人都能使用的界面。确保网站和应用对残障人士友好,比如失明或行动不便的用户也能顺畅使用。
agent-architecture-audit
280k让你的智能体检查一切是否正常运行。它能找出并修复 AI 系统中的问题,确保系统按预期工作。
agent-eval
280k帮你的智能体比较不同的 AI 编程工具。它能衡量哪个工具在特定任务上更快、更便宜、更可靠。
agent-harness-construction
280k让你的智能体更好地理解如何完成任务。它会优化智能体使用的工具和指令,提高成功的几率。