单词单复数转换函数

///   <summary>
        
///  单词单复数转换函数,本函数对2个或2个字母以上单词有效
        
///   </summary>
        
///   <param name="world"> 待转换的单词 </param>
        
///   <returns> 返回一个长度为2的字符串数组,第一个值为单数单词,第二个为复数单词 </returns>
         public   static   string [] worldTransform( string  world)
        {
            world 
=  world.ToLower(); // 将单词转成小写形式
             string  vowel  =   " aoeiu " ; // 声明元音字符串
             int  length  =  world.Length; // 获取单词字符长度待用
             string [] worlds  =   new   string [ 2 ]; // 声明一个二维字符串数组
             if  (length  ==   1 )
            {
                worlds[
0 =  world; // 存储单词单数形式
                worlds[ 1 =  world; // 存储单词复数形式
                 return  worlds;
            }
            
else
            {
                
char  last  =  world[length  -   1 ]; // 取出单词最后一个字符待用
                 char  last2  =  world[length  -   2 ]; // 取出单词倒数第二个字符待用
                 char  last3  =   '   ' ;
                
if  (length  >=   3 )
                    last3 
=  world[length  -   3 ]; // 取出单词倒数第三个字符待用
                 char  last4  =   '   ' ;
                
if  (length  >=   4 )
                    last4 
=  world[length  -   4 ]; // 取出单词倒数第四个字符待用
                worlds[ 0 =  world; // 存储单词单数形式
                worlds[ 1 =  world; // 存储单词复数形式


                
if  (length  ==   1 )
                {
                    
return  worlds;
                }
                
if  (last  !=   ' s '   ||  length  <=   2 )
                {
                    
// 单词最后一个字母不为"s",则可判断为单数形式
                     switch  (last)
                    {
                        
case   ' y ' :
                            
if  (vowel.IndexOf(last2)  <   0 )
                            {
                                worlds[
1 =  worlds[ 1 ].Substring( 0 , length  -   1 +   " i " ;
                                worlds[
1 +=   " es " ;
                            }
                            
else
                                worlds[
1 +=   " s " ;
                            
break ;
                        
case   ' f ' :
                            worlds[
1 =  worlds[ 1 ].Substring( 0 , length  -   1 +   " v " ;
                            worlds[
1 +=   " es " ;
                            
break ;
                        
case   ' e ' :
                            
if  (last2  ==   ' f ' )
                            {
                                worlds[
1 =  worlds[ 1 ].Substring( 0 , length  -   2 +   " ves " ;
                            }
                            
else
                                worlds[
1 +=   " s " ;
                            
break ;
                        
case   ' o ' :
                            worlds[
1 +=   " es " ;
                            
break ;
                        
case   ' z ' :
                            worlds[
1 +=   " es " ;
                            
break ;
                        
case   ' s ' :
                            worlds[
1 +=   " es " ;
                            
break ;
                        
case   ' x ' :
                            worlds[
1 +=   " es " ;
                            
break ;
                        
case   ' h ' :
                            
if  (last2  ==   ' c '   ||  last2  ==   ' s ' )
                                worlds[
1 +=   " es " ;
                            
else
                                worlds[
1 +=   " s " ;
                            
break ;
                        
default :
                            worlds[
1 +=   " s " ;
                            
break ;
                    }
                    
return  worlds;
                }
                
else
                {
                    
if  (last2  ==   ' e ' )
                    {
                        
// 单词最后两个字母为“es”,则可判断其为复数形式
                         if  (last3  ==   ' z '   ||  last3  ==   ' x '   ||  last3  ==   ' s '   ||  last3  ==   ' h '   ||  last3  ==   ' o ' )
                            worlds[
0 =  worlds[ 0 ].Remove(length  -   2 );
                        
else   if  (last3  ==   ' i ' )
                        {
                            
if  (length  >=   4 )
                            {
                                
if  (vowel.IndexOf(last4)  <   0 )
                                {
                                    worlds[
0 =  worlds[ 0 ].Remove(length  -   2 );
                                    worlds[
0 =  worlds[ 0 ].Substring( 0 , length  -   3 +   " y " ;
                                }
                                
else
                                    worlds[
0 =  worlds[ 0 ].Remove(length  -   2 );
                            }
                        }
                        
else   if  (last3  ==   ' v ' )
                        {
                            worlds[
0 =  worlds[ 0 ].Remove(length  -   3 );
                            worlds[
0 +=   " f " ; // 此步骤会产生误差。因为大多数的“f”、“fe”结尾单词中多以“f”结尾(还没有调查过),顾忽略“fe”。要避免误差只能用词库了。
                        }
                        
else
                        {
                            worlds[
0 =  worlds[ 0 ].Remove(length  -   1 );
                        }
                    }
                    
else
                    {
                        worlds[
0 =  worlds[ 0 ].Remove(length  -   1 ); // 此步骤误差最大,当单词最后一个字母为s时,很难判断它是复数还是单数,目前还没有找到判断的规律,估计要用到词库此才行。
                    }
                    
return  worlds;
                }
            }
        }
http://www.cnblogs.com/smalltree/archive/2009/02/14/1390631.html

转载于:https://www.cnblogs.com/tonybinlj/archive/2009/02/15/1391160.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值