Esempio n. 1
0
  def html_content(self, output_directory=None):
    report_length = self.report_length
    for cnt, (left, right) in enumerate(self.compare_directions):
      sleft, sright = sys_names[left], sys_names[right]
      ref, out1, out2 = self.ref, self.outs[left], self.outs[right]
      html = tag_str('h4', f'{report_length} sentences where {sleft}>{sright} at {self.scorer.name()}')
      for bdiff, s1, s2, str1, str2, i in self.scorediff_lists[cnt][:report_length]:
        table = [['', 'Output', f'{self.scorer.idstr()}']]
        if self.src:
          table.append(['Src', ' '.join(self.src[i]), ''])
        table += [
          ['Ref', ' '.join(ref[i]), ''],
          [f'{sleft}', ' '.join(out1[i]), fmt(s1)],
          [f'{sright}', ' '.join(out2[i]), fmt(s2)]
        ]
        
        html += html_table(table, None)

      html += tag_str('h4', f'{report_length} sentences where {sright}>{sleft} at {self.scorer.name()}')
      for bdiff, s1, s2, str1, str2, i in self.scorediff_lists[cnt][-report_length:]:
        table = [['', 'Output', f'{self.scorer.idstr()}']]
        if self.src:
          table.append(['Src', ' '.join(self.src[i]), ''])
        table += [
          ['Ref', ' '.join(ref[i]), ''],
          [f'{sleft}', ' '.join(out1[i]), fmt(s1)],
          [f'{sright}', ' '.join(out2[i]), fmt(s2)]
        ]

        html += html_table(table, None)

    return html
Esempio n. 2
0
def html_table(table, caption=None, bold_rows=1, bold_cols=1):
    html = '<table border="1">\n'
    if caption is not None:
        html += tag_str('caption', caption)
    for i, row in enumerate(table):
        tag_type = 'th' if (i < bold_rows) else 'td'
        table_row = '\n  '.join(
            tag_str('th' if j < bold_cols else tag_type, rdata)
            for (j, rdata) in enumerate(row))
        html += tag_str('tr', table_row)
    html += '\n</table>\n <br/>'

    tab_id = next_tab_id()
    latex_code = "\\begin{table}[t]\n  \\centering\n"
    cs = ['c'] * len(table[0])
    if bold_cols != 0:
        cs[bold_cols - 1] = 'c||'
    latex_code += "  \\begin{tabular}{" + ''.join(cs) + "}\n"
    for i, row in enumerate(table):
        latex_code += ' & '.join([fmt(x) for x in row]) + (
            ' \\\\\n' if i != bold_rows - 1 else ' \\\\ \\hline \\hline\n')
    latex_code += "  \\end{tabular}\n  \\caption{Caption}\n  \\label{tab:table" + tab_id + "}\n\\end{table}"

    html += (
        f'<button onclick="showhide(\'{tab_id}_latex\')">Show/Hide LaTeX</button> <br/>'
        + f'<pre id="{tab_id}_latex" style="display:none">{latex_code}</pre>')
    return html
Esempio n. 3
0
  def html_content(self, output_directory=None):
    report_length = self.report_length
    html = tag_str('p', f'min_ngram_length={self.min_ngram_length}, max_ngram_length={self.max_ngram_length}')
    html += tag_str('p', f'report_length={report_length}, alpha={self.alpha}, compare_type={self.compare_type}')
    if self.label_files is not None:
      html += tag_str('p', self.label_files)

    for i, (left, right) in enumerate(self.compare_directions):
      caption = f'{report_length} n-grams where {sys_names[left]}>{sys_names[right]} in {self.compare_type}'
      table = [['n-gram', self.compare_type, f'{sys_names[left]}', f'{sys_names[right]}']]
      table.extend([[' '.join(k), fmt(v), self.matches[left][k], self.matches[right][k]] for k, v in self.scorelist[i][:report_length]])
      html += html_table(table, caption)

      caption = f'{report_length} n-grams where {sys_names[right]}>{sys_names[left]} in {self.compare_type}'
      table = [['n-gram', self.compare_type, f'{sys_names[left]}', f'{sys_names[right]}']]
      table.extend([[' '.join(k), fmt(v), self.matches[left][k], self.matches[right][k]] for k, v in reversed(self.scorelist[i][-report_length:])])
      html += html_table(table, caption)
    return html 
Esempio n. 4
0
 def __init__(self, scorer, scores, strs,
              wins=None, sys_stats=None):
   self.scorer = scorer 
   self.scores = scores
   self.strs = [f'{fmt(x)} ({y})' if y else fmt(x) for (x,y) in zip(scores,strs)]
   self.wins = wins
   self.sys_stats = sys_stats
   self.output_fig_file = f'{next_fig_id()}-score-{scorer.idstr()}'
   self.prob_thresh = 0.05
Esempio n. 5
0
 def html_content(self, output_directory=None):
   table = [ [self.bucketer.idstr()] + sys_names ]
   for i, bs in enumerate(self.bucketer.bucket_strs):
     line = [bs]
     for stat in self.sys_stats:
       line.append(fmt(stat[i]))
     table.extend([line])
   html = html_table(table, self.title)
   for ext in ('png', 'pdf'):
     self.plot(output_directory, self.output_fig_file, ext)
   html += html_img_reference(self.output_fig_file, 'Sentence Bucket Analysis')
   return html 
Esempio n. 6
0
 def html_content(self, output_directory=None):
   line = [self.bucketer.idstr()]
   if self.bucket_cnts is not None:
     line.append('# sents')
   line += sys_names
   table = [ line ]
   for i, bs in enumerate(self.bucketer.bucket_strs):
     line = [bs]
     if self.bucket_cnts is not None:
       line.append(f'\t{self.bucket_cnts[i]}')
     for j, stat in enumerate(self.sys_stats):
       line.append(fmt(stat[i]))
       if self.bucket_intervals is not None:
         interval =  self.bucket_intervals[j][i]
         low, up = interval['lower_bound'], interval['upper_bound']
         line[-1] += f'<font size=2> [{fmt(low)}, {fmt(up)}]</font>'
     table.extend([line])
   html = html_table(table, self.title)
   for ext in ('png', 'pdf'):
     self.plot(output_directory, self.output_fig_file, ext)
   html += html_img_reference(self.output_fig_file, 'Sentence Bucket Analysis')
   return html 
Esempio n. 7
0
 def print_tabbed_table(self, tab):
   for x in tab:
     print('\t'.join([fmt(y) if y else '' for y in x]))
   print()