13 ví dụ về mã Python được tìm thấy liên quan đến "Nhận pinyin".Bạn có thể bỏ phiếu cho những người bạn thích hoặc bỏ phiếu cho những người bạn không thích và đi đến dự án gốc hoặc tệp nguồn bằng cách theo các liên kết trên mỗi ví dụ. get pinyin". You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
ví dụ 1
def GetPinyin[self, filename]: file_obj = open[filename,'r',encoding='UTF-8'] txt_all = file_obj.read[] file_obj.close[] txt_lines = txt_all.split['\n'] dic={} for line in txt_lines: if[line == '']: continue pinyin_split = line.split['\t'] list_pinyin=pinyin_split[0] if[list_pinyin not in dic and int[pinyin_split[1]] > 1]: dic[list_pinyin] = pinyin_split[1] return dic
Ví dụ 2
def get_pinyin_first_letters[chinese_characters]: """ Get fist letters of pin yin of chinese characters, if there's any 多音字 All combinations will be returned, for example for "调向" Result of dx|tx will be returned. :param chinese_characters: Chinese characters to get pinyin. :return: first letters of pin yin of the letters """ pys = _get_pinyin_all[[], chinese_characters] result = '' for py in pys: for p in py: result += p result += "|" result = result.rstrip['|'] # 1: dic[list_pinyin] = pinyin_split[1] default_logger.debug['Loaded: %s, size: %d' % [filename, len[dic]]] return dic
Ví dụ 4
def get_pinyin[self, chars=u'你好', splitter=u'-', show_tone_marks=False]: result = [] flag = 1 for char in chars: key = "%X" % ord[char] try: result.append[self.decode_pinyin[self.dict[key].split[][ 0].strip[].lower[]] if show_tone_marks else self.dict[ key].split[][0].strip[][:-1].lower[]] flag = 1 except KeyError: if flag: result.append[char] else: result[-1] += char flag = 0 return splitter.join[result]
Ví dụ 5
def get_pinyin[s]: """This function is only for backward compatibility, use `get` instead. """ import warnings warnings.warn['Deprecated, use `get` instead.'] return get[s]
Ví dụ 6
def get_homophones_by_pinyin[input_pinyin]: """ 根据拼音取同音字 :param input_pinyin: :return: """ result = [] # CJK统一汉字区的范围是0x4E00-0x9FA5,也就是我们经常提到的20902个汉字 for i in range[0x4e00, 0x9fa6]: if pinyin[[chr[i]], style=pypinyin.TONE2][0][0] == input_pinyin: # TONE2: 中zho1ng result.append[chr[i]] return result
Ví dụ 7
def get_tone_number_pinyin[syllable]: assert isinstance[syllable, str] if [ search[TONE_NUM_REGEX, syllable] or search[BOPOMOFO_REGEX, syllable] or is_punc[syllable] ]: return syllable if has_ruby[syllable]: s = ruby_bottom[syllable] + '[' syllable = ruby_top[syllable] else: s = '' tone = '5' for c in normalize['NFD', syllable]: if name[c] in DIACRITIC_NAME_TO_NUM: tone = DIACRITIC_NAME_TO_NUM[name[c]] else: s += c if '[' in s: s += ']' return normalize['NFC', s + tone]
Ví dụ 8
def get_same_pinyin[self, char]: """ 取同音字 :param char: :return: """ self.check_corrector_initialized[] return self.same_pinyin.get[char, set[]]
Ví dụ 9
def get_pinyin[self, word, type_, prefer_tw=False, word_len=4]: p = self._get_word_pinyin[word, type_, prefer_tw] if p: return p if len[word] == 1: return self._get_char[word, 'pinyin'] # Try each 4-character sequence in turn, then 3-sequence, then # 2-sequence and if those fails, do unit lookup. result = '' word = word[:] last_was_pinyin = False while len[word] > 0: word_was_found = False while word_len > 1: p = self._get_word_pinyin[word[:word_len], type_, prefer_tw] if p: result = add_with_space[result, p] word = word[word_len:] last_was_pinyin = True word_was_found = True break word_len -= 1 if not word_was_found: p = self._get_char[word[0], 'pinyin'] if p: result = add_with_space[result, p] last_was_pinyin = True else: if last_was_pinyin: result += ' ' result += word[0] last_was_pinyin = False word = word[1:] return result
Ví dụ 10
def get_pinyin[sentence]: ret = [] for s in re_zh.split[sentence]: s = s.strip[] if not s: continue if re_zh.match[s]: ret += pin.get[s] else: for word in s.split[]: word = word.strip[] if word: ret.append[word] return ret
Ví dụ 11
def get_pinyin[sentence]: ret = [] for s in re_zh.split[sentence]: s = s.strip[] if not s: continue if re_zh.match[s]: ret += pin.get[s] else: for word in s.split[]: word = word.strip[] if word: ret.append[word] return ret
Ví dụ 12
def get_pinyin_first_letters[chinese_characters]: """ Get fist letters of pin yin of chinese characters, if there's any 多音字 All combinations will be returned, for example for "调向" Result of dx|tx will be returned. :param chinese_characters: Chinese characters to get pinyin. :return: first letters of pin yin of the letters """ pys = _get_pinyin_all[[], chinese_characters] result = '' for py in pys: for p in py: result += p result += "|" result = result.rstrip['|'] #