Package: cjklib3
ContentsIntroductionDependenciesPorting to Python 3InstallingWindowsUnixDocumentation & UsageExamplesDatabaseSQLiteMySQLContactIntroductionCjklib provides language routines related to Han characters (characters based
on Chinese characters named Hanzi, Kanji, Hanja and chu Han respectively) used
in writing of the Chinese, the Japanese, infrequently the Korean and formerly
the Vietnamese language(s). Functionality is included for character
pronunciations, radicals, glyph components, stroke decomposition and variant
information.DependenciesPython2.4 or above (currently no support for Python3)SQLite3+SQLAlchemy0.5+pysqlite2(already ships with Python 2.5 and above)Alternatively for MySQL as backend:MySQL5+MySQL-PythonPorting to Python 3condacreate-npy37python=3.7condaactivatepy37gitclone<git-repo-url>cdcjklib3pipinstall2to32to3-w.curlhttp://ftp.unicode.org/Public/UNIDATA/Unihan.zip-oUnihan.zippython-mcjklib.build.clibuildcjklibData--attach=--database=sqlite:///cjklib/cjklib.dbpipinstall.installcjkdict--downloadCEDICTpython-mcjklib.build.clibuildfullCEDICT--attach=sqlite:///cjklib/cjklib.db--database=sqlite:///cjklib/cjklib.dbpipinstall.InstallingWindowsInstall cjklib using the provided.exeinstaller. Make sure above
dependencies are satisfied.Three scriptscjknife.exe,buildcjkdb.exe, andinstallcjkdict.exewill be added to the PythonScriptssub-directory. Make sure this directory
is included in yourPATHenvironment variable to access these programs from
the command line.CJK dictionaries are not included by default. If you want to install any of
those run the following (with an Internet connection) from the root directory
of the source package:$ installcjkdict CEDICTThis will download CEDICT, create a SQLite database file and install it under
the directory given by theAPPDATAenvironment variable, e.g.C:\windows\profiles\MY_USER\ApplicationData\cjklib. Just substituteCEDICTfor any other supported dictionary (i.e. EDICT, CEDICT, HanDeDict,
CFDICT, CEDICTGR).UnixIf you are installing from the source package you need to deploy the library on
your system:$ sudo python setup.py installAlso make sure above dependencies are satisfied. CJK dictionaries are not
included by default. If you want to install any of those run the following
(with an Internet connection):$ sudo installcjkdict CEDICTThis will download CEDICT, create a SQLite database file and install it to/usr/local/share/cjklib. Just substituteCEDICTfor any other supported
dictionary (i.e. EDICT, CEDICT, HanDeDict, CFDICT, CEDICTGR).Documentation & UsageDocumentationis available online. Also see theproject pageand its wiki.
There is a small command line toolcjknifethat offers some of the library’s
functions. Seecjknife--helpfor an overview.ExamplesGet stroke order of characters:>>> from cjklib import characterlookup
>>> cjk = characterlookup.CharacterLookup('C')
>>> cjk.getStrokeOrder(u'说')
[u'㇔', u'㇊', u'㇔', u'㇒', u'㇑', u'㇕', u'㇐', u'㇓', u'㇟']Access a dictionary (here using Jim Breen’s EDICT):>>> from cjklib.dictionary import EDICT
>>> d = EDICT()
>>> d.getForTranslation('Tokyo')
[EntryTuple(Headword=u'東京', Reading=u'とうきょう',
Translation=u'/(n) Tokyo (current capital of Japan)/(P)/')]DatabasePackaged versions of the library will ship with a pre-built SQLite database
file. You can however easily rebuild the database yourself.First download the newest Unihan file:$ wget ftp://ftp.unicode.org/Public/UNIDATA/Unihan.zipThen start the build process:$ sudo buildcjkdb -r build cjklibDataSQLiteSQLite by default has no Unicode support for string operations. Optionally the
ICU library can be compiled in for handling alphabetic non-ASCII characters.
Cjklib can register own Unicode functions if ICU support is missing. Queries
withLIKEwill then use functionlower(). This compatibility mode has
negative impact on performance and as it is not needed for dictionaries like
EDICT or CEDICT it is disabled by default. Seecjklib.conffor enabling.MySQLWith MySQL 5 the followingCREATEcommand creates a database withutf8as character set using the general Unicode collation
(MySQL from 5.5.3 on will support full Unicode given character setutf8mb4and collationutf8mb4_bin):CREATE DATABASE cjklib DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;You might need to set access rights, too (substituteuser_nameandhost_name):GRANT ALL ON cjklib.* TO 'user_name'@'host_name';Now update the settings incjklib.conf.MySQL < 5.5 doesn’t support full UTF-8, and uses a version with max 3 bytes, so
characters outside the Basic Multilingual Plane (BMP) can’t be encoded. Building
the Unihan database thus might result in warnings, characters above U+FFFF
can’t be built at all. You need to disable building the full character range
by settingwideBuildtoFalseincjklib.confbefore building.
Alternatively pass--wideBuild=Falsetobuildcjkdb.ContactFor help or discussions on cjklib, joincjklib-devel@googlegroups.com.Please report bugs to theproject’s bug tracker.