def test(): for testn in sorted(listdir('cases')): if not exists(join('cases', testn, 'input')): continue print print '-' * 40 print print 'Running test', testn, '...' with codecs.open(join('cases', testn, 'input'), 'r', 'utf-8') as f: inp = f.read() print 'input size:', len(inp) parserules = True for var in VALIDVARIANTS: print print 'testing', var, '...', start = time() try: convhandler = ConverterHandler(var) outp = convhandler.convert(inp, parserules) except Exception: print 'error occurred.' print_exc() else: print '%.3f sec.' % (time() - start) if exists(join('cases', testn, 'output.' + var)): print 'comparing converter\'s output with expected output ...' with codecs.open(join('cases', testn, 'output.' + var), 'r', 'utf-8') as f: cp = f.read() if cp == outp: print 'OK' else: print 'FAILED'
def genLoc(filePath): c = open(filePath) conv = ConverterHandler('zh-hant') word = u'女装连衣裙' for x in xrange(100000): line = word if len(line): keyword = '' keyword = urllib.quote(conv.convert(line.strip()).encode('utf-8')) if not len(keyword): continue url = 'http://example.com/?q=%s' % keyword yield url
def convert_name(word): name = ConverterHandler('zh-hans').convert(convert(word)) return name