translator = Translator(model) for line in lines: left = tuple(line.split()) try: result = translator(left) print(" ".join(result)) except translator.TranslationFailure: print("<translation-failed/>") # =========================================================================== if __name__ == "__main__": import optparse import tool optparser = optparse.OptionParser(usage="%prog [OPTION]... FILE...\n" + __doc__, version="%prog " + __version__) SequiturTool.addOptions(optparser) tool.addTrainOptions(optparser) optparser.add_option( "-a", "--apply", dest="applySample", help="apply translation to sentences read from FILE", metavar="FILE", ) options, args = optparser.parse_args() tool.run(main, options, args)
# =========================================================================== def main(options, args): model = SequiturTool.procureModel(options, loadSample) if options.applySample: lines = gopen(options.applySample).readlines() words = Set([ word for line in lines for word in line.split() ]) addUnknowns(model, words) translator = Translator(model) for line in lines: left = tuple(line.split()) try: result = translator(left) print ' '.join(result) except translator.TranslationFailure: print '<translation-failed/>' # =========================================================================== if __name__ == '__main__': import optparse, tool optparser = optparse.OptionParser( usage = '%prog [OPTION]... FILE...\n' + __doc__, version = '%prog ' + __version__) SequiturTool.addOptions(optparser) tool.addTrainOptions(optparser) optparser.add_option( '-a', '--apply', dest='applySample', help='apply translation to sentences read from FILE', metavar='FILE') options, args = optparser.parse_args() tool.run(main, options, args)