Example #1
0
def phrase_pinyin(phrase, style, heteronym, errors='default', strict=True):
    """词语拼音转换.

    :param phrase: 词语
    :param errors: 指定如何处理没有拼音的字符
    :param strict: 是否严格遵照《汉语拼音方案》来处理声母和韵母
    :return: 拼音列表
    :rtype: list
    """
    py = []
    if phrase in PHRASES_DICT:
        py = deepcopy(PHRASES_DICT[phrase])
        for idx, item in enumerate(py):
            if heteronym:
                py[idx] = _remove_dup_items([
                    _to_fixed(x, style=style, strict=strict) for x in item])
            else:
                py[idx] = [_to_fixed(item[0], style=style, strict=strict)]
    else:
        for i in phrase:
            single = single_pinyin(i, style=style, heteronym=heteronym,
                                   errors=errors, strict=strict)
            if single:
                py.extend(single)
    return py
Example #2
0
def phrase_pinyin(phrase, style, heteronym, errors='default', strict=True):
    """词语拼音转换.

    :param phrase: 词语
    :param errors: 指定如何处理没有拼音的字符
    :param strict: 是否严格遵照《汉语拼音方案》来处理声母和韵母
    :return: 拼音列表
    :rtype: list
    """
    py = []
    if phrase in PHRASES_DICT:
        py = deepcopy(PHRASES_DICT[phrase])
        for idx, item in enumerate(py):
            py[idx] = _remove_dup_items(
                [_to_fixed(x, style=style, strict=strict) for x in item])
    else:
        for i in phrase:
            single = single_pinyin(i,
                                   style=style,
                                   heteronym=heteronym,
                                   errors=errors,
                                   strict=strict)
            if single:
                py.extend(single)
    return py
Example #3
0
    def _phrase_pinyin(self, phrase, style, heteronym, errors, strict):
        """词语拼音转换.

        :param phrase: 词语
        :param errors: 指定如何处理没有拼音的字符
        :param strict: 是否严格遵照《汉语拼音方案》来处理声母和韵母
        :return: 拼音列表
        :rtype: list
        """
        py = []
        if phrase in PHRASES_DICT:
            py = deepcopy(PHRASES_DICT[phrase])

            post_data = self.post_pinyin(phrase, heteronym, py)
            if post_data is not None:
                py = post_data

            for idx, item in enumerate(py):
                han = phrase[idx]
                if heteronym:
                    py[idx] = _remove_dup_items([
                        self.convert_style(han,
                                           orig_pinyin=x,
                                           style=style,
                                           strict=strict) for x in item
                    ])
                else:
                    orig_pinyin = item[0]
                    py[idx] = [
                        self.convert_style(han,
                                           orig_pinyin=orig_pinyin,
                                           style=style,
                                           strict=strict)
                    ]
        else:
            for i in phrase:
                single = self._single_pinyin(i,
                                             style=style,
                                             heteronym=heteronym,
                                             errors=errors,
                                             strict=strict)
                if single:
                    py.extend(single)
        return py