[opencc 1.0.4 安裝]
1. 下載 opencc 1.0.4 => https://github.com/BYVoid/OpenCC
2. 解壓到你的程式下某目錄(自行依喜好安排)
3. 再來就是進到 opencc 的目錄執行
# cd opencc1.0.4
# mkdir build
# cd build
產生 makefile, 以下分兩個平台, MAC 不能打開 GETTEXT
CENTOS 執行以下命令
# cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release LE_GETTEXT:BOOL=ON ..
MAC 執行以下命令
# cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_BUILD_TYPE=Release -D ENABLE_GETTEXT:BOOL=OFF -DCMAKE_OSX_ARCHITECTURES=x86_64 ..
# make
# sudo make install
4. 最後,用 pip 安裝 OpenCC 即可
$ pip install OpenCC==0.2
5. 若遇到 libopencc.so.2: cannot open shared object file: No such file or directory
那是因為build 出來的 library 是 32bit, centos 64bit 是放在 /usr/lib64/ 故建個捷徑連到 /usr/lib 即可
#sudo ln -s /usr/lib/libopencc.so.2 /usr/lib64/libopencc.so.2
[測試]
$ opencc --version
Open Chinese Convert (OpenCC) Command Line Tool
Version: 1.0.4
[python 測試]
$ python
Python 3.4.3 (default, Jul 13 2015, 03:19:09)
[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import opencc
>>> opencc.convert("开放中文转换", config='s2tw')
'開放中文轉換'
>>>
[內建可轉換檔有]
Conversions include 轉換包含:
'hk2s': Traditional Chinese (Hong Kong standard) to Simplified Chinese
's2hk': Simplified Chinese to Traditional Chinese (Hong Kong standard)
's2t': Simplified Chinese to Traditional Chinese
's2tw': Simplified Chinese to Traditional Chinese (Taiwan standard)
's2twp': Simplified Chinese to Traditional Chinese (Taiwan standard, with phrases)
't2hk': Traditional Chinese to Traditional Chinese (Hong Kong standard)
't2s': Traditional Chinese to Simplified Chinese
't2tw': Traditional Chinese to Traditional Chinese (Taiwan standard)
'tw2s': Traditional Chinese (Taiwan standard) to Simplified Chinese
'tw2sp': Traditional Chinese (Taiwan standard) to Simplified Chinese (with phrases)
沒有留言:
張貼留言