圆月山庄资源网 Design By www.vgjia.com
后来想到自己Delphi有一个获得拼音的代码。于是找了出来。研究了一下代码如下:
复制代码 代码如下:
function get_hz_pywb(hzstr: string; pytype: integer): string;
var
I: Integer;
allstr: string;
hh: THandle;
pp: pointer;
ss: TStringList;
function retturn_wbpy(tempstr: string; tqtype: integer): string;
var
outstr, str: string;
i: integer;
begin
//################### 汉字查询电位
i := 0;
while i <= ss.Count - 1 do
begin
str := ss.Strings[i];
if (tempstr = trim(str[1] + str[2])) or (tempstr = trim(str[3] + str[4])) then
begin
str := ss.Strings[i];
Break;
end;
i := i + 1;
end;
//###################
outstr := ''; //提取编码
if tqtype = 1 then
begin
for i := pos('①', str) + 2 to pos('②', str) - 1 do
if str[i] <> '' then if outstr = '' then outstr := str[i] else outstr := outstr + str[i];
end;
if tqtype = 2 then
begin
for i := pos('②', str) + 2 to pos('③', str) - 1 do
if str[i] <> '' then if outstr = '' then outstr := str[i] else outstr := outstr + str[i];
end;
if tqtype = 3 then
begin
for i := pos('③', str) + 2 to pos('④', str) - 1 do
if str[i] <> '' then if outstr = '' then outstr := str[i] else outstr := outstr + str[i];
end;
if tqtype = 4 then
begin
for i := pos('④', str) + 2 to length(str) do
if str[i] <> '' then if outstr = '' then outstr := str[i] else outstr := outstr + str[i];
end;
Result := trim(outstr);
end;
begin
//加载资源文件,将内容赋值给 s
ss := TStringList.Create;
hh := FindResource(hInstance, 'mywb', 'TXT');
hh := LoadResource(hInstance, hh);
pp := LockResource(hh);
ss.Text := pchar(pp);
UnLockResource(hh);
FreeResource(hh);
allstr := '';
i := 0;
while i <= length(hzstr) do //提取汉字字符
begin
if (Ord(hzstr[I]) > 127) then
begin
if allstr = '' then
allstr := retturn_wbpy(hzstr[I] + hzstr[I + 1], pytype)
else
allstr := allstr + retturn_wbpy(hzstr[I] + hzstr[I + 1], pytype);
i := i + 2;
end
else
begin
if allstr = '' then allstr := hzstr[I] else allstr := allstr + hzstr[I];
i := i + 1;
end;
end;
ss.Free;
Result := trim(allstr);
en
function get_hz_pywb(hzstr: string; pytype: integer): string;
var
I: Integer;
allstr: string;
hh: THandle;
pp: pointer;
ss: TStringList;
function retturn_wbpy(tempstr: string; tqtype: integer): string;
var
outstr, str: string;
i: integer;
begin
//################### 汉字查询电位
i := 0;
while i <= ss.Count - 1 do
begin
str := ss.Strings[i];
if (tempstr = trim(str[1] + str[2])) or (tempstr = trim(str[3] + str[4])) then
begin
str := ss.Strings[i];
Break;
end;
i := i + 1;
end;
//###################
outstr := ''; //提取编码
if tqtype = 1 then
begin
for i := pos('①', str) + 2 to pos('②', str) - 1 do
if str[i] <> '' then if outstr = '' then outstr := str[i] else outstr := outstr + str[i];
end;
if tqtype = 2 then
begin
for i := pos('②', str) + 2 to pos('③', str) - 1 do
if str[i] <> '' then if outstr = '' then outstr := str[i] else outstr := outstr + str[i];
end;
if tqtype = 3 then
begin
for i := pos('③', str) + 2 to pos('④', str) - 1 do
if str[i] <> '' then if outstr = '' then outstr := str[i] else outstr := outstr + str[i];
end;
if tqtype = 4 then
begin
for i := pos('④', str) + 2 to length(str) do
if str[i] <> '' then if outstr = '' then outstr := str[i] else outstr := outstr + str[i];
end;
Result := trim(outstr);
end;
begin
//加载资源文件,将内容赋值给 s
ss := TStringList.Create;
hh := FindResource(hInstance, 'mywb', 'TXT');
hh := LoadResource(hInstance, hh);
pp := LockResource(hh);
ss.Text := pchar(pp);
UnLockResource(hh);
FreeResource(hh);
allstr := '';
i := 0;
while i <= length(hzstr) do //提取汉字字符
begin
if (Ord(hzstr[I]) > 127) then
begin
if allstr = '' then
allstr := retturn_wbpy(hzstr[I] + hzstr[I + 1], pytype)
else
allstr := allstr + retturn_wbpy(hzstr[I] + hzstr[I + 1], pytype);
i := i + 2;
end
else
begin
if allstr = '' then allstr := hzstr[I] else allstr := allstr + hzstr[I];
i := i + 1;
end;
end;
ss.Free;
Result := trim(allstr);
en
这里需要用到一个资源文件。随后我会把资源文件地址发上来。
我把他改成Python代码供大家研究。。。。
复制代码 代码如下:
# -*-coding:utf-8-*-
# 返回汉字的拼音
def Return_pinyin(word):
global reslist
for line in reslist:
if (word==line[0]+line[1]) or (word==line[2]+line[3]):
str = line
break
# 取①和②之间的内容
s = str.find(u'①')+4
e = str.find(u'②')+3
return str[s:e]
def GetPy(word):
#首先装载资源文件
i=0
allstr = ''
while i<len(word):
if ord(word[i])>127:
if allstr:
allstr += Return_pinyin(word[i]+word[i+1])
else:
allstr = Return_pinyin(word[i]+word[i+1])
i +=2
else:
if allstr:
allstr += word[i]
else:
allstr = word[i]
i +=1
return allstr
if __name__=='__main__':
f = open('wbtext1.txt','r')
reslist = f.readlines()
f.close()
word = raw_input(u'请输入汉字: ')
print GetPy(word).lower()
如果大家有什么问题欢迎讨论。。。。。。
复制代码 代码如下:
function get_hz_pywb(hzstr: string; pytype: integer): string;
var
I: Integer;
allstr: string;
hh: THandle;
pp: pointer;
ss: TStringList;
function retturn_wbpy(tempstr: string; tqtype: integer): string;
var
outstr, str: string;
i: integer;
begin
//################### 汉字查询电位
i := 0;
while i <= ss.Count - 1 do
begin
str := ss.Strings[i];
if (tempstr = trim(str[1] + str[2])) or (tempstr = trim(str[3] + str[4])) then
begin
str := ss.Strings[i];
Break;
end;
i := i + 1;
end;
//###################
outstr := ''; //提取编码
if tqtype = 1 then
begin
for i := pos('①', str) + 2 to pos('②', str) - 1 do
if str[i] <> '' then if outstr = '' then outstr := str[i] else outstr := outstr + str[i];
end;
if tqtype = 2 then
begin
for i := pos('②', str) + 2 to pos('③', str) - 1 do
if str[i] <> '' then if outstr = '' then outstr := str[i] else outstr := outstr + str[i];
end;
if tqtype = 3 then
begin
for i := pos('③', str) + 2 to pos('④', str) - 1 do
if str[i] <> '' then if outstr = '' then outstr := str[i] else outstr := outstr + str[i];
end;
if tqtype = 4 then
begin
for i := pos('④', str) + 2 to length(str) do
if str[i] <> '' then if outstr = '' then outstr := str[i] else outstr := outstr + str[i];
end;
Result := trim(outstr);
end;
begin
//加载资源文件,将内容赋值给 s
ss := TStringList.Create;
hh := FindResource(hInstance, 'mywb', 'TXT');
hh := LoadResource(hInstance, hh);
pp := LockResource(hh);
ss.Text := pchar(pp);
UnLockResource(hh);
FreeResource(hh);
allstr := '';
i := 0;
while i <= length(hzstr) do //提取汉字字符
begin
if (Ord(hzstr[I]) > 127) then
begin
if allstr = '' then
allstr := retturn_wbpy(hzstr[I] + hzstr[I + 1], pytype)
else
allstr := allstr + retturn_wbpy(hzstr[I] + hzstr[I + 1], pytype);
i := i + 2;
end
else
begin
if allstr = '' then allstr := hzstr[I] else allstr := allstr + hzstr[I];
i := i + 1;
end;
end;
ss.Free;
Result := trim(allstr);
en
function get_hz_pywb(hzstr: string; pytype: integer): string;
var
I: Integer;
allstr: string;
hh: THandle;
pp: pointer;
ss: TStringList;
function retturn_wbpy(tempstr: string; tqtype: integer): string;
var
outstr, str: string;
i: integer;
begin
//################### 汉字查询电位
i := 0;
while i <= ss.Count - 1 do
begin
str := ss.Strings[i];
if (tempstr = trim(str[1] + str[2])) or (tempstr = trim(str[3] + str[4])) then
begin
str := ss.Strings[i];
Break;
end;
i := i + 1;
end;
//###################
outstr := ''; //提取编码
if tqtype = 1 then
begin
for i := pos('①', str) + 2 to pos('②', str) - 1 do
if str[i] <> '' then if outstr = '' then outstr := str[i] else outstr := outstr + str[i];
end;
if tqtype = 2 then
begin
for i := pos('②', str) + 2 to pos('③', str) - 1 do
if str[i] <> '' then if outstr = '' then outstr := str[i] else outstr := outstr + str[i];
end;
if tqtype = 3 then
begin
for i := pos('③', str) + 2 to pos('④', str) - 1 do
if str[i] <> '' then if outstr = '' then outstr := str[i] else outstr := outstr + str[i];
end;
if tqtype = 4 then
begin
for i := pos('④', str) + 2 to length(str) do
if str[i] <> '' then if outstr = '' then outstr := str[i] else outstr := outstr + str[i];
end;
Result := trim(outstr);
end;
begin
//加载资源文件,将内容赋值给 s
ss := TStringList.Create;
hh := FindResource(hInstance, 'mywb', 'TXT');
hh := LoadResource(hInstance, hh);
pp := LockResource(hh);
ss.Text := pchar(pp);
UnLockResource(hh);
FreeResource(hh);
allstr := '';
i := 0;
while i <= length(hzstr) do //提取汉字字符
begin
if (Ord(hzstr[I]) > 127) then
begin
if allstr = '' then
allstr := retturn_wbpy(hzstr[I] + hzstr[I + 1], pytype)
else
allstr := allstr + retturn_wbpy(hzstr[I] + hzstr[I + 1], pytype);
i := i + 2;
end
else
begin
if allstr = '' then allstr := hzstr[I] else allstr := allstr + hzstr[I];
i := i + 1;
end;
end;
ss.Free;
Result := trim(allstr);
en
这里需要用到一个资源文件。随后我会把资源文件地址发上来。
我把他改成Python代码供大家研究。。。。
复制代码 代码如下:
# -*-coding:utf-8-*-
# 返回汉字的拼音
def Return_pinyin(word):
global reslist
for line in reslist:
if (word==line[0]+line[1]) or (word==line[2]+line[3]):
str = line
break
# 取①和②之间的内容
s = str.find(u'①')+4
e = str.find(u'②')+3
return str[s:e]
def GetPy(word):
#首先装载资源文件
i=0
allstr = ''
while i<len(word):
if ord(word[i])>127:
if allstr:
allstr += Return_pinyin(word[i]+word[i+1])
else:
allstr = Return_pinyin(word[i]+word[i+1])
i +=2
else:
if allstr:
allstr += word[i]
else:
allstr = word[i]
i +=1
return allstr
if __name__=='__main__':
f = open('wbtext1.txt','r')
reslist = f.readlines()
f.close()
word = raw_input(u'请输入汉字: ')
print GetPy(word).lower()
如果大家有什么问题欢迎讨论。。。。。。
标签:
Python,汉语拼音
圆月山庄资源网 Design By www.vgjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
圆月山庄资源网 Design By www.vgjia.com
暂无评论...
更新日志
2024年11月08日
2024年11月08日
- 雨林唱片《赏》新曲+精选集SACD版[ISO][2.3G]
- 罗大佑与OK男女合唱团.1995-再会吧!素兰【音乐工厂】【WAV+CUE】
- 草蜢.1993-宝贝对不起(国)【宝丽金】【WAV+CUE】
- 杨培安.2009-抒·情(EP)【擎天娱乐】【WAV+CUE】
- 周慧敏《EndlessDream》[WAV+CUE]
- 彭芳《纯色角3》2007[WAV+CUE]
- 江志丰2008-今生为你[豪记][WAV+CUE]
- 罗大佑1994《恋曲2000》音乐工厂[WAV+CUE][1G]
- 群星《一首歌一个故事》赵英俊某些作品重唱企划[FLAC分轨][1G]
- 群星《网易云英文歌曲播放量TOP100》[MP3][1G]
- 方大同.2024-梦想家TheDreamer【赋音乐】【FLAC分轨】
- 李慧珍.2007-爱死了【华谊兄弟】【WAV+CUE】
- 王大文.2019-国际太空站【环球】【FLAC分轨】
- 群星《2022超好听的十倍音质网络歌曲(163)》U盘音乐[WAV分轨][1.1G]
- 童丽《啼笑姻缘》头版限量编号24K金碟[低速原抓WAV+CUE][1.1G]