天天看點

漢語言處理工具pyhanlp的簡繁轉換

繁簡轉換

HanLP幾乎實作了所有我們需要的繁簡轉換方式,并且已經封裝到了HanLP中,使得我們可以輕松的使用,而分詞器中已經預設支援多種繁簡格式或者混合。這裡我們不再做過多描述。

說明

·HanLP能夠識别簡繁分歧詞,比如列印機=印表機。許多簡繁轉換工具不能區分“以後”“皇後”中的兩個“後”字,HanLP可以。

算法詳解

·《漢字轉拼音與簡繁轉換的Java實作》——請查閱此文

1. from pyhanlp import *

2. # 繁簡轉化

3. print(HanLP.convertToTraditionalChinese("“以後等你當上皇後,就能買草莓慶祝了”。發現一根白頭發"))

4. print(HanLP.convertToSimplifiedChinese("憑藉筆記簿型電腦寫程式HanLP"))

5. # 簡體轉台灣繁體

6. print(HanLP.s2tw("hankcs在台灣寫代碼"))

7. # 台灣繁體轉簡體

8. print(HanLP.tw2s("hankcs在臺灣寫程式碼"))

9. # 簡體轉香港繁體

10. print(HanLP.s2hk("hankcs在香港寫代碼"))

11. # 香港繁體轉簡體

12. print(HanLP.hk2s("hankcs在香港寫代碼"))

13. # 香港繁體轉台灣繁體

14. print(HanLP.hk2tw("hankcs在臺灣寫代碼"))

15. # 台灣繁體轉香港繁體

16. print(HanLP.tw2hk("hankcs在香港寫程式碼"))

17.

18.# 香港/台灣繁體和HanLP标準繁體的互轉

19.print(HanLP.t2tw("hankcs在臺灣寫代碼"))

20.print(HanLP.t2hk("hankcs在臺灣寫代碼"))

21.

22.print(HanLP.tw2t("hankcs在臺灣寫程式碼"))

23.print(HanLP.hk2t("hankcs在台灣寫代碼"))

1.「以後等你當上皇後,就能買草莓慶祝了」。發現一根白頭髮

2.憑借筆記本電腦寫程式HanLP

3.hankcs在臺灣寫程式碼

4.hankcs在台灣寫代碼

5.hankcs在香港寫代碼

6.hankcs在香港寫代碼

7.hankcs在臺灣寫程式碼

8.hankcs在香港寫代碼

9.hankcs在臺灣寫程式碼

10.hankcs在台灣寫代碼

11.hankcs在臺灣寫代碼

12.hankcs在臺灣寫代碼

---------------------