• Stars
    star
    334
  • Rank 125,480 (Top 3 %)
  • Language
    Python
  • License
    MIT License
  • Created over 11 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Constants used in Chinese text processing

Zhon

https://badge.fury.io/py/zhon.png https://travis-ci.org/tsroten/zhon.png?branch=develop

Zhon is a Python library that provides constants commonly used in Chinese text processing.

About

Zhon's constants can be used in Chinese text processing, for example:

  • Find CJK characters in a string:

    >>> re.findall('[{}]'.format(zhon.hanzi.characters), 'I broke a plate: 我打破了一个盘子.')
    ['我', '打', '破', '了', '一', '个', '盘', '子']
  • Validate Pinyin syllables, words, or sentences:

    >>> re.findall(zhon.pinyin.syllable, 'Yuànzi lǐ tíngzhe yí liàng chē.', re.I)
    ['Yuàn', 'zi', 'lǐ', 'tíng', 'zhe', 'yí', 'liàng', 'chē']
    
    >>> re.findall(zhon.pinyin.word, 'Yuànzi lǐ tíngzhe yí liàng chē.', re.I)
    ['Yuànzi', 'lǐ', 'tíngzhe', 'yí', 'liàng', 'chē']
    
    >>> re.findall(zhon.pinyin.sentence, 'Yuànzi lǐ tíngzhe yí liàng chē.', re.I)
    ['Yuànzi lǐ tíngzhe yí liàng chē.']

Features

  • Includes commonly-used constants:
    • CJK characters and radicals
    • Chinese punctuation marks
    • Chinese sentence regular expression pattern
    • Pinyin vowels, consonants, lowercase, uppercase, and punctuation
    • Pinyin syllable, word, and sentence regular expression patterns
    • Zhuyin characters and marks
    • Zhuyin syllable regular expression pattern
    • CC-CEDICT characters
  • Runs on Python 2.7 and 3

Getting Started