def pass1(): global output outfile = '__h1output.txt' with open(outfile, 'w') as f: count = 0 for t in tests: nabcc = False if t.has_key('mode') and t['mode'] == 'NABCC': nabcc = True if t.has_key('output'): result, inpos1 = translator1.translateWithInPos(t['input'], nabcc=nabcc) if t.has_key('inpos1'): correct_inpos1 = ','.join(['%d' % n for n in t['inpos1'] ]) else: correct_inpos1 = None result_inpos1 = ','.join(['%d' % n for n in inpos1]) if result != t['output'] or \ (correct_inpos1 and result_inpos1 != correct_inpos1) or \ (len(result) != len(inpos1)): count+=1 f.write("input: " + t['input'].encode('utf-8') + "\n") f.write("result: " + result.encode('utf-8') + "\n") f.write("correct: " + t['output'].encode('utf-8') + "\n") if correct_inpos1: f.write("correct_inpos1: " + correct_inpos1 + "\n") f.write("result_inpos1: " + result_inpos1 + "\n") if 'comment' in t: f.write("comment: " + t['comment'].encode('utf-8') + "\n") f.write("\n") print 'h1: %d error(s). see %s' % (count, outfile) return (count, outfile)
def translateWithInPos2(inbuf, logwrite=_logwrite, nabcc=False): if not mecab_initialized: initialize() # do not translate if string is unicode braille if all((0x2800 <= ord(c) <= 0x28ff or c == ' ') for c in inbuf): outbuf = inbuf inpos2 = [n for n in xrange(len(inbuf))] else: outbuf, inpos2 = japanese_braille_separate(inbuf, logwrite, nabcc=nabcc) result, inpos1 = translator1.translateWithInPos(outbuf, nabcc=nabcc) result = result.replace('□', ' ') return (outbuf, result, inpos1, inpos2)