GithubHelp home page GithubHelp logo

zxfksie / zhconv Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gumblex/zhconv

0.0 0.0 0.0 935 KB

Simple conversion and localization between simplified and traditional Chinese using tables from MediaWiki.

Home Page: https://pypi.python.org/pypi/zhconv

License: MIT License

Python 100.00%

zhconv's Introduction

简易中文简繁转换

文档

zhconv 提供基于 MediaWiki 和 OpenCC 词汇表的最大正向匹配简繁转换,支持地区词转换:zh-cn, zh-tw, zh-hk, zh-sg, zh-hans, zh-hant。Python 2、3通用。

若要求高精确度,参见 OpenCCopencc-python

>>> print(convert(u'我幹什麼不干你事。', 'zh-cn'))
我干什么不干你事。
>>> print(convert(u'人体内存在很多微生物', 'zh-tw'))
人體內存在很多微生物

其中,zh-hans, zh-hant 仅转换简繁,不转换地区词。

完整支持 MediaWiki 人工转换语法:

>>> print(convert_for_mw(u'在现代,机械计算-{}-机的应用已经完全被电子计算-{}-机所取代', 'zh-hk'))
在現代,機械計算機的應用已經完全被電子計算機所取代
>>> print(convert_for_mw(u'-{zh-hant:資訊工程;zh-hans:计算机工程学;}-是电子工程的一个分支,主要研究计算机软硬件和二者间的彼此联系。', 'zh-tw'))
資訊工程是電子工程的一個分支,主要研究計算機軟硬體和二者間的彼此聯繫。
>>> print(convert_for_mw(u'張國榮曾在英國-{zh:利兹;zh-hans:利兹;zh-hk:列斯;zh-tw:里茲}-大学學習。', 'zh-sg'))
张国荣曾在英国利兹大学学习。
>>> print(convert_for_mw('毫米(毫公分),符號mm,是長度單位和降雨量單位,-{zh-hans:**作-{公釐}-或-{公厘}-;zh-hant:港澳和大陸稱為-{毫米}-(台灣亦有使用,但較常使用名稱為毫公分);zh-mo:台灣作-{公釐}-或-{公厘}-;zh-hk:台灣作-{公釐}-或-{公厘}-;}-。', 'zh-cn'))
毫米(毫公分),符号mm,是长度单位和降雨量单位,**作公釐或公厘。

和其他高级字词转换语法

转换字典可下载 MediaWiki 源码包中的 includes/ZhConversion.php,使用 convmwdict.py 可转换成 json 格式。

代码授权协议采用 MIT 协议;转换表由于来自 MediaWiki,为 GPLv2+ 协议。

在Spark集群中使用该项目

在分布式集群中,也许受环境限制,不便于在每台机器上安装该项目。 那么你可以从driver机器中单独上传该项目的egg文件,不需要依赖于其它的项目。

# python setup.py bdist_egg

# ls dist
zhconv-1.2.2-py2.7.egg

如果在本地,则可以直接执行sys.path.append('PATH_TO_ZHCONV/zhconv-1.2.2-py2.7.egg')后使用。

小工具

EPUB 电子书简繁转换:python3 epubzhconv.py 输入.epub 输出.epub zh-{cn,tw}


Simple Chinese Conversion Library

zhconv converts between Simplified and Traditional Chinese using maximum forward matching. The conversion table is based on MediaWiki and OpenCC. Supports regional vocabulary: zh-cn, zh-tw, zh-hk, zh-sg, zh-hans, zh-hant. Supports both Python 2 and 3.

Example:

>>> print(convert(u'我幹什麼不干你事。', 'zh-cn'))
我干什么不干你事。
>>> print(convert(u'人体内存在很多微生物', 'zh-tw'))
人體內存在很多微生物

If zh-hans or zh-hant is used, then regional vocabulary conversion will be disabled.

Documentation is available in Chinese.

The code is licensed under MIT, while the conversion table is licensed under GPLv2+.

zhconv's People

Contributors

guangyi-z avatar gumblex avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.