commit 57278a5537f6aae4d58274de7841da7a1d52001d Author: Daniel Swanson Date: Fri Jul 9 14:49:50 2021 -0500 change web format to be closer to CLI diff --git a/apertium-regtest.py b/apertium-regtest.py index 34c7d37..77a2e10 100755 --- a/apertium-regtest.py +++ b/apertium-regtest.py @@ -92,7 +92,7 @@ def save_gold(fname, data): with open(fname, 'w') as fout: for inhash in sorted(data.keys()): fout.write('[%s]\n' % inhash) - for ln in sorted(data[inhash]): + for ln in sorted(set(data[inhash])): fout.write('%s [/option]\n' % ln) fout.write('[/%s]\n' % inhash) @@ -553,7 +553,11 @@ def start_server(port): print('Starting server') print('Open http://localhost:%d in your browser' % port) with socketserver.TCPServer(('', port), handle) as httpd: - httpd.serve_forever() + try: + httpd.serve_forever() + except KeyboardInterrupt: + print('') + sys.exit(0) class RegtestShell(cmd.Cmd): prompt = '> ' diff --git a/static/regtest.css b/static/regtest.css index b77ab13..5816a98 100644 --- a/static/regtest.css +++ b/static/regtest.css @@ -57,8 +57,19 @@ pre { font-weight: bold; } .rt-input { + font-size: 11px; font-style: italic; - margin-bottom: 1ex; + margin: 1ex; +} + +ul.rt-gold { + margin-top: 1ex; +} + +ul.rt-gold:before { + content: "Golds: "; + font-style: normal; + font-weight: bold; } .rt-count { diff --git a/static/regtest.js b/static/regtest.js index 7f191e3..d504b34 100644 --- a/static/regtest.js +++ b/static/regtest.js @@ -233,23 +233,25 @@ function btn_gold_replace() { let tr = $(this).closest('tr'); let c = tr.attr('data-corp'); let h = tr.attr('data-hash'); - let gs = [tr.find('pre.rt-last-tab').attr('data-output')]; - let tid = toast('Replacing Gold', 'Corpus '+c+' sentence '+h); - post({a: 'gold', c: c, h: h, gs: JSON.stringify(gs)}).done(function(rv) { $(tid).toast('hide'); cb_accept(rv); }); + let s = tr.find('.nav-link.active').text(); + let gs = [tr.find('.rt-output.active').attr('data-output')]; + let tid = toast('Replacing Gold', 'Corpus '+c+' sentence '+h+' step '+s); + post({a: 'gold', c: c, h: h, s: s, gs: JSON.stringify(gs)}).done(function(rv) { $(tid).toast('hide'); cb_accept(rv); }); } function btn_gold_add() { let tr = $(this).closest('tr'); let c = tr.attr('data-corp'); let h = tr.attr('data-hash'); + let s = tr.find('.nav-link.active').text(); let gs = []; let gold = state[c].cmds[state[c].cmds.length-1].gold; if (gold.hasOwnProperty(h)) { gs = gold[h]; } - gs.push(tr.find('pre.rt-last-tab').attr('data-output')); - let tid = toast('Adding Gold', 'Corpus '+c+' sentence '+h); - post({a: 'gold', c: c, h: h, gs: JSON.stringify(gs)}).done(function(rv) { $(tid).toast('hide'); cb_accept(rv); }); + gs.push(tr.find('.rt-output.active').attr('data-output')); + let tid = toast('Adding Gold', 'Corpus '+c+' sentence '+h+' step '+s); + post({a: 'gold', c: c, h: h, s: s, gs: JSON.stringify(gs)}).done(function(rv) { $(tid).toast('hide'); cb_accept(rv); }); } function btn_accept() { @@ -372,13 +374,10 @@ function btn_show_tab() { let div = $($(this).attr('href')); let type = div.attr('data-type'); - let text = div.text(); + let text = div.attr('data-output'); let expect = div.attr('data-expect'); - if ($(this).hasClass('rt-tab-gold')) { - // Nothing - } - else if (expect) { + if (expect) { let diff = Diff.diffWordsWithSpace(expect, text); let output = ''; for (let d=0 ; d'+esc_html(input.text())+''); + $(div).find('pre').html(hilite_output(esc_html(text), type)); } $(this).attr('data-hilite', true); @@ -535,7 +528,6 @@ function cb_load(rv) { let cmds = state[c].cmds; let ins = state[c].inputs; - let golds = cmds[cmds.length-1].gold; // TODO: use per-step let outs = cmds[0].expect; let add = state[c].add; let del = state[c].del; @@ -584,8 +576,7 @@ function cb_load(rv) { let body = '
'; let id = c+'-'+k+'-input'; - nav += ''; - body += '
'+esc_html(ins[k][1])+'
'; + body += '
'+esc_html(ins[k][1])+'
'; for (let i=0 ; i'+cmd.opt+''; - body += '
'+output+'
'; + body += '
'+output+'
'; + + if (cmd.gold.hasOwnProperty(k)) { + let ul = '
    '; + for (let g = 0; g < cmd.gold[k].length; g++) { + ul += '
  • '+esc_html(cmd.gold[k][g])+'
  • '; + } + ul += '
'; + body += ul; + } + body += '
'; if (cmd.trace.hasOwnProperty(k)) { let id = c+'-'+k+'-'+cmd.opt+'-trace'; @@ -641,17 +636,6 @@ function cb_load(rv) { } } - if (golds.hasOwnProperty(k)) { - let id = c+'-'+k+'-gold'; - let ul = 'Input:

'+esc_html(ins[k][1])+'

Golds:
    '; - for (let g=0 ; g'; - } - ul += '
'; - nav += ''; - body += '
'+ul+'
'; - } - body += '
'; nav += ''; if (changed) {