30 April 2015

packages

  1. cjklib

  2. pinyin

  3. hanzi2pinyin

  4. Unidecode

package cjklib

  1. check my post anaconda on mac

  2. we can not use cjklib on osx-64 now

    • No packages found in current osx-64 channels matching: cjklib
  3. code snippet from www.codeitive.com

         from cjklib.characterlookup import CharacterLookup
    
         source_file = 'input.txt'
         dest_file = 'output.txt'
    
         s = open(source_file, 'r')
         d = open(dest_file, 'w')
    
         cjk = CharacterLookup('T')
    
         for line in s:
             p = line.split('\t')
             for p_shard in p:
                 for c in p_shard:
                     readings = cjk.getReadingForCharacter(c.encode('utf-8'), 'Pinyin')
                     d.write(readings[0].encode('utf-8'))
                 d.write('\t')
             d.write('\n')
    
         s.close()
         d.close()
    

package pinyin

  1. install form pypi source

         $ cd pinyin-0.1.2
         $ python setup.py install
    
  2. code snippet

         >>> import pinyin
         >>> pinyin.get_pinyin(u'你好')
         'nihao'
         >>> pinyin.get_initial(u'你好')
         'n h'
    

package hanzi2pinyin

  1. we can not use cjklib on osx-64 now

    • No packages found in current osx-64 channels matching: cjklib
  2. install form pypi source

  3. code snippet

         >>> from hanzi2pinyin import hanzi2pinyin
         >>> hanzi2pinyin(u"你好")
         ... nihao
    

package Unidecode

  1. install from pypi source

  2. code snippet

         from unidecode import unidecode
         print unidecode(u"\u5317\u4EB0")
    
         # That prints: Bei Jing
    


blog comments powered by Disqus