|
from pyhanlp import HanLP |
|
from snownlp import SnowNLP |
|
import pkuseg |
|
|
|
|
|
def wrap_str_func(func): |
|
""" |
|
Wrapper to apply str function to the proper key of return_dict. |
|
""" |
|
|
|
def wrapper(some_dict): |
|
some_dict["seg"] = [func(item) for item in some_dict["seg"]] |
|
return some_dict |
|
|
|
return wrapper |
|
|
|
|
|
|
|
@wrap_str_func |
|
def zh_segmentator(line, server_model): |
|
return " ".join(pkuseg.pkuseg().cut(line)) |
|
|
|
|
|
|
|
@wrap_str_func |
|
def zh_traditional_standard(line, server_model): |
|
return HanLP.convertToTraditionalChinese(line) |
|
|
|
|
|
|
|
@wrap_str_func |
|
def zh_traditional_hk(line, server_model): |
|
return HanLP.s2hk(line) |
|
|
|
|
|
|
|
@wrap_str_func |
|
def zh_traditional_tw(line, server_model): |
|
return HanLP.s2tw(line) |
|
|
|
|
|
|
|
@wrap_str_func |
|
def zh_simplify(line, server_model): |
|
return HanLP.convertToSimplifiedChinese(line) |
|
|
|
|
|
|
|
@wrap_str_func |
|
def zh_simplify_v2(line, server_model): |
|
return SnowNLP(line).han |
|
|