Commits

wooparadog  committed 39dc5c9

f

  • Participants
  • Parent commits a63eb29

Comments (0)

Files changed (2)

File pinyin/main.py

 Created on
 2012-04-24
 '''
-from pinyin import pinyin_list_by_str
+from pinyin2 import Pinyin
 import doctest
 
+parser = Pinyin()
+pinyin_list_by_str = parser.get_pinyin
+
 def pinyin_parser_length_2(name):
-    '''
-    >>> pinyin_parser_length_2("王慧")
-    'wahu'
-    '''
     pinyin_list = pinyin_list_by_str(name)
     return ''.join([i[:2] for i in pinyin_list])
 
 def pinyin_parser_length_3(name):
-    '''
-    >>> pinyin_parser_length_3("郭浩川")
-    'ghch'
-    '''
     pinyin_list = pinyin_list_by_str(name)
     return ''.join([i[0] for i in pinyin_list[:2]]+[pinyin_list[-1][:2]])
 
 def pinyin_parser_length_4(name):
-    '''
-    >>> pinyin_parser_length_4("郭浩慧川")
-    'ghhc'
-    '''
     pinyin_list = pinyin_list_by_str(name)
     return ''.join([i[0] for i in pinyin_list])
 
 def pinyin_parser_length_x(name):
-    '''
-    >>> pinyin_parser_length_x("王浩郭慧川")
-    'whgh'
-    '''
     pinyin_list = pinyin_list_by_str(name)
     return ''.join([i[0] for i in pinyin_list[:4]])
 
 def pinyin_parser(name):
     '''
-    >>> pinyin_parser("王慧")
-    'wahu'
+    >>> pinyin_parser("郇豪")
+    'xuha'
     >>> pinyin_parser("郭浩川")
     'ghch'
     >>> pinyin_parser("郭浩慧川")
     >>> pinyin_parser("王浩郭慧川")
     'whgh'
     '''
-    if not isinstance(name, unicode):
-        name = name.decode("utf8")
+    name = name.decode('utf8')
 
     if len(name) == 2:
         result = pinyin_parser_length_2(name)

File pinyin/pinyin.py

     return ''.join(pinyin_list_by_str(text))
 
 if __name__ == '__main__':
-    print pinyin_list_by_str("郭浩川")
+    print pinyin_list_by_str(u"郇")