class UpdaterProc(object): def __init__(self, config): # parse config file parser = SafeConfigParser() parser.read(config) self.Aligner_object = Aligner_GIZA(parser) self.Extractor_object = Extractor_Moses(parser) self.Annotator_object = Annotator_onlinecache(parser) self.logger = logging.getLogger('translation_log.updater') def update(self, source="", target=""): # get alignment information for the (source,correction) self.log("ALIGNER_INPUT source: " + str(source)) self.log("ALIGNER_INPUT correction: " + str(target)) aligner_output = self.Aligner_object.align(source=source, correction=target) self.log("ALIGNER_OUTPUT: " + str(aligner_output)) # get phrase pairs form the alignment information bias, new, full = self.Extractor_object.extract_phrases( source, target, aligner_output) self.log("BIAS: " + str(bias)) self.log("NEW: " + str(new)) self.log("FULL: " + str(full)) self.Annotator_object.cbtm_update(new=new, bias=bias, full=full) self.Annotator_object.cblm_update(target) # read and annotate the next sentence dummy_source = "" annotated_source = self.Annotator_object.annotate(dummy_source) return annotated_source def reset(self): annotated_source = '' annotated_source = annotated_source + '<dlt cblm-command="clear"/>' annotated_source = annotated_source + '<dlt cbtm-command="clear"/>' return annotated_source def log(self, message): self.logger.info(message)
class UpdaterProc(object): def __init__(self, config): # parse config file parser = SafeConfigParser() parser.read(config) self.Aligner_object = Aligner_GIZA(parser) self.Extractor_object = Extractor_Moses(parser) self.Annotator_object = Annotator_onlinecache(parser) self.logger = logging.getLogger('translation_log.updater') def update(self, source="", target=""): # get alignment information for the (source,correction) self.log("ALIGNER_INPUT source: "+str(source)) self.log("ALIGNER_INPUT correction: "+str(target)) aligner_output = self.Aligner_object.align(source=source,correction=target) self.log("ALIGNER_OUTPUT: "+str(aligner_output)) # get phrase pairs form the alignment information bias, new, full = self.Extractor_object.extract_phrases(source,target,aligner_output) self.log("BIAS: "+str(bias)) self.log("NEW: "+str(new)) self.log("FULL: "+str(full)) self.Annotator_object.cbtm_update(new=new, bias=bias, full=full) self.Annotator_object.cblm_update(target) # read and annotate the next sentence dummy_source = "" annotated_source = self.Annotator_object.annotate(dummy_source) return annotated_source def reset(self): annotated_source = '' annotated_source = annotated_source + '<dlt cblm-command="clear"/>' annotated_source = annotated_source + '<dlt cbtm-command="clear"/>' return annotated_source def log(self, message): self.logger.info(message)
while source: logging.info(str(s_id)) # talk to decoder logging.info("DECODER_IN: "+annotated_source) decoder_out, decoder_err = Decoder_object.communicate(annotated_source) logging.info("DECODER_OUT: "+decoder_out) # write translation to stdout sys.stdout.write(decoder_out+'\n') sys.stdout.flush() # now the reference is available correction = edit.readline().strip() logging.info("SOURCE: "+source) logging.info("USER_EDIT: "+correction) # get alignment information for the (source,correction) aligner_output = Aligner_object.align(source=source,correction=correction,moses_translation_options=decoder_err) logging.info("ALIGNER_OUTPUT: "+repr(aligner_output)) # get phrase pairs form the alignment information bias, new, full = Extractor_object.extract_phrases(source,correction,aligner_output) logging.info("BIAS: "+str(bias)) logging.info("NEW: "+str(new)) logging.info("FULL: "+str(full)) Annotator_object.cbtm_update(new=new, bias=bias, full=full) Annotator_object.cblm_update(correction) # read and annotate the next sentence source = input.readline().strip() annotated_source = Annotator_object.annotate(source)
logging.info(str(s_id)) # talk to decoder logging.info("DECODER_IN: " + annotated_source) decoder_out, decoder_err = Decoder_object.communicate(annotated_source) logging.info("DECODER_OUT: " + decoder_out) # write translation to stdout sys.stdout.write(decoder_out + '\n') sys.stdout.flush() # now the reference is available correction = edit.readline().strip() logging.info("SOURCE: " + source) logging.info("USER_EDIT: " + correction) # get alignment information for the (source,correction) aligner_output = Aligner_object.align( source=source, correction=correction, moses_translation_options=decoder_err) logging.info("ALIGNER_OUTPUT: " + repr(aligner_output)) # get phrase pairs form the alignment information bias, new, full = Extractor_object.extract_phrases( source, correction, aligner_output) logging.info("BIAS: " + str(bias)) logging.info("NEW: " + str(new)) logging.info("FULL: " + str(full)) Annotator_object.cbtm_update(new=new, bias=bias, full=full) Annotator_object.cblm_update(correction) # read and annotate the next sentence source = input.readline().strip()