加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
汉字转拼音.py 1.35 KB
一键复制 编辑 原始数据 按行查看 历史
fengmingshan 提交于 2021-12-15 20:46 . 找回资料提交
# -*- coding: utf-8 -*-
"""
Created on Thu Feb 1 13:07:22 2018
@author: Administrator
"""
#hanzi2pinyin函数
#原来的hanzi2pinyin函数:
def hanzi2pinyin(self, string=""):
result = []
if not isinstance(string, unicode):
string = string.decode("utf-8")
for char in string:
key = '%X' % ord(char)
result.append(self.word_dict.get(key, char).split()[0][:-1].lower())
return result
#修改后的hanzi2pinyin函数:
def hanzi2pinyin(self, string=""):
result = []
if not isinstance(string, unicode):
string = string.decode("utf-8")
for char in string:
key = '%X' % ord(char)
if not self.word_dict.get(key):
result.append(char)
else:
result.append(self.word_dict.get(key, char).split()[0][:-1].lower())
return result
#hanzi2pinyin_split函数
#原来的hanzi2pinyin_split函数:
def hanzi2pinyin_split(self, string="", split=""):
result = self.hanzi2pinyin(string=string)
if split == "":
return result
else:
return split.join(result)
#修改后的hanzi2pinyin_split函数(不论split参数是否为空,hanzi2pinyin_split均返回字符串):
def hanzi2pinyin_split(self, string="", split=""):
result = self.hanzi2pinyin(string=string)
#if split == "":
# return result
#else:
return split.join(result)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化