mozillazg/python-pinyin

增加按照拼音风格进行分割的接口

Open

#247 opened on Jul 27, 2021

View on GitHub
 (1 comment) (0 reactions) (0 assignees)Python (638 forks)batch import
backlogdiscusshelp wantednew feature

Repository metrics

Stars
 (4,582 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

问题描述

  {'pos': 't', 'word': '一九五四年', 'pinyin': 'yi1jiu3wu3si4nian2'},

我们已知该格式的拼音,可以考虑增加接口返回一个分割好的列表。当前的模式下,可能使用正则表达式即可。扩展到各种已知风格,可能会更复杂些。但是包装好的接口可以节省很多重复工作。

本issue中的例子可以这样解决:

def parse_pinyin(text):
    g = re.findall(r'([a-z]+)', text)
    if g is not None:
        return g
    else:
        return [text]

Contributor guide