00001 # Copyright (C) 1997-2004 The CDG Team <cdg@nats.informatik.uni-hamburg.de> 00002 # 00003 # This file is free software; as a special exception the author gives 00004 # unlimited permission to copy and/or distribute it, with or without 00005 # modifications, as long as this notice is preserved. 00006 # 00007 # This program is distributed in the hope that it will be useful, but 00008 # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 00009 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00010 00011 ## ---------------------------------------------------------------------------- 00012 ## YadaGlsStats - extra statistics for gls. 00013 ## \ingroup YadaRunnableDocuments 00014 ## 00015 ## \author Michael Daum 00016 ## 00017 ## $Id: YadaGlsStats.tcl,v 1.24 2004/02/25 14:42:09 micha Exp $ 00018 ## ---------------------------------------------------------------------------- 00019 class YadaGlsStats { 00020 inherit YadaRunnableDocument 00021 00022 # variables ---------------------------------------------------------------- 00023 private variable _totalTime 0 00024 private variable _totalRecall 0.0 00025 private variable _minUtility 0 00026 private variable _maxCosts 0 00027 private variable _maxDetour 0 00028 private variable _maxTime 0 00029 private variable _maxCycles 0 00030 private variable _typeOfColumn ;## \type TclArray 00031 private variable _lexicalHitsOf ;## \type TclArray 00032 private variable _triesOf ;## \type TclArray 00033 00034 # methods ------------------------------------------------------------------ 00035 public method activationHandle {} 00036 public method clear {} 00037 public method sortRows {colNo args}; ## \type TclNumber, TclList 00038 00039 constructor {args} {}; ## \type TclList 00040 00041 private method _analyseDocument {document experiment}; ## \type DomDocument, YadaExperiment 00042 private method _computeStatistics {} 00043 private method _showStatistics {} 00044 private method _getTypeOfColumn {colNo} ;## \type TclNumber 00045 private method _judgeRow {row}; ## \type TclNumber 00046 private method _resetDataOf {wordgraphs};## \type TclList 00047 }; 00048 00049 ## ---------------------------------------------------------------------------- 00050 ## constructor 00051 ## ---------------------------------------------------------------------------- 00052 body YadaGlsStats::constructor {args} { 00053 00054 # reconfigure table 00055 $itk_component(table) configure \ 00056 -rows 300 -cols 16 \ 00057 -cellanchor e \ 00058 -rowtagcommand [code $this _judgeRow] 00059 00060 # set types of columns 00061 array set _typeOfColumn { 00062 0 "dictionary" 00063 1 "integer" 00064 2 "real" 00065 3 "integer" 00066 4 "real" 00067 5 "integer" 00068 6 "integer" 00069 7 "real" 00070 8 "real" 00071 9 "real" 00072 10 "real" 00073 11 "real" 00074 12 "real" 00075 13 "integer" 00076 14 "integer" 00077 15 "integer" 00078 } 00079 00080 00081 itk_component add experimentBoxLabel { 00082 label $itk_component(heading).experimentBoxLabel \ 00083 -text "Experiment:" \ 00084 -anchor w 00085 } {} 00086 00087 # experiment box 00088 itk_component add experimentBox { 00089 iwidgets::combobox $itk_component(heading).experimentBox \ 00090 -completion false \ 00091 -borderwidth 2 \ 00092 -margin 4 \ 00093 -selectioncommand [code $this selectExperiment] 00094 } {} 00095 00096 # statistics 00097 itk_component add totalTimeLabel { 00098 label $itk_component(heading).totalTimeLabel \ 00099 -text "Time:" \ 00100 -anchor w 00101 } {} 00102 00103 itk_component add totalTime { 00104 entry $itk_component(heading).totalTime \ 00105 -borderwidth 2 \ 00106 -state disabled \ 00107 -width 20 00108 } {} 00109 00110 itk_component add minUtilityLabel { 00111 label $itk_component(heading).minUtilityLabel \ 00112 -text "Min.Utility:" \ 00113 -anchor w 00114 } {} 00115 00116 itk_component add minUtility { 00117 entry $itk_component(heading).minUtility \ 00118 -borderwidth 2 \ 00119 -state disabled \ 00120 -width 20 00121 } {} 00122 00123 itk_component add maxCostsLabel { 00124 label $itk_component(heading).maxCostsLabel \ 00125 -text "Max.Costs:" \ 00126 -anchor w 00127 } {} 00128 00129 itk_component add maxCosts { 00130 entry $itk_component(heading).maxCosts \ 00131 -borderwidth 2 \ 00132 -state disabled \ 00133 -width 20 00134 } {} 00135 00136 itk_component add maxDetourLabel { 00137 label $itk_component(heading).maxDetourLabel \ 00138 -text "Max.Detour:" \ 00139 -anchor w 00140 } {} 00141 00142 itk_component add maxDetour { 00143 entry $itk_component(heading).maxDetour \ 00144 -borderwidth 2 \ 00145 -state disabled \ 00146 -width 20 00147 } {} 00148 00149 itk_component add maxTimeLabel { 00150 label $itk_component(heading).maxTimeLabel \ 00151 -text "Max.Time:" \ 00152 -anchor w 00153 } {} 00154 00155 itk_component add maxTime { 00156 entry $itk_component(heading).maxTime \ 00157 -borderwidth 2 \ 00158 -state disabled \ 00159 -width 20 00160 } {} 00161 00162 itk_component add maxCyclesLabel { 00163 label $itk_component(heading).maxCyclesLabel \ 00164 -text "Max.Cycles:" \ 00165 -anchor w 00166 } {} 00167 00168 itk_component add maxCycles { 00169 entry $itk_component(heading).maxCycles \ 00170 -borderwidth 2 \ 00171 -state disabled \ 00172 -width 20 00173 } {} 00174 00175 itk_component add totalRecallLabel { 00176 label $itk_component(heading).totalRecallLabel \ 00177 -text "Lex.Recall:" \ 00178 -anchor w 00179 } {} 00180 00181 itk_component add totalRecall { 00182 entry $itk_component(heading).totalRecall \ 00183 -borderwidth 2 \ 00184 -state disabled \ 00185 -width 20 00186 } {} 00187 00188 # bindings 00189 set entry [$itk_component(experimentBox) component entry] 00190 bind $entry <Return> [code $this selectExperiment] 00191 bind $entry <Up> +[code $this selectExperiment] 00192 bind $entry <Down> +[code $this selectExperiment] 00193 00194 # packing 00195 grid columnconfigure $itk_component(heading) 1 -weight 1 00196 grid columnconfigure $itk_component(heading) 2 -pad 5 00197 grid columnconfigure $itk_component(heading) 3 -weight 1 00198 00199 grid $itk_component(experimentBoxLabel) -row 0 -column 0 -sticky ew -pady 2 00200 grid $itk_component(experimentBox) -row 0 -column 1 -sticky ew -pady 2 00201 grid $itk_component(totalRecallLabel) -row 0 -column 2 -sticky ew -pady 2 00202 grid $itk_component(totalRecall) -row 0 -column 3 -sticky ew -pady 2 00203 grid $itk_component(totalTimeLabel) -row 1 -column 0 -sticky ew -pady 2 00204 grid $itk_component(totalTime) -row 1 -column 1 -sticky ew -pady 2 00205 grid $itk_component(minUtilityLabel) -row 1 -column 2 -sticky ew -pady 2 00206 grid $itk_component(minUtility) -row 1 -column 3 -sticky ew -pady 2 00207 grid $itk_component(maxCostsLabel) -row 3 -column 0 -sticky ew -pady 2 00208 grid $itk_component(maxCosts) -row 3 -column 1 -sticky ew -pady 2 00209 grid $itk_component(maxDetourLabel) -row 3 -column 2 -sticky ew -pady 2 00210 grid $itk_component(maxDetour) -row 3 -column 3 -sticky ew -pady 2 00211 grid $itk_component(maxTimeLabel) -row 4 -column 0 -sticky ew -pady 2 00212 grid $itk_component(maxTime) -row 4 -column 1 -sticky ew -pady 2 00213 grid $itk_component(maxCyclesLabel) -row 4 -column 2 -sticky ew -pady 2 00214 grid $itk_component(maxCycles) -row 4 -column 3 -sticky ew -pady 2 00215 00216 00217 eval itk_initialize $args 00218 .main registerDocument $this 00219 } 00220 00221 ## ---------------------------------------------------------------------------- 00222 ## clear 00223 ## ---------------------------------------------------------------------------- 00224 body YadaGlsStats::clear {} { 00225 chain ;# call YadaRunnableDocument::clear 00226 00227 # reset the table 00228 set table $itk_component(table) 00229 $table setCell \ 00230 0,0 "wordgraph" \ 00231 0,1 "values" \ 00232 0,2 "score" \ 00233 0,3 "errors" \ 00234 0,4 "recall" \ 00235 0,5 "cycles" \ 00236 0,6 "time" \ 00237 0,7 "sol.time" \ 00238 0,8 "soft.time" \ 00239 0,9 "min.util" \ 00240 0,10 "needed util" \ 00241 0,11 "max.costs" \ 00242 0,12 "needed costs" \ 00243 0,13 "max.detour" \ 00244 0,14 "needed detour" \ 00245 0,15 "blind alleys" \ 00246 00247 $table tag config default -anchor e -relief flat -bd 2 00248 $table tag config error -bg red3 -fg white -anchor e -relief flat -bd 2 00249 $table tag config colored -bg gray80 -anchor e 00250 00251 $table tag config sel -fg "" -bg "" -relief raised -bd 1 00252 $table tag config active -anchor w -fg black -bg gray -relief sunk -bd 1 00253 $table tag config title -font {-adobe-helvetica-medium-r-normal--12-*-*-*-*-*-*-*} -bg #a3a3a3 -fg white 00254 $table tag config runner -fg red3 -bg #a3a3a3 00255 $table width 0 15 1 5 2 10 3 5 4 6 5 7 00256 $table tag raise runner title 00257 00258 # reset scores of selected wordgraphs 00259 _resetDataOf [_getActiveWordgraphs] 00260 00261 _computeStatistics 00262 } 00263 00264 ## ---------------------------------------------------------------------------- 00265 ## _analyseDocument 00266 ## ---------------------------------------------------------------------------- 00267 body YadaGlsStats::_analyseDocument {document experiment} { 00268 00269 # default analysis 00270 YadaRunnableDocument::_analyseDocument $document $experiment 00271 00272 # the wordgraph is needed at least 00273 if {$_analyseResult(wordgraph) == ""} { 00274 print "ERROR: no information available in this run\n" 00275 return 00276 } 00277 00278 # 00279 # special analysis 00280 # 00281 set _analyseResult(minUtility) 0 00282 set _analyseResult(minUtilityNeeded) 0 00283 set _analyseResult(maxCosts) 0 00284 set _analyseResult(maxCostsNeeded) 0 00285 set _analyseResult(maxDetour) 0 00286 set _analyseResult(maxDetourNeeded) 0 00287 set _analyseResult(blindAlleys) 0 00288 00289 00290 # get the root node 00291 set cdgpNode [$document documentElement] 00292 00293 # parse the statistics 00294 foreach aspect {steps minUtility 00295 minUtilityNeeded maxDetour maxDetourNeeded maxCosts maxCostsNeeded blindAlleys } { 00296 set _analyseResult($aspect) [[$cdgpNode selectNodes \ 00297 descendant::statistics/number\[@name="$aspect"\]] @value ] 00298 if {$_analyseResult($aspect) == ""} { 00299 set _analyseResult($aspect) 0 00300 } 00301 } 00302 00303 set _lexicalHitsOf($_analyseResult(wordgraph)) $_analyseResult(lexicalHits) 00304 set _triesOf($_analyseResult(wordgraph)) $_analyseResult(tries) 00305 set lexicalRecall [expr $_analyseResult(lexicalHits) * 100.0 / $_analyseResult(tries) ] 00306 00307 00308 # add the collected data to the table 00309 _insertData $_analyseResult(wordgraph) \ 00310 $_analyseResult(noValues) \ 00311 [format "%4.3e" $_analyseResult(score)] \ 00312 [expr $_analyseResult(tries) - $_analyseResult(lexicalHits)] \ 00313 [format "%.2f" $lexicalRecall] \ 00314 $_analyseResult(steps) \ 00315 $_analyseResult(totalTime) \ 00316 $_analyseResult(solutionTime) \ 00317 $_analyseResult(softTime) \ 00318 [format "%4.3e" $_analyseResult(minUtility)] \ 00319 [format "%4.3e" $_analyseResult(minUtilityNeeded)] \ 00320 [format "%.2f" $_analyseResult(maxCosts)] \ 00321 [format "%.2f" $_analyseResult(maxCostsNeeded)] \ 00322 $_analyseResult(maxDetour) \ 00323 $_analyseResult(maxDetourNeeded) \ 00324 $_analyseResult(blindAlleys) 00325 } 00326 00327 ## ---------------------------------------------------------------------------- 00328 ## activationHandle 00329 ## ---------------------------------------------------------------------------- 00330 body YadaGlsStats::activationHandle {} { 00331 chain ;# call YadaRunnableDocument::activationHandle 00332 00333 foreach experiment [.main getExperiments] { 00334 set experimentName [$experiment cget -name] 00335 if {$experimentName == "<none>" || 00336 ([$experiment cget -isActive] && [$experiment cget -type] == "gls")} { 00337 lappend experimentNames $experimentName 00338 } 00339 } 00340 00341 # get the previous selection 00342 set box $itk_component(experimentBox) 00343 set experimentName [$box get] 00344 00345 # default experiments to choose 00346 if {$experimentName == ""} { 00347 set experimentName "<none>" 00348 } 00349 00350 set listOfEntries [[$box component list] get 0 end] 00351 if {$listOfEntries != $experimentNames} { 00352 $box clear list 00353 eval $box insert list end $experimentNames 00354 selectExperiment $experimentName 00355 } 00356 } 00357 00358 ## ---------------------------------------------------------------------------- 00359 ## _computeStatistics 00360 ## ---------------------------------------------------------------------------- 00361 body YadaGlsStats::_computeStatistics {} { 00362 chain 00363 00364 set table $itk_component(table) 00365 set rmax [$table cget -rows] 00366 00367 set _totalTime 0 00368 set _totatLexicalRecall 0.0 00369 set _minUtility 999999999 00370 set _maxCosts 0 00371 set _maxDetour 0 00372 set _maxTime 0 00373 set _maxCycles 0 00374 00375 set totalTries 0 00376 set totalLexicalHits 0 00377 00378 for {set row 1} {$row < $rmax} {incr row} { 00379 00380 set dataRow [$table getCell $row,0 $row,14] 00381 set wordgraph [lindex $dataRow 0] 00382 # set noValues [lindex $dataRow 1] 00383 # set score [lindex $dataRow 2] 00384 set errors [lindex $dataRow 3] 00385 set cycles [lindex $dataRow 5] 00386 set time [lindex $dataRow 6] 00387 set minUtilityNeeded [lindex $dataRow 7] 00388 set maxCostsNeeded [lindex $dataRow 12] 00389 set maxDetourNeeded [lindex $dataRow 14] 00390 00391 if {$errors == ""} { 00392 continue 00393 } 00394 00395 incr _totalTime $time 00396 if {$_minUtility > $minUtilityNeeded} { 00397 set _minUtility $minUtilityNeeded 00398 } 00399 if {$_maxCosts < $maxCostsNeeded} { 00400 set _maxCosts $maxCostsNeeded 00401 } 00402 if {$_maxDetour < $maxDetourNeeded} { 00403 set _maxDetour $maxDetourNeeded 00404 } 00405 if {$_maxTime < $time} { 00406 set _maxTime $time 00407 } 00408 if {$_maxCycles < $cycles} { 00409 set _maxCycles $cycles 00410 } 00411 00412 incr totalTries $_triesOf($wordgraph) 00413 incr totalLexicalHits $_lexicalHitsOf($wordgraph) 00414 } 00415 00416 if {$totalTries > 0} { 00417 set _totalRecall [expr $totalLexicalHits * 100.0 / $totalTries ] 00418 } 00419 00420 _showStatistics 00421 } 00422 00423 ## ---------------------------------------------------------------------------- 00424 ## _showStatistics 00425 ## ---------------------------------------------------------------------------- 00426 body YadaGlsStats::_showStatistics {} { 00427 $itk_component(totalTime) configure -state normal 00428 $itk_component(minUtility) configure -state normal 00429 $itk_component(maxCosts) configure -state normal 00430 $itk_component(maxDetour) configure -state normal 00431 $itk_component(maxTime) configure -state normal 00432 $itk_component(maxCycles) configure -state normal 00433 $itk_component(totalRecall) configure -state normal 00434 00435 $itk_component(totalTime) delete 0 end 00436 $itk_component(minUtility) delete 0 end 00437 $itk_component(maxCosts) delete 0 end 00438 $itk_component(maxDetour) delete 0 end 00439 $itk_component(maxTime) delete 0 end 00440 $itk_component(maxCycles) delete 0 end 00441 $itk_component(totalRecall) delete 0 end 00442 00443 $itk_component(totalTime) insert 0 "[timeToString $_totalTime]" 00444 if {$_minUtility == 999999999} { 00445 $itk_component(minUtility) insert 0 "<min>" 00446 } else { 00447 $itk_component(minUtility) insert 0 [format "%4.3e" $_minUtility] 00448 } 00449 $itk_component(maxCosts) insert 0 [format "%.2f" $_maxCosts] 00450 $itk_component(maxDetour) insert 0 $_maxDetour 00451 $itk_component(maxTime) insert 0 $_maxTime 00452 $itk_component(maxCycles) insert 0 $_maxCycles 00453 $itk_component(totalRecall) insert 0 [format "%.4f" $_totalRecall] 00454 00455 $itk_component(totalTime) configure -state disabled 00456 $itk_component(minUtility) configure -state disabled 00457 $itk_component(maxCosts) configure -state disabled 00458 $itk_component(maxDetour) configure -state disabled 00459 $itk_component(maxTime) configure -state disabled 00460 $itk_component(maxCycles) configure -state disabled 00461 $itk_component(totalRecall) configure -state disabled 00462 } 00463 00464 ## ---------------------------------------------------------------------------- 00465 ## _getTypeOfColumn 00466 ## ---------------------------------------------------------------------------- 00467 body YadaGlsStats::_getTypeOfColumn {colNo} { 00468 return $_typeOfColumn($colNo) 00469 } 00470 00471 ## ---------------------------------------------------------------------------- 00472 ## sortRows 00473 ## ---------------------------------------------------------------------------- 00474 body YadaGlsStats::sortRows {colNo args} { 00475 eval chain $colNo $args 00476 _computeStatistics 00477 } 00478 00479 ## ---------------------------------------------------------------------------- 00480 ## _judgeRow 00481 ## ---------------------------------------------------------------------------- 00482 body YadaGlsStats::_judgeRow {row} { 00483 set recall [$itk_component(table) getCell $row,4] 00484 if {$recall != "" && $recall < 100.0} { 00485 return "error" 00486 } else { 00487 if {[expr $row % 2]} { 00488 return "default" 00489 } else { 00490 return "colored" 00491 } 00492 } 00493 } 00494 00495 ## ---------------------------------------------------------------------------- 00496 ## _resetDataOf 00497 ## ---------------------------------------------------------------------------- 00498 body YadaGlsStats::_resetDataOf {wordgraphs} { 00499 chain $wordgraphs 00500 foreach wordgraph $wordgraphs { 00501 set _triesOf($wordgraph) 0 00502 set _lexicalHitsOf($wordgraph) 0 00503 } 00504 } 00505