#!/usr/bin/tclsh # eval2tex - evaluation display script # Copyright (C) 2004-2007 Richard Moot (Richard.Moot@labri.fr) # Copyright (C) 2004-2007 CNRS (http://www.cnrs.fr) # Copyright (C) 2004-2007 INRIA (http://www.inria.fr) # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # takes an evaluation file as produced by the evalkmaxent script # and transforms it to a LaTeX file containing a bar chart of the # statistics. set debug 0 set diff 10 set color blue proc loadcgn {file} { global diff color set lx 0 set rx [expr $lx+$diff] set f [open $file r] set of [open "[file rootname $file].tex" w] set sentno 0 # read the cgn output file and convert it to an array puts $of "\\documentclass{article}" puts $of "" puts $of "\\usepackage{a4wide}" puts $of "\\usepackage{color}" puts $of "\\usepackage{epic}" puts $of "\\usepackage{eepicemu}" puts $of "\\input{pnmacros}" puts $of "" puts $of "\\begin{document}" puts $of "" puts $of "\\setlength{\\unitlength}{0.5mm}" puts $of "" set list {} set items 0 while {[gets $f line] >= 0} { if {[regexp {([^[:space:]]+).*[[:space:]]+([[:digit:]]+)\.([[:digit:]]+)[[:space:]]+} $line all l d1 d2]} { set t [expr ($d1.$d2)] set l [string toupper $l] lappend list $lx $rx $t $l incr items set lx $rx incr rx $diff } elseif {[regexp {([[:digit:]]+)[[:space:]]+words\,[[:space:]]+([[:digit:]]+)[[:space:]]+correct} $line all words correct]} { set t [expr double($correct*100)/double($words)] set lx $rx incr rx $diff lappend list $lx $rx $t Total incr items 2 set lx $rx incr rx $diff } } puts $of "\\begin{picture}([expr $items*$diff],110)" print_grid $of $items print_items $of $list puts $of "\\end{picture}" puts $of "" puts $of "\\end{document}" close $f close $of } proc print_grid {of items} { global diff set r [expr $items*$diff] set t [expr 10*$diff] for {set i $diff} {$i <= $r} {incr i $diff} { puts $of "\\path($i,0)($i,100)" } for {set i $diff} {$i <= $t} {incr i $diff} { puts $of "\\path(-2,$i)($r,$i)" } for {set i 0} {$i <= $t} {incr i $diff} { puts $of "\\put(-5,$i){\\makebox(0,0)\[r\]{$i}}" } puts $of "\\thicklines" puts $of "\\path(0,100)(0,0)($r,0)" } proc print_items {of list} { set end [llength $list] for {set i 0} {$i < $end} {incr i} { set lx [lindex $list $i] incr i set rx [lindex $list $i] incr i set t [lindex $list $i] incr i set l [lindex $list $i] rectangle $of $lx $rx $t $l } } proc rectangle {of lx rx t l} { global diff color puts $of "\\put([expr $lx+($diff/2)],-10){\\makebox(0,0){\\tiny $l}}" puts $of "\\textcolor{$color}{\\put($lx,0){\\rectangle{10}{$t}}}" puts $of "\\path($lx,0)($lx,$t)($rx,$t)($rx,0)($lx,0)" } set files [lrange $argv 0 end] foreach f $files { if {[file readable $f]} { puts stderr "File: $f" loadcgn $f } else { puts stderr "File $f does not exist or is unreadable" exit 1 } }