def add_charcut_diff(self, trg_str: str, reference: str, match_size: numbers.Integral = 3, alt_norm: bool = False, mt_label: str = "MT:", ref_label: str = "Ref:") -> None: aligned_segs = charcut.load_input_segs(cand_segs=[trg_str], ref_segs=[reference]) styled_ops = [ charcut.compare_segments(cand, ref, match_size) for seg_id, _, _, cand, ref in aligned_segs ] seg_scores = list(charcut.score_all(aligned_segs, styled_ops, alt_norm)) # doc_cost = sum(cost for cost, _ in seg_scores) # doc_div = sum(div for _, div in seg_scores) self.html_contents.append( charcut.segs2html(aligned_segs[0], styled_ops[0], seg_scores[0], mt_label=mt_label, ref_label=ref_label, use_id_col=False))
def conclude_report(self) -> None: if self.hyp_sents: html_filename = os.path.join(self.report_path, "charcut.html") utils.make_parent_dir(html_filename) args = utils.ArgClass(html_output_file=html_filename, match_size=self.match_size, alt_norm=self.alt_norm) aligned_segs = charcut.load_input_segs(cand_segs=self.hyp_sents, ref_segs=self.ref_sents, src_segs=self.src_sents) charcut.run_on(aligned_segs, args) self.hyp_sents, self.ref_sents, self.src_sents = [], [], []
def on_end_inference(self): if self.hyp_sents: html_filename = f"{self.report_path}/charcut.html" util.make_parent_dir(html_filename) args = util.ArgClass(html_output_file=html_filename, match_size=self.match_size, alt_norm=self.alt_norm) aligned_segs = charcut.load_input_segs(cand_segs=self.hyp_sents, ref_segs=self.ref_sents, src_segs=self.src_sents) charcut.run_on(aligned_segs, args) self.hyp_sents, self.ref_sents, self.src_sents = [], [], []