Rss & SiteMap

搭建论坛 http://bbs.diylsoft.com:8118/starforum/index.asp

搭建论坛是“搭建式”中文软件开发工具《搭建之星》、《网站·搭建者》技术交流的地方。
共17 条记录, 每页显示 10 条, 页签: [1] [2]
[浏览完整版]

标题:[建议]增加拼音解析功能

1楼
pc_doctor 发表于:2007-4-17 18:15:13

在数据库应用中,为了快速或模糊查询,往往需要根据查询内容的汉语拼音声母来进行查询。

比如,通过‘姓名’查询时,由于中国文字的多音字很多,在不知道确凿文字而准确输入时很难查询到结果。

——可以将姓名‘孙悟空’用快速识别码——汉语拼音声母“SWK”来进行快速模糊查询,尽管会出现多个结果,但,也比盲目输入汉字去碰运气还是来得快些。特别方便中老年客户或大型数据库。

很多数据库系统都有此必备功能,过去鼓捣FOX时就能写出此功能。

——希望公司重视这个数据库必备功能,尽快完善!

——现如今,能有其他办法能在《星》中实现吗?

2楼
FSJM 发表于:2007-4-18 7:52:33
凡是数据库拥有的功能,《星》都可以通过SQL语言调用,不存在你所说的完善问题。
3楼
admin 发表于:2007-4-18 14:30:01
如主贴所述功能,都是在开发具体的数据库项目时所要做的工作,在数据库中建立一个对照表就可以了,搭建之星、搭建者,它本身是一个通用的开发工具。
4楼
春林 发表于:2007-4-18 14:56:28

好像不是这样......

5楼
FSJM 发表于:2007-4-18 15:32:53

你可以提一个解决方案。

6楼
pc_doctor 发表于:2007-4-18 20:28:59
以下是引用FSJM在2007-4-18 7:52:33的发言:
凡是数据库拥有的功能,《星》都可以通过SQL语言调用,不存在你所说的完善问题。

FSJM,你没明白主贴的意思还是误会了呢?!

我是指但凡一个数据库管理系统都需要的一个应用功能。见图示:


此主题相关图片如下:
按此在新窗口浏览图片


如按照ADMIN所说,建一对照表来实现恐怕是不行的吧!这个庞大的未知对照表,是无法建立的。

应该要有专门的一个解析的构件来完成才可行的。
这确实是一个数据库管理系统的必备功能啊!

7楼
水手 发表于:2007-4-19 12:29:13
以前给ADMIN发过邮件,提供了一些这方面资料,希望公司能够参考,增加这方面的功能,是非常必要的。
8楼
水手 发表于:2007-4-19 12:39:29

提供搜集的相关参考资料供大家参考:

1、获取汉字的第一个拼音

typedef struct {
const char * pinyin;
int code;
} PAIR;

static PAIR table[] =
{
{ "a",-20319 },
{ "ai",-20317 },
{ "an",-20304 },
{ "ang",-20295 },
{ "ao",-20292 },
{ "ba",-20283 },
{ "bai",-20265 },
{ "ban",-20257 },
{ "bang",-20242 },
{ "bao",-20230 },
{ "bei",-20051 },
{ "ben",-20036 },
{ "beng",-20032 },
{ "bi",-20026 },
{ "bian",-20002 },
{ "biao",-19990 },
{ "bie",-19986 },
{ "bin",-19982 },
{ "bing",-19976 },
{ "bo",-19805 },
{ "bu",-19784 },
{ "ca",-19775 },
{ "cai",-19774 },
{ "can",-19763 },
{ "cang",-19756 },
{ "cao",-19751 },
{ "ce",-19746 },
{ "ceng",-19741 },
{ "cha",-19739 },
{ "chai",-19728 },
{ "chan",-19725 },
{ "chang",-19715 },
{ "chao",-19540 },
{ "che",-19531 },
{ "chen",-19525 },
{ "cheng",-19515 },
{ "chi",-19500 },
{ "chong",-19484 },
{ "chou",-19479 },
{ "chu",-19467 },
{ "chuai",-19289 },
{ "chuan",-19288 },
{ "chuang",-19281 },
{ "chui",-19275 },
{ "chun",-19270 },
{ "chuo",-19263 },
{ "ci",-19261 },
{ "cong",-19249 },
{ "cou",-19243 },
{ "cu",-19242 },
{ "cuan",-19238 },
{ "cui",-19235 },
{ "cun",-19227 },
{ "cuo",-19224 },
{ "da",-19218 },
{ "dai",-19212 },
{ "dan",-19038 },
{ "dang",-19023 },
{ "dao",-19018 },
{ "de",-19006 },
{ "deng",-19003 },
{ "di",-18996 },
{ "dian",-18977 },
{ "diao",-18961 },
{ "die",-18952 },
{ "ding",-18783 },
{ "diu",-18774 },
{ "dong",-18773 },
{ "dou",-18763 },
{ "du",-18756 },
{ "duan",-18741 },
{ "dui",-18735 },
{ "dun",-18731 },
{ "duo",-18722 },
{ "e",-18710 },
{ "en",-18697 },
{ "er",-18696 },
{ "fa",-18526 },
{ "fan",-18518 },
{ "fang",-18501 },
{ "fei",-18490 },
{ "fen",-18478 },
{ "feng",-18463 },
{ "fo",-18448 },
{ "fou",-18447 },
{ "fu",-18446 },
{ "ga",-18239 },
{ "gai",-18237 },
{ "gan",-18231 },
{ "gang",-18220 },
{ "gao",-18211 },
{ "ge",-18201 },
{ "gei",-18184 },
{ "gen",-18183 },
{ "geng",-18181 },
{ "gong",-18012 },
{ "gou",-17997 },
{ "gu",-17988 },
{ "gua",-17970 },
{ "guai",-17964 },
{ "guan",-17961 },
{ "guang",-17950 },
{ "gui",-17947 },
{ "gun",-17931 },
{ "guo",-17928 },
{ "ha",-17922 },
{ "hai",-17759 },
{ "han",-17752 },
{ "hang",-17733 },
{ "hao",-17730 },
{ "he",-17721 },
{ "hei",-17703 },
{ "hen",-17701 },
{ "heng",-17697 },
{ "hong",-17692 },
{ "hou",-17683 },
{ "hu",-17676 },
{ "hua",-17496 },
{ "huai",-17487 },
{ "huan",-17482 },
{ "huang",-17468 },
{ "hui",-17454 },
{ "hun",-17433 },
{ "huo",-17427 },
{ "ji",-17417 },
{ "jia",-17202 },
{ "jian",-17185 },
{ "jiang",-16983 },
{ "jiao",-16970 },
{ "jie",-16942 },
{ "jin",-16915 },
{ "jing",-16733 },
{ "jiong",-16708 },
{ "jiu",-16706 },
{ "ju",-16689 },
{ "juan",-16664 },
{ "jue",-16657 },
{ "jun",-16647 },
{ "ka",-16474 },
{ "kai",-16470 },
{ "kan",-16465 },
{ "kang",-16459 },
{ "kao",-16452 },
{ "ke",-16448 },
{ "ken",-16433 },
{ "keng",-16429 },
{ "kong",-16427 },
{ "kou",-16423 },
{ "ku",-16419 },
{ "kua",-16412 },
{ "kuai",-16407 },
{ "kuan",-16403 },
{ "kuang",-16401 },
{ "kui",-16393 },
{ "kun",-16220 },
{ "kuo",-16216 },
{ "la",-16212 },
{ "lai",-16205 },
{ "lan",-16202 },
{ "lang",-16187 },
{ "lao",-16180 },
{ "le",-16171 },
{ "lei",-16169 },
{ "leng",-16158 },
{ "li",-16155 },
{ "lia",-15959 },
{ "lian",-15958 },
{ "liang",-15944 },
{ "liao",-15933 },
{ "lie",-15920 },
{ "lin",-15915 },
{ "ling",-15903 },
{ "liu",-15889 },
{ "long",-15878 },
{ "lou",-15707 },
{ "lu",-15701 },
{ "lv",-15681 },
{ "luan",-15667 },
{ "lue",-15661 },
{ "lun",-15659 },
{ "luo",-15652 },
{ "ma",-15640 },
{ "mai",-15631 },
{ "man",-15625 },
{ "mang",-15454 },
{ "mao",-15448 },
{ "me",-15436 },
{ "mei",-15435 },
{ "men",-15419 },
{ "meng",-15416 },
{ "mi",-15408 },
{ "mian",-15394 },

{ "miao",-15385 },
{ "mie",-15377 },
{ "min",-15375 },
{ "ming",-15369 },
{ "miu",-15363 },
{ "mo",-15362 },
{ "mou",-15183 },
{ "mu",-15180 },
{ "na",-15165 },
{ "nai",-15158 },
{ "nan",-15153 },
{ "nang",-15150 },
{ "nao",-15149 },
{ "ne",-15144 },
{ "nei",-15143 },
{ "nen",-15141 },
{ "neng",-15140 },
{ "ni",-15139 },
{ "nian",-15128 },
{ "niang",-15121 },
{ "niao",-15119 },
{ "nie",-15117 },
{ "nin",-15110 },
{ "ning",-15109 },
{ "niu",-14941 },
{ "nong",-14937 },
{ "nu",-14933 },
{ "nv",-14930 },
{ "nuan",-14929 },
{ "nue",-14928 },
{ "nuo",-14926 },
{ "o",-14922 },
{ "ou",-14921 },
{ "pa",-14914 },
{ "pai",-14908 },
{ "pan",-14902 },
{ "pang",-14894 },
{ "pao",-14889 },
{ "pei",-14882 },
{ "pen",-14873 },
{ "peng",-14871 },
{ "pi",-14857 },
{ "pian",-14678 },
{ "piao",-14674 },
{ "pie",-14670 },
{ "pin",-14668 },
{ "ping",-14663 },
{ "po",-14654 },
{ "pu",-14645 },
{ "qi",-14630 },
{ "qia",-14594 },
{ "qian",-14429 },
{ "qiang",-14407 },
{ "qiao",-14399 },
{ "qie",-14384 },
{ "qin",-14379 },
{ "qing",-14368 },
{ "qiong",-14355 },
{ "qiu",-14353 },
{ "qu",-14345 },
{ "quan",-14170 },
{ "que",-14159 },
{ "qun",-14151 },
{ "ran",-14149 },
{ "rang",-14145 },
{ "rao",-14140 },
{ "re",-14137 },
{ "ren",-14135 },
{ "reng",-14125 },
{ "ri",-14123 },
{ "rong",-14122 },
{ "rou",-14112 },
{ "ru",-14109 },
{ "ruan",-14099 },
{ "rui",-14097 },
{ "run",-14094 },
{ "ruo",-14092 },
{ "sa",-14090 },
{ "sai",-14087 },
{ "san",-14083 },
{ "sang",-13917 },
{ "sao",-13914 },
{ "se",-13910 },
{ "sen",-13907 },
{ "seng",-13906 },
{ "sha",-13905 },
{ "shai",-13896 },
{ "shan",-13894 },
{ "shang",-13878 },
{ "shao",-13870 },
{ "she",-13859 },
{ "shen",-13847 },
{ "sheng",-13831 },
{ "shi",-13658 },
{ "shou",-13611 },
{ "shu",-13601 },
{ "shua",-13406 },
{ "shuai",-13404 },
{ "shuan",-13400 },
{ "shuang",-13398 },
{ "shui",-13395 },
{ "shun",-13391 },
{ "shuo",-13387 },
{ "si",-13383 },
{ "song",-13367 },
{ "sou",-13359 },
{ "su",-13356 },
{ "suan",-13343 },
{ "sui",-13340 },
{ "sun",-13329 },
{ "suo",-13326 },
{ "ta",-13318 },
{ "tai",-13147 },
{ "tan",-13138 },
{ "tang",-13120 },
{ "tao",-13107 },
{ "te",-13096 },
{ "teng",-13095 },
{ "ti",-13091 },
{ "tian",-13076 },
{ "tiao",-13068 },
{ "tie",-13063 },
{ "ting",-13060 },
{ "tong",-12888 },
{ "tou",-12875 },
{ "tu",-12871 },
{ "tuan",-12860 },
{ "tui",-12858 },
{ "tun",-12852 },
{ "tuo",-12849 },
{ "wa",-12838 },
{ "wai",-12831 },
{ "wan",-12829 },
{ "wang",-12812 },
{ "wei",-12802 },
{ "wen",-12607 },
{ "weng",-12597 },
{ "wo",-12594 },
{ "wu",-12585 },
{ "xi",-12556 },
{ "xia",-12359 },
{ "xian",-12346 },
{ "xiang",-12320 },
{ "xiao",-12300 },
{ "xie",-12120 },
{ "xin",-12099 },
{ "xing",-12089 },
{ "xiong",-12074 },
{ "xiu",-12067 },
{ "xu",-12058 },
{ "xuan",-12039 },
{ "xue",-11867 },
{ "xun",-11861 },
{ "ya",-11847 },
{ "yan",-11831 },
{ "yang",-11798 },
{ "yao",-11781 },
{ "ye",-11604 },
{ "yi",-11589 },
{ "yin",-11536 },
{ "ying",-11358 },
{ "yo",-11340 },
{ "yong",-11339 },
{ "you",-11324 },
{ "yu",-11303 },
{ "yuan",-11097 },
{ "yue",-11077 },
{ "yun",-11067 },
{ "za",-11055 },
{ "zai",-11052 },
{ "zan",-11045 },
{ "zang",-11041 },
{ "zao",-11038 },
{ "ze",-11024 },
{ "zei",-11020 },
{ "zen",-11019 },
{ "zeng",-11018 },
{ "zha",-11014 },
{ "zhai",-10838 },
{ "zhan",-10832 },
{ "zhang",-10815 },
{ "zhao",-10800 },
{ "zhe",-10790 },
{ "zhen",-10780 },
{ "zheng",-10764 },
{ "zhi",-10587 },
{ "zhong",-10544 },
{ "zhou",-10533 },
{ "zhu",-10519 },
{ "zhua",-10331 },
{ "zhuai",-10329 },
{ "zhuan",-10328 },
{ "zhuang",-10322 },
{ "zhui",-10315 },
{ "zhun",-10309 },
{ "zhuo",-10307 },
{ "zi",-10296 },
{ "zong",-10281 },
{ "zou",-10274 },
{ "zu",-10270 },
{ "zuan",-10262 },
{ "zui",-10260 },
{ "zun",-10256 },
{ "zuo",-10254 }
//max = -10247
};

9楼
水手 发表于:2007-4-19 12:42:04

3

Option Explicit
Private Const IME_ESC_MAX_KEY = &H1005
Private Const IME_ESC_IME_NAME = &H1006
Private Const GCL_REVERSECONVERSION = &H2
Private Declare Function GetKeyboardLayoutList Lib "user32" (ByVal nBuff As Long, lpList As Long) As Long
Private Declare Function ImmEscape Lib "imm32.dll" Alias "ImmEscapeA" (ByVal hkl As Long, ByVal himc As Long, ByVal un As Long, lpv As Any) As Long
Private Declare Function ImmGetConversionList Lib "imm32.dll" Alias "ImmGetConversionListA" (ByVal hkl As Long, ByVal himc As Long, ByVal lpsz As String, lpCandidateList As Any, ByVal dwBufLen As Long, ByVal uFlag As Long) As Long
Private Declare Function IsDBCSLeadByte Lib "kernel32" (ByVal bTestChar As Byte) As Long
Public Function GetChineseSpell(Chinese As String, Optional Delimiter As String = " ", Optional IMEName As String = "微软拼音输入法", Optional BufferSize As Long = 255) As String
If Len(Trim(Chinese)) > 0 Then
Dim i As Long
Dim s As String
s = Space(BufferSize)
Dim IMEInstalled As Boolean
Dim j As Long
Dim a() As Long
ReDim a(BufferSize) As Long
j = GetKeyboardLayoutList(BufferSize, a(LBound(a)))


For i = LBound(a) To LBound(a) + j - 1
If ImmEscape(a(i), 0, IME_ESC_IME_NAME, ByVal s) Then
If Trim(IMEName) = Replace(Trim(s), Chr(0), "") Then
IMEInstalled = True
Exit For
End If
End If
Next i
If IMEInstalled Then
'Stop
Chinese = Trim(Chinese)
Dim sChar As String
Dim Buffer0() As Byte
'Dim Buffer() As Byte
Dim bBuffer0() As Byte
Dim bBuffer() As Byte
Dim k As Long
Dim l As Long
Dim m As Long
For j = 0 To Len(Chinese) - 1
sChar = Mid(Chinese, j + 1, 1)
Buffer0 = StrConv(sChar, vbFromUnicode)
If IsDBCSLeadByte(Buffer0(0)) Then
k = ImmEscape(a(i), 0, IME_ESC_MAX_KEY, Null)
If k Then
l = ImmGetConversionList(a(i), 0, sChar, 0, 0, GCL_REVERSECONVERSION)
If l Then
s = Space(BufferSize)
If ImmGetConversionList(a(i), 0, sChar, ByVal s, l, GCL_REVERSECONVERSION) Then

bBuffer0 = StrConv(s, vbFromUnicode)
ReDim bBuffer(k * 2 - 1)
For m = bBuffer0(24) To bBuffer0(24) + k * 2 - 1
bBuffer(m - bBuffer0(24)) = bBuffer0(m)
Next m
sChar = Trim(StrConv(bBuffer, vbUnicode))
If InStr(sChar, vbNullChar) Then
sChar = Trim(Left(sChar, InStr(sChar, vbNullChar) - 1))
End If
'sChar = Left(sChar, Len(sChar) - 1) & IIf(j < Len(Chinese) - 1, Delimiter, "")
sChar = UCase(Left(sChar, 1))
End If

End If
End If
End If
GetChineseSpell = GetChineseSpell & sChar
Next j
Else


End If

End If
End Function

Private Sub Command1_Click()
MsgBox GetChineseSpell("你是谁")
End Sub

10楼
水手 发表于:2007-4-19 12:42:41

4、判断拼音首个字母的代码我有,是利用ASCII码判断的,原理很简单,很容易看懂:)


//定义首字拼音过程

Public Function py(mystr As String) As String
If Asc(mystr) < 0 Then
If Asc(Left(mystr, 1)) < Asc("啊") Then
py = "0"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("啊") And Asc(Left(mystr, 1)) < Asc("芭") Then
py = "A"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("芭") And Asc(Left(mystr, 1)) < Asc("擦") Then
py = "B"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("擦") And Asc(Left(mystr, 1)) < Asc("搭") Then
py = "C"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("搭") And Asc(Left(mystr, 1)) < Asc("蛾") Then
py = "D"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("蛾") And Asc(Left(mystr, 1)) < Asc("发") Then
py = "E"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("发") And Asc(Left(mystr, 1)) < Asc("噶") Then
py = "F"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("噶") And Asc(Left(mystr, 1)) < Asc("哈") Then
py = "G"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("哈") And Asc(Left(mystr, 1)) < Asc("击") Then
py = "H"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("击") And Asc(Left(mystr, 1)) < Asc("喀") Then
py = "J"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("喀") And Asc(Left(mystr, 1)) < Asc("垃") Then
py = "K"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("垃") And Asc(Left(mystr, 1)) < Asc("妈") Then
py = "L"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("妈") And Asc(Left(mystr, 1)) < Asc("拿") Then
py = "M"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("拿") And Asc(Left(mystr, 1)) < Asc("哦") Then
py = "N"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("哦") And Asc(Left(mystr, 1)) < Asc("啪") Then
py = "O"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("啪") And Asc(Left(mystr, 1)) < Asc("期") Then
py = "P"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("期") And Asc(Left(mystr, 1)) < Asc("然") Then
py = "Q"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("然") And Asc(Left(mystr, 1)) < Asc("撒") Then
py = "R"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("撒") And Asc(Left(mystr, 1)) < Asc("塌") Then
py = "S"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("塌") And Asc(Left(mystr, 1)) < Asc("挖") Then
py = "T"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("挖") And Asc(Left(mystr, 1)) < Asc("昔") Then
py = "W"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("昔") And Asc(Left(mystr, 1)) < Asc("压") Then
py = "X"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("压") And Asc(Left(mystr, 1)) < Asc("匝") Then
py = "Y"
Exit Function
End If
If Asc(Left(mystr, 1)) >= Asc("匝") Then
py = "Z"
Exit Function
End If
Else
If UCase(mystr) <= "Z" And UCase(mystr) >= "A" Then
py = UCase(Left(mystr, 1))
Else
py = mystr
End If
End If
End Function



//调用过程.TEXT1输入,LABEL1显示

Private Sub command1_click()
Dim a As Integer
Label1.Caption = ""
a = Len(Text1.Text)
For i = 1 To a
Label1.Caption = Label1.Caption & py(Mid(Text1.Text, i, 1))
Next i
End Sub

共17 条记录, 每页显示 10 条, 页签: [1] [2]

搭建之星 网站·搭建者 Copyright © 2000 - 2011
Powered By Dvbbs Version 8.2.0
Processed in 0.09375 s, 3 queries.