一些原生 Python 中的 Unicode 字符串处理工具
项目描述
cldr-language-helpers
基本上,这个项目是为了提供一个 UTF8 块范围到区域/语言代码的映射。
它以 cldr.unicode.org 项目作为参考。
构建
克隆最新的 cldr 发布版
svn co http://www.unicode.org/repos/cldr/tags/release-34/ ./cldr-release-34
测试
pip install -r requirements/dev.txt
然后运行测试
pytest
测试还将填充 cldr_language_helpers/data 目录。或者您也可以只运行填充测试
pytest -sm generate
API
from cldr_language_helpers.annotator import StringAnnotator
assert StringAnnotator('123').char_types_by_index == [{'numbers'}, {'numbers'}, {'numbers'}]
assert 'ru_RU' in StringAnnotator('ф').langs_by_index[0]
assert {'ru_RU', 'en_US', 'en', 'ru'}.issubset(StringAnnotator('йцу 123 qwe LOL').all_langs)
stats = StringAnnotator('qwe йцу').lang_stats
assert stats['ru_RU'] == 3
assert stats['ru'] == 3
assert stats['en'] == 3
assert stats['space'] == 1
assert 'en' in StringAnnotator('somesortof123').langs_intersection
assert StringAnnotator('somesortof123').char_types_intersection == set()
assert StringAnnotator('somesortof').char_types_intersection == {'auxiliary', 'main'}
assert StringAnnotator(' ').char_types_intersection == {'space'}
assert StringAnnotator('что-то everything как-то lol !').split_by_lang_intersection() == \
['что-то', ' ', 'everything', ' ', 'как-то', ' ', 'lol', ' ', '!']
assert StringAnnotator('somesortof123').split_by_lang_intersection() == ['somesortof123']
assert StringAnnotator('qwe, 123!!!').split_by_char_type() == \
['qwe', ',', ' ', '123', '!!!']
assert StringAnnotator('йцу 123 qwe LOL').has_langs('ru', 'en')
assert StringAnnotator().has_langs_throughout('ru') is False
assert StringAnnotator('йцу 123').has_langs_throughout('ru') is True
assert StringAnnotator('йцу 123').has_langs_throughout('ru_RU') is True
项目详情
下载文件
下载适用于您的平台文件。如果您不确定要选择哪个,请了解有关 安装包 的更多信息。
源代码分发
cldr-language-helpers-1.2.0.tar.gz (314.2 kB 查看哈希值)