本文整理汇总了Python中pypinyin.lazy_pinyin函数的典型用法代码示例。如果您正苦于以下问题:Python lazy_pinyin函数的具体用法?Python lazy_pinyin怎么用?Python lazy_pinyin使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了lazy_pinyin函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: change_pinyin
def change_pinyin(name):
ret =lazy_pinyin(name,errors='ignore')
short_cut = lazy_pinyin(name, style=Style.FIRST_LETTER)
result = ret[:1]+short_cut[1:]
# 返回不同组合的名字
return ''.join(ret),'_'.join(ret),'_'.join(ret[:2])+''.join(ret[2:]),''.join(result),'_'.join(result[:2])+''.join(result[2:])
开发者ID:Rockyzsu,项目名称:base_function,代码行数:7,代码来源:pinyin_usage.py
示例2: get_confusion_word_set
def get_confusion_word_set(word):
confusion_word_set = set()
candidate_words = list(known(edit_distance_word(word, cn_char_set)))
for candidate_word in candidate_words:
if lazy_pinyin(candidate_word) == lazy_pinyin(word):
# same pinyin
confusion_word_set.add(candidate_word)
return confusion_word_set
开发者ID:djk111,项目名称:pycorrector,代码行数:8,代码来源:corrector.py
示例3: test_custom_pinyin_dict
def test_custom_pinyin_dict():
hans = '桔'
try:
assert lazy_pinyin(hans, style=TONE2) == ['ju2']
except AssertionError:
pass
load_single_dict({ord('桔'): 'jú,jié'})
assert lazy_pinyin(hans, style=TONE2) == ['ju2']
开发者ID:zhaochl,项目名称:python-pinyin,代码行数:8,代码来源:test_pinyin.py
示例4: test_custom_pinyin_dict2
def test_custom_pinyin_dict2():
hans = ['同行']
try:
assert lazy_pinyin(hans, style=TONE2) == ['to2ng', 'ha2ng']
except AssertionError:
pass
load_phrases_dict({'同行': [['tóng'], ['xíng']]})
assert lazy_pinyin(hans, style=TONE2) == ['to2ng', 'xi2ng']
开发者ID:zhaochl,项目名称:python-pinyin,代码行数:8,代码来源:test_pinyin.py
示例5: create_device_user
def create_device_user(redis, request):
_uuid = request.get("uuid")
if not _uuid:
logging.error("no uuid provided. %s" % request)
return None
_is_service_user = bool(request.get("is_service_user"))
_is_anonymous_user = bool(request.get("is_anonymous_user"))
_is_owner_user = bool(request.get("is_owner_user"))
_user_email = request.get("user_email")
if not _user_email:
import strgen
_user_email = strgen.StringGenerator("[\d\w]{10}").render() + "@" + strgen.StringGenerator("[\d\w]{10}").render()
_user_icon = request.get("user_icon")
if not _user_icon:
_user_icon = random_identicon(_user_email)
_user_name = request.get("user_name")
_user_mobile = request.get("user_mobile")
_user_fullname = request.get("user_fullname")
_user_password = request.get("user_password")
_user_language = request.get("user_language") or "cn"
_ent_user_uuid = request.get("ent_user_uuid")
_ent_user_createtime = request.get("ent_user_createtime")
import pypinyin
if not isinstance(_user_fullname, unicode):
_user_fullname = _user_fullname.decode("utf-8")
_user_pinyin = "".join(pypinyin.lazy_pinyin(_user_fullname))
_user_py = "".join(pypinyin.lazy_pinyin(_user_fullname, style=pypinyin.FIRST_LETTER))
_values = {
"uuid": _uuid,
"is_service_user": _is_service_user,
"is_owner_user": _is_owner_user,
"is_ppmessage_user": _is_ppmessage_user,
"is_anonymous_user": _is_anonymous_user,
"user_name": _user_name,
"user_mobile": _user_mobile,
"user_email": _user_email,
"user_icon": _user_icon,
"user_fullname": _user_fullname,
"user_password": _user_password,
"user_pinyin": _user_pinyin,
"user_py": _user_py,
"ent_user_uuid": _ent_user_uuid,
"ent_user_createtime": _ent_user_createtime
}
_row = DeviceUser(**_values)
_row.async_add(redis)
_row.create_redis_keys(redis)
return _values
开发者ID:anxiaoyi,项目名称:ppmessage,代码行数:57,代码来源:deviceuser.py
示例6: test_errors_callable
def test_errors_callable():
def foobar(chars):
return 'a' * len(chars)
class Foobar(object):
def __call__(self, chars):
return 'a' * len(chars)
n = 5
assert lazy_pinyin('あ' * n, errors=foobar) == ['a' * n]
assert lazy_pinyin('あ' * n, errors=Foobar()) == ['a' * n]
开发者ID:zhaochl,项目名称:python-pinyin,代码行数:11,代码来源:test_pinyin.py
示例7: post_or_put
def post_or_put(pk=None, dic=None):
tobj = dic_to_tobj(dic, thirdparty_svc.ers.TCity, True)
if not tobj.pinyin:
tobj.pinyin = ''.join(lazy_pinyin(tobj.name, errors='ignore'))
if not tobj.abbr:
tobj.abbr = ''.join(
lazy_pinyin(tobj.name, style=FIRST_LETTER, errors='ignore')).upper()
if not tobj.sort:
tobj.sort = 2000
with thrift_client('ers') as ers:
result = ers.save_city(pk, tobj)
return result
开发者ID:liuzelei,项目名称:walis,代码行数:12,代码来源:city.py
示例8: _du
def _du(self):
_request = json.loads(self.request.body)
_user_uuid = _request.get("user_uuid")
if not _user_uuid:
self.setErrorCode(API_ERR.NO_PARA)
return
_o = redis_hash_to_dict(self.application.redis, DeviceUser, _user_uuid)
if not _o:
self.setErrorCode(API_ERR.NO_OBJECT)
return
# not return the password default
return_password = False
if "return_password" in _request:
return_password = _request["return_password"]
if not return_password:
del _o["user_password"]
_fn = _o.get("user_fullname")
if _fn != None and not isinstance(_fn, unicode):
_fn = _fn.decode("utf-8")
_rdata = self.getReturnData()
_rdata.update(_o)
_rdata["pinyinname0"] = "".join(lazy_pinyin(_fn))
_rdata["pinyinname1"] = "".join(list(itertools.chain.from_iterable(pinyin(_fn, style=pypinyin.INITIALS))))
_app_uuid = _get_config().get("team").get("app_uuid")
_o = redis_hash_to_dict(self.application.redis, AppInfo, _app_uuid)
_rdata.update({"team": _o});
return
开发者ID:anxiaoyi,项目名称:ppmessage,代码行数:34,代码来源:ppgetuserdetailhandler.py
示例9: process_item
def process_item(self, item, spider):
if spider.name=='songs':
try:
cursor1=self.db.cursor()
author_id=0
keys=lazy_pinyin(item['author']+'_'+item['dynasty'])
key=''.join(keys)
kwd=''
if self.redis_conn.hexists('author',item['author_id']):
kwd=item['author_id']
elif self.redis_conn.hexists('author',key):
kwd=key
if kwd!='':
author_id=self.redis_conn.hget('author',kwd)
else:
sql="insert into `author` (`name`,`dynasty`,`pinyin`) values(%s,%s,%s)"
cursor1.execute(sql,[item['author'],item['dynasty'],item['pinyin']])
author_id=str(cursor1.lastrowid)
self.redis_conn.hsetnx('author',key,author_id)
created=int(time.time())
sql1="insert into `content` (`author_id`,`title`,`created`,`view_url`,`comment_num`,`point`,`content`) values(%s,%s,%s,%s,%s,%s,%s)"
cursor1.execute(sql1,[author_id,item['title'],created,item['view_url'],item['comment_nums'],item['point'],item['content']])
cursor1.close()
except mysql.connector.Error as e:
msg=u'view_url:%s 写入数据失败:%s' % (item['view_url'],e)
logger.error(msg)
cursor1.close()
finally:
cursor1.close()
return item
else:
return item
开发者ID:yunyu2019,项目名称:blog,代码行数:32,代码来源:pipelines.py
示例10: txt_to_voice
def txt_to_voice(text, name='test', export_path=EXPORT_PATH):
"""
将文字转换为音频
:param text: 需要转换的文字
:param name: 生成的音频文件名
:return:
"""
pinyin_list = lazy_pinyin(text, style=TONE3)
new = AudioSegment.empty()
for piny in pinyin_list:
piny_song = VOICE_DICT.get(piny)
if piny_song is None and piny and piny[-1] not in '0123456789':
# 没有音调
piny = piny + '5'
piny_song = VOICE_DICT.get(piny, silent)
# 交叉渐入渐出方法
# with_style = beginning.append(end, crossfade=1500)
# crossfade 就是让一段音乐平缓地过渡到另一段音乐,crossfade = 1500 表示过渡的时间是1.5秒。
# if new and piny_song:
# crossfade = min(len(new), len(piny_song), 1500)/60
# new = new.append(piny_song, crossfade=crossfade)
if not piny_song:
continue
new += piny_song
new.export(os.path.join(export_path, "{}.mp3".format(name)), format='mp3')
开发者ID:gswyhq,项目名称:hello-world,代码行数:27,代码来源:文字转换成语音.py
示例11: doTarget
def doTarget(isp, ipList):
fd =open(target,'a')
if isp == 'tel':
title = 'telcom'
menu = '中国电信'
elif isp == 'uni':
title = 'unicom'
menu = '中国联通'
elif isp =='mob':
title = 'CMCC'
menu = '中国移动'
else :
title = 'EDU'
menu = '中国教育'
line = "+%s\nmenu = %s\ntitle = %s\n\n" % (title, menu, title)
fd.writelines(line)
for ip in ipList.keys():
subTitle = ''.join(lazy_pinyin(ipList[ip]))+"-"+ip.split('.')[0]
line2 = '++%s\nmenu = %s\ntitle = %s\nhost = %s\n\n' %(subTitle, ipList[ip].encode('utf8'), ip, ip)
fd.writelines(line2)
fd.close()
开发者ID:langlangago,项目名称:sa-scripts,代码行数:26,代码来源:doSmokepingTarget.py
示例12: _du
def _du(self, _request, _rdata):
if "user_uuid" not in _request:
self.setErrorCode(API_ERR.NO_PARA)
logging.error("Error for no para: %s.", (str(_request)))
return
_o = redis_hash_to_dict(self.application.redis, DeviceUser, _request["user_uuid"])
logging.info(_o)
if _o == None:
self.setErrorCode(API_ERR.NO_OBJECT)
logging.error("Error for no user uuid: %s." % (_request["user_uuid"]))
return
# not return the password default
return_password = False
if "return_password" in _request:
return_password = _request["return_password"]
if not return_password:
del _o["user_password"]
_fn = _o.get("user_fullname")
if _fn != None and not isinstance(_fn, unicode):
_fn = _fn.decode("utf-8")
_rdata.update(_o)
_rdata["pinyinname0"] = "".join(lazy_pinyin(_fn))
_rdata["pinyinname1"] = "".join(list(itertools.chain.from_iterable(pinyin(_fn, style=pypinyin.INITIALS))))
return
开发者ID:Michael2008S,项目名称:ppmessage,代码行数:31,代码来源:ppgetuserdetailhandler.py
示例13: CJKFirstLetters
def CJKFirstLetters(str):
pinyins = lazy_pinyin(str)
firstLetters = ''
for pinyin in pinyins:
firstLetters += pinyin[0]
return firstLetters
开发者ID:twotreeszf,项目名称:Sony-Walkman-Sorter,代码行数:7,代码来源:SortFilesForce.py
示例14: initial
def initial(folderName, type):
documents = os.listdir('./'+folderName+'/')
index = 1
# the same sequence with model in models.py
model = {}
documentModel = {}
wordModel = {}
ld = len(documents)
if type == 0:
hrefList = open('./html_sohu.txt', 'r').readlines()
titleList = open('./title_sohu.txt', 'r').readlines()
for document in documents:
if index % 50 == 0:
print str(index) + ' / ' + str(ld)
documentName = document[0:4]
documentModel[documentName] = {'length': 0, 'href': hrefList[int(documentName)-1].split('\n')[0].split('\t')[1], 'title':titleList[int(documentName)-1].split('\n')[0].split('\t')[1]}
words = open('./'+folderName+'/'+document, 'r').readlines()
for word in words:
singleWord = word.split('\n')[0]
if len(singleWord) < 3:
continue
singleWordUnicode = singleWord.decode('utf-8')
pinyins = lazy_pinyin(singleWordUnicode)
pinyinStr = ''
for pinyin in pinyins:
pinyinStr = pinyinStr + pinyin.encode('utf-8')
if len(pinyinStr) < 2:
continue
if (singleWord in wordModel) == False:
wordModel[singleWord] = {'length': len(pinyins), 'idf': 0, 'pinyin': pinyinStr}
if ((singleWord, documentName) in model) == False:
model[(singleWord, documentName)] = {'tfIdf': 0, 'times': 1, 'tf': 0}
else:
times = model[(singleWord, documentName)]['times'] + 1
model[(singleWord, documentName)]['times'] = times
index = index + 1
else:
hrefList = open('./html_wiki.txt', 'r').readlines()
titleList = open('./title_wiki.txt', 'r').readlines()
for document in documents:
if index % 50 == 0:
print str(index) + ' / ' + str(ld)
documentName = document[0:4]
documentModel[documentName] = {'length': 0, 'href': hrefList[int(documentName)-1].split('\n')[0].split('\t')[1], 'title':titleList[int(documentName)-1].split('\n')[0].split('\t')[1]}
words = open('./'+folderName+'/'+document, 'r').readlines()
for word in words:
singleWord = word.split('\n')[0]
l = len(singleWord)
if l < 3 or l > 15:
continue
if (singleWord in wordModel) == False:
wordModel[singleWord] = {'length': l, 'idf': 0}
if ((singleWord, documentName) in model) == False:
model[(singleWord, documentName)] = {'tfIdf': 0, 'times': 1, 'tf': 0}
else:
times = model[(singleWord, documentName)]['times'] + 1
model[(singleWord, documentName)]['times'] = times
index = index + 1
return model, documentModel, wordModel
开发者ID:xzr12,项目名称:IR,代码行数:60,代码来源:search.py
示例15: correctOneWord
def correctOneWord(oldWord):
word = oldWord.decode('utf-8')
pyList = lazy_pinyin(word)
pyStr = ""
maxSame = 0
resultWord = ""
same = 0
count = 0
for py in pyList:
pyStr+=py.encode('utf-8')
print pyStr
result = ChineseWordModel.objects.filter(pinyin=pyStr).order_by('idf')
if len(result) == 0:
print "pinyin do not exist"
return oldWord
for r in result:
print r['word']
print r['idf']
same = findSameChar(word,r['word'])
if(same>maxSame):
maxSame = same
resultWord = r['word']
print "maxSame",maxSame
if maxSame == 0:
resultWord = result[0]['word']
print "no similar word"
return resultWord
开发者ID:xzr12,项目名称:IR,代码行数:27,代码来源:corrector_CH.py
示例16: parse
def parse(self,response):
hxs=Selector(response)
items=[]
allSite=hxs.xpath('//ul/li[1]/dl/dt/a')
if len(allSite)>0:
url = response.url
province = os.path.basename(url)
item=ProvinceItem()
item['link'] = allSite.xpath('@href').extract()[0]
item['code'] = self.city_codes.get(province)
items.append(item)
sites=hxs.xpath('//ul/li[1]/dl/dd/a')
for site in sites:
item=ProvinceItem()
item['name'] = site.xpath('text()').extract()[0]
item['link'] = site.xpath('@href').extract()[0]
item['code'] = int(os.path.basename(item['link']).split('-')[0])
item['parent'] = item['code'] - item['code'] % 100
item['pinyin'] = ''.join(lazy_pinyin(item['name']))
items.append(item)
#self.saveCity(item);
for item in items:
yield Request(item['link'],meta={'code':item['code']},callback=self.parse2)
开发者ID:wirror800,项目名称:crawler,代码行数:25,代码来源:province_spider.py
示例17: parse_profile
def parse_profile(self,response):
hxs=Selector(response)
item=response.meta['item']
page=response.meta['page']
cont=hxs.xpath('//div[@class="mm-p-info mm-p-base-info"]')
ls=cont.xpath('ul/li/span').extract()
ls1=cont.xpath('ul/li/p').extract()
lists=map(filterHtml,ls)
profiles=map(filterHtml,ls1)
exprince=hxs.xpath('//div[@class="mm-p-info mm-p-experience-info"]/p').extract()
item['nicename']=lists[0].strip()
item['borthday']=lists[1].replace(u'\xa0','')
item['job'] =lists[3].strip(u'型')
item['blood'] =lists[4].strip(u'型')
item['school'] =''
item['specialty'] =''
if lists[5]!='':
m=re.split(u'\xa0{2,}',lists[5])
if len(m)>1:
item['school'] =m[0]
item['specialty'] =m[1]
item['style'] =lists[6].strip()
item['height'] =profiles[0].strip('CM')
item['weight'] =profiles[1].strip('KG')
item['solid'] =profiles[2].strip()
item['bar'] =bar(profiles[3])
item['shoes'] =profiles[4].strip(u'码')
item['exprince']=filterHtml(exprince[0])
left_img=hxs.xpath('//div[@class="mm-p-modelCard"]/a/img/@src').extract()
item['life_img']='https:'+left_img[0] if left_img else ''
item['image_urls']=[item['faceimg'],item['big_img'],item['life_img']]
username=lazy_pinyin(item['nicename'])
item['pinyin']=''.join(username)
yield item
开发者ID:yunyu2019,项目名称:blog,代码行数:34,代码来源:taobao.py
示例18: delete
def delete(self, item, pinyin=False, seg=False):
self.item_check(item)
uid = hashlib.md5(item['term'].encode('utf8')).hexdigest()
for prefix in self.prefixs_for_term(item['term'], seg=seg):
self._delete_prefix(prefix, uid)
if pinyin:
prefix_pinyin = ''.join(lazy_pinyin(prefix))
self._delete_prefix(prefix_pinyin, uid)
开发者ID:xuyaoqiang,项目名称:search_prompt,代码行数:8,代码来源:search_prompt.py
示例19: save
def save(self, *args, **kwargs):
# 输入中文
if self.simple_name == '' or self.simple_name == None:
self.simple_name = '-'.join(lazy_pinyin(self.name))
# 输入英文
if self.simple_name == '' or self.simple_name == None:
self.simple_name = self.name
super(Category, self).save(*args, **kwargs)
开发者ID:Hainuer,项目名称:website,代码行数:8,代码来源:models.py
示例20: weather_crawler
def weather_crawler(city):
city_pinyin = ''.join(lazy_pinyin(city))
weather_url = 'http://lishi.tianqi.com/{}/index.html'.format(city_pinyin)
weather_web_data = requests.get(weather_url)
weather_soup = BeautifulSoup(weather_web_data.text,'lxml')
weather = weather_soup.select(' div.tqtongji > p')[0].get_text()[0:-15]
wind = weather_soup.select(' div.tqtongji > ul')[1].get_text().replace('\n',' ')
print(weather,'\n\n'+'风力情况为:\n',wind)
开发者ID:yunxingwoo,项目名称:Spider_app,代码行数:8,代码来源:city.py
注:本文中的pypinyin.lazy_pinyin函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论