CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
【经验总结】不能实施并行处理的情况 浅谈并行编程中的任务分解模式
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Java >  Web 开发

用户的特殊要求,100求解 着急!

楼主fzdcn(混沌)2005-08-27 14:54:20 在 Java / Web 开发 提问

用户希望输入数据库的姓名都是汉字,然后查找时通过拼音字母查找。  
   
  比如:数据库中是江海涛     希望搜索时输入jht   就能查找到  
  且数据入库时,不输jht  
   
   
  如何实现,请高手指教,分数不够,可以再加 问题点数:100、回复次数:17Top

1 楼blackdreamzg(基本靠手)回复于 2005-08-27 15:05:29 得分 5

构建一个拼音字典(上网搜搜,应该有现成的)。  
  录入中文的时候,从字典做检索。在数据库里建立一个相应的拼音字段。Top

2 楼wanchao2001(如果可以重来,我还是选择程序员)回复于 2005-08-27 17:41:11 得分 5

对增加一个字段比如字段姓名         拼音字段  
                                      江海涛               jhtTop

3 楼luoxueyong(琪咪漫珥)回复于 2005-08-27 18:13:45 得分 5

做一个键盘事件........在用户输入名字的时候,,,,,,,,,,然后分段得到用户输入的拼音!......再内部设计取得拼音第一字母.......与汉字对应保存.......以后就行了Top

4 楼ming500(ming500)回复于 2005-08-27 18:50:54 得分 0

前面的方法都不错的Top

5 楼famousboy(famousboy)回复于 2005-08-27 20:16:21 得分 5

名字的每个字放一个字段。  
  把数据库的中文排序排序方式设为按拼音排序。(SQL   Server,DB2   ,Oracle好像默认是,其他的不知道)  
  然后再建一张映射表:(link)  
  -----------------------  
  字母     该字母对用的字  
  letter   charactor  
  a               啊  
  b               吧  
  c               擦  
  ...           ...  
  z               咋  
  -----------------------  
  就是用26个字母和以这26字母加韵母a等到的汉字作个对用关系。(u,v   都对应   哇)  
   
  检索   江海涛(jht)   时   可用  
  select   charactor   from   link   where   letter   in   ('j','k')  
  select   charactor   from   link   where   letter   in   ('h','i')  
  select   charactor   from   link   where   letter   in   ('t','u')  
  搜索出条件中每个字母和这个字母前一个字母对应的汉字放在数组m1[],m2[],m3[]中  
  select    
        c1+c2+c3   as   name    
  from    
        user  
  where    
        (user.c1>=m1[0]   and   user.c1<m1[1])   AND  
        (user.c2>=m2[0]   and   user.c1<m2[1])   AND  
        (user.c3>=m3[0]   and   user.c1<m3[1])   AND  
   
  条件有a和z时,检索条件只取一边。  
  SQL语句应该还可以优化。  
   
   
  Top

6 楼qiyadeng(。。。。。)回复于 2005-08-27 20:19:59 得分 5

famousboy(famousboy)   说的很有道理,这样做的效果是最好的,不用构建什么词典!Top

7 楼famousboy(famousboy)回复于 2005-08-27 20:38:56 得分 5

找字母对应的第一个汉字比较麻烦。  
  可以肯定的是,先按拼音的字母顺序,再按声调顺去,一声最小,轻声最大。  
  如果读音完全相同,好像是看笔画的,第一画是的横比第一画是点的小(没有验证过)。  
   
  有哪位大哥知道汉字按拼音排序的规则请赐教。  
   
  但是可以把常用的a韵母的一声的常用汉字存到一列里,然后用order   by   拍一下序。生僻字暂时就不考虑了。Top

8 楼simon0512(虫虫)回复于 2005-08-27 22:39:25 得分 0

学习Top

9 楼99131103(点滴)回复于 2005-08-28 00:20:18 得分 5

名字与拼音首字母建立关系表。Top

10 楼ccm1980(海浪)回复于 2005-08-28 09:49:28 得分 5

字母汉字比较,数据库多存个字段Top

11 楼fzdcn(混沌)回复于 2005-08-28 17:20:30 得分 0

jsp   中   有没有象   asp   中的Asc   函数  
   
  Asc   函数   返回字符串首字母的   ANSI   字符代码Top

12 楼jyy7751(wish i could fly)回复于 2005-08-28 17:27:42 得分 5

增加一个拼音字段,再写一个把汉字名称转换成拼音首字母的方法,输入汉字时,调用方法,不需再输入拼音首字母。Top

13 楼fzdcn(混沌)回复于 2005-08-29 09:59:53 得分 0

想用asc   类似的方法实现字名称转换成拼音首字母  
  jsp   中类似的函数是什么?  
  Top

14 楼jyy7751(wish i could fly)回复于 2005-08-29 10:21:05 得分 50

没有这样的方法,自已写一个  
  public   class   GetCh2Spell   {  
          public   static   int   compare(String   str1,   String   str2)  
            {  
                    int   result   =   0;  
                    String   m_s1   =   null;  
                    String   m_s2   =   null;  
                    try  
                    {  
                            m_s1   =   new   String(str1.getBytes(_FromEncode_),   _ToEncode_);  
                            m_s2   =   new   String(str2.getBytes(_FromEncode_),   _ToEncode_);  
                    }  
                    catch(Exception   e)  
                    {  
                            return   str1.compareTo(str2);  
                    }  
                    result   =   chineseCompareTo(m_s1,   m_s2);  
                    return   result;  
            }  
   
            public   static   int   getCharCode(String   s)  
            {  
                    if(s   ==   null   &&   s.equals(""))  
                            return   -1;  
                    byte   b[]   =   s.getBytes();  
                    int   value   =   0;  
                    for(int   i   =   0;   i   <   b.length   &&   i   <=   2;   i++)  
                            value   =   value   *   100   +   b[i];  
   
                    return   value;  
            }  
   
            public   static   int   chineseCompareTo(String   s1,   String   s2)  
            {  
                    int   len1   =   s1.length();  
                    int   len2   =   s2.length();  
                    int   n   =   Math.min(len1,   len2);  
                    for(int   i   =   0;   i   <   n;   i++)  
                    {  
                            int   s1_code   =   getCharCode(s1.charAt(i)   +   "");  
                            int   s2_code   =   getCharCode(s2.charAt(i)   +   "");  
                            if(s1_code   *   s2_code   <   0)  
                                    return   Math.min(s1_code,   s2_code);  
                            if(s1_code   !=   s2_code)  
                                    return   s1_code   -   s2_code;  
                    }  
   
                    return   len1   -   len2;  
            }  
   
            public   static   String   getBeginCharacter(String   res)  
            {  
                    String   a   =   res;  
                    String   result   =   "";  
                    for(int   i   =   0;   i   <   a.length();   i++)  
                    {  
                            String   current   =   a.substring(i,   i   +   1);  
                            if(compare(current,   "\u554A")   <   0)  
                                    result   =   result   +   current;  
                            else  
                            if(compare(current,   "\u554A")   >=   0   &&   compare(current,   "\u5EA7")   <=   0)  
                                    if(compare(current,   "\u531D")   >=   0)  
                                            result   =   result   +   "z";  
                                    else  
                                    if(compare(current,   "\u538B")   >=   0)  
                                            result   =   result   +   "y";  
                                    else  
                                    if(compare(current,   "\u6614")   >=   0)  
                                            result   =   result   +   "x";  
                                    else  
                                    if(compare(current,   "\u6316")   >=   0)  
                                            result   =   result   +   "w";  
                                    else  
                                    if(compare(current,   "\u584C")   >=   0)  
                                            result   =   result   +   "t";  
                                    else  
                                    if(compare(current,   "\u6492")   >=   0)  
                                            result   =   result   +   "s";  
                                    else  
                                    if(compare(current,   "\u7136")   >=   0)  
                                            result   =   result   +   "r";  
                                    else  
                                    if(compare(current,   "\u671F")   >=   0)  
                                            result   =   result   +   "q";  
                                    else  
                                    if(compare(current,   "\u556A")   >=   0)  
                                            result   =   result   +   "p";  
                                    else  
                                    if(compare(current,   "\u54E6")   >=   0)  
                                            result   =   result   +   "o";  
                                    else  
                                    if(compare(current,   "\u62FF")   >=   0)  
                                            result   =   result   +   "n";  
                                    else  
                                    if(compare(current,   "\u5988")   >=   0)  
                                            result   =   result   +   "m";  
                                    else  
                                    if(compare(current,   "\u5783")   >=   0)  
                                            result   =   result   +   "l";  
                                    else  
                                    if(compare(current,   "\u5580")   >=   0)  
                                            result   =   result   +   "k";  
                                    else  
                                    if(compare(current,   "\u51FB")   >   0)  
                                            result   =   result   +   "j";  
                                    else  
                                    if(compare(current,   "\u54C8")   >=   0)  
                                            result   =   result   +   "h";  
                                    else  
                                    if(compare(current,   "\u5676")   >=   0)  
                                            result   =   result   +   "g";  
                                    else  
                                    if(compare(current,   "\u53D1")   >=   0)  
                                            result   =   result   +   "f";  
                                    else  
                                    if(compare(current,   "\u86FE")   >=   0)  
                                            result   =   result   +   "e";  
                                    else  
                                    if(compare(current,   "\u642D")   >=   0)  
                                            result   =   result   +   "d";  
                                    else  
                                    if(compare(current,   "\u64E6")   >=   0)  
                                            result   =   result   +   "c";  
                                    else  
                                    if(compare(current,   "\u82AD")   >=   0)  
                                            result   =   result   +   "b";  
                                    else  
                                    if(compare(current,   "\u554A")   >=   0)  
                                            result   =   result   +   "a";  
                    }  
   
                    return   result;  
            }  
   
            public   static   String   getFirstStr(String   str)  
            {  
                    char   a   =   str.charAt(0);  
                    char   aa[]   =   {  
                            a  
                    };  
                    String   sss   =   new   String(aa);  
                    if(Character.isDigit(aa[0]))  
                            sss   =   "data";  
                    else  
                    if(a   >=   'a'   &&   a   <=   'z'   ||   a   >=   'A'   &&   a   <=   'Z')  
                            sss   =   "character";  
                    else  
                            sss   =   getBeginCharacter(sss);  
                    return   sss;  
            }  
   
            private   static   String   _FromEncode_   =   "GBK";  
            private   static   String   _ToEncode_   =   "GBK";  
   
  }Top

15 楼classjava(原始野人)回复于 2005-08-29 10:26:43 得分 3

建立一个表,用来存放拼音符号的  
  然后在用户中加入一个属性叫简码就ok   了Top

16 楼flyoversky(碧海)回复于 2005-08-29 10:45:23 得分 0

UPTop

17 楼java_student()回复于 2005-08-29 11:39:12 得分 2

其实数据输入才是这个问题的症结  
  1.难道客户数据输入的时候还是输入汉字头字母吗(而且汉字有多种读法)   那也太土了  
  2.加个汉字对照表吗   工程太大  
   
  所以   建议可以和客户谈判说这个功能不是当初设计时谈好的   要加钱   客户1慌就不要求这个功能了Top

相关问题

  • ※ 着急求解决方法!!!
  • 着急,100分求解链接问题!
  • 着急,100分求解链接问题!
  • 求解_两个特殊数据窗口
  • 着急求解全文目录的问题
  • 着急,100分高分求解编译错误!
  • 高分求解,如何强制刷新页面? 比较着急谢谢
  • 着急万分,倾家荡产求解决一个javascrip小问题!在线等!!
  • 谁能给个求解pi 3.1515926.....要求精确到任意位.
  • 急要求解搬运工问题的算法。

关键词

  • 字母
  • 字段
  • 排序
  • 数据库
  • 用户
  • compare
  • 拼音
  • jht
  • current
  • result

得分解答快速导航

  • 帖主:fzdcn
  • blackdreamzg
  • wanchao2001
  • luoxueyong
  • famousboy
  • qiyadeng
  • famousboy
  • 99131103
  • ccm1980
  • jyy7751
  • jyy7751
  • classjava
  • java_student

相关链接

  • CSDN Java频道
  • Java类图书
  • Java类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
惹火投票。。火热进行中...
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
CSDN网站24小时值班电话:13552009689
Copyright © 2000-2009, CSDN.NET, All Rights Reserved
GongshangLogo