class UpdaterProc(object): def __init__(self, config): # parse config file parser = SafeConfigParser() parser.read(config) self.Aligner_object = Aligner_onlineGIZA(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_onlineGIZA(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)