___ _____ __ ___ ___ ___ _____ __ __
/ __`\/\ '__`\ /'__`\/' _ `\ /'___\ /'___\/\ '__`\/\ \/\ \
/\ \L\ \ \ \L\ \/\ __//\ \/\ \/\ \__//\ \__/\ \ \L\ \ \ \_\ \
\ \____/\ \ ,__/\ \____\ \_\ \_\ \____\ \____\\ \ ,__/\/`____ \
\/___/ \ \ \/ \/____/\/_/\/_/\/____/\/____/ \ \ \/ `/___/> \
\ \_\ \ \_\ /\___/
\/_/ \/_/ \/__/
複製代碼
OpenccPy 是一款 python 中文繁簡體轉換工具。java
Python 3.Xpython
pip install openccpy
複製代碼
# coding=utf-8
from openccpy.opencc import *
class TestOpencc(object):
""" 核心轉換測試類 """
def test_to_simple(self):
""" 測試轉換爲簡體 """
assert "絲" == Opencc.to_simple("絲")
assert "一目瞭然" == Opencc.to_simple("一目瞭然")
def test_to_traditional(self):
""" 測試轉化爲繁體 """
assert "絲" == Opencc.to_traditional("絲")
assert "一目瞭然" == Opencc.to_traditional("一目瞭然")
複製代碼
def to_simple(traditional):
""" 繁體轉化爲簡體 1. 若是字符爲空,直接返回 2. 字符長度爲1,返回對應簡體字符 3. 對應長度大於1,返回對應簡體詞組 :param traditional: 繁體單詞/單個詞組 :return: 對應的簡體信息 """
複製代碼
def to_traditional(simple):
""" 簡體轉化爲繁體 1. 若是字符爲空,直接返回 2. 字符長度爲1,返回對應繁體字符 3. 對應長度大於1,返回對應繁體詞組 :param simple: 簡體單詞/單個詞組 :return: 對應的繁體信息 """
複製代碼
github/openccpygithub