Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

改进pinyin.py #15

Open
snaker95 opened this issue Apr 12, 2017 · 0 comments
Open

改进pinyin.py #15

snaker95 opened this issue Apr 12, 2017 · 0 comments

Comments

@snaker95
Copy link

def hanzi2pinyin(self, string=""):
    result = []
    if not isinstance(string, unicode):
        string = string.decode("utf-8")
    
    for char in string:
        # 做ascII的判断
        if ord(char) > 128:
            key = '%X' % ord(char)
            result.append(self.word_dict.get(key, char).split()[0][:-1].lower())
        else:
            result.append(char)
    return result


def hanzi2pinyin_split(self, string="", split=""):
    result = self.hanzi2pinyin(string=string)
    # 去除split的判断
    return split.join(result)
# 新增获取简拼(中国zg)
def hanzi2jianpin(self, string=""):
    result = self.hanzi2pinyin(string=string)
    return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant