Skip to main content

search for chinese pinyin and wrap it with HTML.

Project description

search for chinese pinyin and wrap it with HTML.

colorize pinyin

search for chinese pinyin and wrap it with HTML.

module provides some useful functions for working with Chinese pinyin, “phonetic system for transcribing the Mandarin pronunciations of Chinese characters into the Latin alphabet” (c) wikipedia .

usage sample

>>> colorized_HTML_string_from_string('nǐ hǎo')
'<span class="pinYinWrapper"><span class="t3">nǐ</span> <span class="t3">hǎo</span></span>'
>>> ranges_of_pinyin_in_string('nǐ hǎo')
[Range(location=0, length=2), Range(location=3, length=3)]  # == [(0, 2), (3, 3)]

requirements

lxml is only required if you want to work with DOM. but it does not listed in requirements because if you want to use them, surely you already have lxml on the board; for other cases we don’t need additional third-party libs.

functions that designed to work with lxml marked with [*].

functions

modify given DOM by replacing children text nodes containing pinyin with wrapper element:

colorize_DOM [*]

undo colorize:

uncolorize_DOM [*]

detect and wrap pinyin with HTML in plain text string:

colorized_HTML_string_from_string

do the same, but returns a wrapper – DOM element:

colorized_HTML_element_from_string [*]

searching for pinyin in string of text:

ranges_of_pinyin_in_string

finding out what tone has some pinyin word:

determine_tone

remove tones (diacritics) from pinyin string:

lowercase_string_by_removing_pinyin_tones

constants

PINYIN_LIST – specially sorted list of all possible pinyin words.

PINYIN_LIST_BY_LEN – same as PINYIN_LIST but grouped by len descending.

PINYIN_WRAPPER_CLASS – default class used by [un]colorize_DOM.

classes

Range – 2-named-tuple with [0] location and [1] length.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

colorize_pinyin-2.1.1.tar.gz (7.9 kB view details)

Uploaded Source

colorize_pinyin-2.1.1.macosx-10.8-x86_64.tar.gz (11.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

colorize_pinyin-2.1.1-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

colorize_pinyin-2.1.1-py2-none-any.whl (11.2 kB view details)

Uploaded Python 2

File details

Details for the file colorize_pinyin-2.1.1.tar.gz.

File metadata

File hashes

Hashes for colorize_pinyin-2.1.1.tar.gz
Algorithm Hash digest
SHA256 d2aa9adae50ea9a2d59042710ee830b5020a17c05ae5c455786c30e284be8fb9
MD5 bf3ced9b1a689ec05fa6018b59a1f6c4
BLAKE2b-256 7579c0661c7a41bc7ffe7d1c3583a1e2b3e4887b127fe1e056d5e9e4a3ccabb4

See more details on using hashes here.

File details

Details for the file colorize_pinyin-2.1.1.macosx-10.8-x86_64.tar.gz.

File metadata

File hashes

Hashes for colorize_pinyin-2.1.1.macosx-10.8-x86_64.tar.gz
Algorithm Hash digest
SHA256 ac78d75f9b17e9ac1674f0dca6472fd063f1de865cebc0ac5f46fcc7638d3f32
MD5 c64d0d4053438058692fd3572152143c
BLAKE2b-256 8ccf1b359e73db3ba5f4034f7237c3c6679e7c11c5611c2536628cbf2ea66693

See more details on using hashes here.

File details

Details for the file colorize_pinyin-2.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for colorize_pinyin-2.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 927fc1e18e9ae072d03e9573e25765a7f79feda00b1c5b2b03c4adf7f76a4293
MD5 089112991b0eb97eccf3cb43307a4122
BLAKE2b-256 763e9874fd764e982fec90d40dbf06cebdf449d62cc53fbdd6987f374a850066

See more details on using hashes here.

File details

Details for the file colorize_pinyin-2.1.1-py2-none-any.whl.

File metadata

File hashes

Hashes for colorize_pinyin-2.1.1-py2-none-any.whl
Algorithm Hash digest
SHA256 c617e0483c5f2924637d5f565f54eb6431308543b511a26dd33308b870f606b1
MD5 c3e5d238ec21e483880e17cb125cfd66
BLAKE2b-256 c01a3bb27caeefd021d1b03c714a25f2443c5892df9eec875b3a52330934c1b2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page