由于汉字拼音转换表资源比较宝贵的缘故,网络上开源的转换程序
比较少。另外,网络上给出的码表,可能不能覆盖全部的多音字,
生僻字,所以基于此类码表写成的程序,也就有一定的局限性。
本文给出一份完毕的,将汉字转换成无声调标注的拼音的设计思
路、全部代码并且给出一份在一定程度上可用的汉字拼音转换表
void StringManipulation::FormatPinYinMap
(map
{
ifstream ifile("mycodebook.txt");
string line;
while (getline(ifile,line))
{
if (!line.empty())
{ wstring wsResult=String2Wstring(line);
vector
boost::split
(goodWordstemp,wsResult,boost::is_any_of(" "));
wstring mykey=goodWordstemp[0];
vector
for(vector
it=goodWordstemp.begin()+1;it!=goodWordstemp.end();it++)
{
myval.push_back
(Wstring2String(*it));
}
if (!hptable.count(mykey))
{
hptable[mykey]=myval;
}
}
}
}
单个汉字转换拼音的代码
vector
character,map
{
vector
if (hptable.count(character))
{
candidates=hptable[character];
}
else
{
candidates.push_back("[A-Z]+");
}
return candidates;
}
获得一汉字字符串的拼音串
/*********************************************************
***************/
/*获得一汉字字符串的拼音串
*/
/*********************************************************
***************/
vector
shan,map
{
vector
GraphRepresentation gr;
gr.Vertex[0]="@";
int mycount=0;//是否添加“正则边”
int prevsize=0;//上一个汉字有几个读音
int laslabel=0;//上一次节点编号的最大值
if (!shan.empty())
{
wstring whan=String2Wstring(shan);
for (wstring::iterator it=whan.begin
();it!=whan.end();it++)
{
wstring tmp;
tmp.assign(1,*it);
vector
(tmp,hptable);
if(mycount==0)
{
for (int
i=0;i
gr.Vertex
[i+laslabel+1]=tmpcandidates[i];
gr.GraphR
[make_pair(0,i+laslabel+1)]="&";
}
prevsize=tmpcandidates.size();
laslabel=tmpcandidates.size();
}
else
{
for (int
i=0;i
gr.Vertex
[i+laslabel+1]=tmpcandidates[i];
for (int
j=laslabel;j>laslabel-prevsize;j--)
{
gr.GraphR
[make_pair(j,i+laslabel+1)]=".*?";
}
}
laslabel+=tmpcandidates.size();
prevsize=tmpcandidates.size();
}
mycount++;
}
gr.Vertex[laslabel+1]="@";
for (int j=laslabel;j>laslabel-prevsize;j
--)
{
gr.GraphR[make_pair
(j,laslabel+1)]="&";
}
vector
gr.GetPaths(paths,0,laslabel+1);
for (vector
it=paths.begin();it!=paths.end();it++)
{
deque
string singlecandidate;
for (vector
rit=it->rbegin();rit!=it->rend();rit++)
{
tmpque.push_back(*rit);
if (tmpque.size()==2)
{
int
tmp1=tmpque.front();
tmpque.pop_front
();
singlecandidate+=gr.Vertex[tmp1];
int
tmp2=tmpque.front();
string
edge=gr.GraphR[make_pair(tmp1,tmp2)];
singlecandidate+=edge;
}
}
TrimString(singlecandidate,"@");
TrimString(singlecandidate,"&");
result.push_back(singlecandidate);
}
}
return result;
}
茶杯头甜蜜终章dlc 官方手机版v1.0.0.3
下载火柴人传说暗影格斗内置菜单 最新版v3.0.1
下载荒野乱斗测试服 安卓版v61.10.3
下载荒野乱斗彩虹服 安卓版v61.10.3
下载寒霜启示录 安卓版v1.25.10
寒霜启示录是一款生存模拟游戏,不少玩家可能对于末日都有着自己
末日城堡免广告版 安卓最新版v0.7.1
末日城堡免广告版是一款非常好玩的模拟经营类游戏,内部可以不看
甜蜜人生模拟器 最新版v1.4.5
甜蜜人生模拟器是一款非常好玩的模拟恋爱手游,玩家在这里能够对
武器锻造师内置功能菜单 v10.4
武器锻造师内置菜单版是游戏的破解版本,在该版本中为玩家提供了
开放空间overfield 安卓版v1.0.5
开放空间Overfield是一款箱庭养成经营手游,让你在广阔