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
## YadaRunner - document to run YadaJobs.
00013
## This document is the basic implementation of a YadaRunnableDocument. A more
00014
## specific implementation of a YadaRunnableDocument is for example the YadaGlsStats.
00015
## We implement here the basic functionality to select an schedule YadaJobs
00016
## that run on YadaMachines.
00017
## \ingroup YadaRunnableDocuments
00018
##
00019
## \author Michael Daum
00020
##
00021
## $Id: YadaRunner.tcl,v 1.27 2004/09/06 13:41:13 micha Exp $
00022
## ----------------------------------------------------------------------------
00023 class YadaRunner {
00024 inherit
YadaRunnableDocument
00025
00026
# private variables ----------------------------------------------------------------
00027
private variable _totalTime 0
00028
private variable _totalSolTime 0
00029
private variable _totalSoftTime 0
00030
private variable _totalScore 0
00031
private variable _noSolutions 0
00032
private variable _noErrors 0
00033
private variable _totalWordgraphs 0
00034
private variable _totalStructRecall 0
00035
private variable _totalLabelledRecall 0
00036
private variable _totalLexicalRecall 0
00037
private variable _totalStrictRecall 0
00038
private variable _typeOfColumn; ## \type TclArray
00039
private variable _scoreOf; ## \type TclArray
00040
private variable _structHitsOf; ## \type TclArray
00041
private variable _labelledHitsOf; ## \type TclArray
00042
private variable _lexicalHitsOf; ## \type TclArray
00043
private variable _strictHitsOf; ## \type TclArray
00044
private variable _triesOf; ## \type TclArray
00045
00046
00047
# methods ------------------------------------------------------------------
00048
public method
activationHandle {}
00049
public method
clear {}
00050
public method
toDOM {}
00051
public method
fromDOM {rootNode}; ## \type domNode
00052
public method
getPersistanceFileName {}; ## overriding
virtual method from
YadaPlainDocument
00053
public method
displayTitle {}
00054
public method
reload {}
00055
00056
## accessor methods
00057
public method
getTotalTime {}
00058
public method
getTotalSolTime {}
00059
public method
getTotalSoftTime {}
00060
public method
getTotalStructRecall {}
00061
public method
getTotalLabelRecall {}
00062
public method
getTotalLexRecall {}
00063
public method
getTotalScore {}
00064
00065
public method
load {}; ## overrides implementation from
YadaPlainDocument
00066
00067
00068
00069
00070
00071 constructor {args} {}; ## \type TclList
00072
00073
private method
_analyseDocument {document experiment} ;## \type DomDocument,
YadaExperiment
00074
private method
_showStatistics {}
00075
private method
_computeStatistics {}
00076
private method
_judgeRow {row}; ## \type TclNumber
00077
private method
_getTypeOfColumn {colNo} ;## \type TclNumber
00078
private method
_toHtml {}
00079
private method
_resetDataOf {wordgraphs} ;## \type TclList
00080
private method
_getUpdatedWordgraphNames {}
00081
private method
_getSavedWordgraphNames {rootNode} ; ## \type domNode
00082
private method
_isModified {rootNode}; ## \type domNode
00083
private method
_getLoadedWordgraphNames {}
00084 };
00085
00086
## ----------------------------------------------------------------------------
00087
## constructor
00088
## ----------------------------------------------------------------------------
00089
body YadaRunner::constructor {args} {
00090
# reconfigure table
00091 $itk_component(table) configure -rows 300 -cols 12 \
00092 -rowtagcommand [code $this _judgeRow]
00093
00094 # set types of columns
00095 array set _typeOfColumn {
00096 0
"dictionary"
00097 1
"integer"
00098 2
"real"
00099 3
"integer"
00100 4
"integer"
00101 5
"integer"
00102 6
"integer"
00103 7
"real"
00104 8
"real"
00105 9
"real"
00106 10
"real"
00107 }
00108
00109
00110 itk_component add experimentBoxLabel {
00111 label $itk_component(heading).experimentBoxLabel \
00112 -text
"Experiment:" \
00113 -anchor w
00114 } {}
00115
00116 itk_component add experimentBox {
00117 iwidgets::combobox $itk_component(heading).experimentBox \
00118 -completion
false \
00119 -borderwidth 2 \
00120 -margin 4 \
00121 -selectioncommand [code $this selectExperiment]
00122 } {}
00123
00124 itk_component add totalScoreLabel {
00125 label $itk_component(heading).totalScoreLabel \
00126 -text
"Score:" \
00127 -anchor w \
00128 } {}
00129
00130 itk_component add totalScore {
00131 entry $itk_component(heading).totalScore \
00132 -borderwidth 2 \
00133 -state disabled \
00134 -width 20
00135 } {}
00136
00137 itk_component add totalTimeLabel {
00138 label $itk_component(heading).totalTimeLabel \
00139 -text
"Time:" \
00140 -anchor w
00141 } {}
00142
00143 itk_component add totalTime {
00144 entry $itk_component(heading).totalTime \
00145 -borderwidth 2 \
00146 -state disabled \
00147 -width 20
00148 } {}
00149
00150 itk_component add noErrorsLabel {
00151 label $itk_component(heading).noErrorsLabel \
00152 -text
"No.Errors:" \
00153 -anchor w
00154 } {}
00155
00156 itk_component add noErrors {
00157 entry $itk_component(heading).noErrors \
00158 -textvariable [scope _noErrors] \
00159 -borderwidth 2 \
00160 -state disabled \
00161 -width 20
00162 } {}
00163
00164 itk_component add noSolutionsLabel {
00165 label $itk_component(heading).noSolutionsLabel \
00166 -text
"No.Solutions:" \
00167 -anchor w
00168 } {}
00169
00170 itk_component add noSolutions {
00171 entry $itk_component(heading).noSolutions \
00172 -textvariable [scope _noSolutions] \
00173 -borderwidth 2 \
00174 -state disabled \
00175 -width 20
00176 } {}
00177
00178 itk_component add totalSolTimeLabel {
00179 label $itk_component(heading).totalSolTimeLabel \
00180 -text
"Sol.Time:" \
00181 -anchor w
00182 } {}
00183
00184 itk_component add totalSolTime {
00185 entry $itk_component(heading).totalSolTime \
00186 -borderwidth 2 \
00187 -state disabled \
00188 -width 20
00189 } {}
00190
00191 itk_component add totalSoftTimeLabel {
00192 label $itk_component(heading).totalSoftTimeLabel \
00193 -text
"Soft.Time:" \
00194 -anchor w
00195 } {}
00196
00197 itk_component add totalSoftTime {
00198 entry $itk_component(heading).totalSoftTime \
00199 -borderwidth 2 \
00200 -state disabled \
00201 -width 20
00202 } {}
00203
00204 itk_component add totalStructRecallLabel {
00205 label $itk_component(heading).totalStructRecallLabel \
00206 -text
"Struct.Recall:" \
00207 -anchor w
00208 } {}
00209
00210 itk_component add totalStructRecall {
00211 entry $itk_component(heading).totalStructRecall \
00212 -borderwidth 2 \
00213 -state disabled \
00214 -width 20
00215 } {}
00216
00217 itk_component add totalLabelledRecallLabel {
00218 label $itk_component(heading).totalLabelledRecallLabel \
00219 -text
"Label.Recall:" \
00220 -anchor w
00221 } {}
00222
00223 itk_component add totalLabelledRecall {
00224 entry $itk_component(heading).totalLabelledRecall \
00225 -borderwidth 2 \
00226 -state disabled \
00227 -width 20
00228 } {}
00229
00230 itk_component add totalLexicalRecallLabel {
00231 label $itk_component(heading).totalLexicalRecallLabel \
00232 -text
"Lex.Recall:" \
00233 -anchor w
00234 } {}
00235
00236 itk_component add totalLexicalRecall {
00237 entry $itk_component(heading).totalLexicalRecall \
00238 -borderwidth 2 \
00239 -state disabled \
00240 -width 20
00241 } {}
00242
00243 itk_component add totalStrictRecallLabel {
00244 label $itk_component(heading).totalStrictRecallLabel \
00245 -text
"Strict.Recall:" \
00246 -anchor w
00247 } {}
00248
00249 itk_component add totalStrictRecall {
00250 entry $itk_component(heading).totalStrictRecall \
00251 -borderwidth 2 \
00252 -state disabled \
00253 -width 20
00254 } {}
00255
00256
# bindings
00257
set entry [$itk_component(experimentBox) component entry]
00258 bind $entry <Return> [code $this selectExperiment]
00259 bind $entry <Up> +[code $this selectExperiment]
00260 bind $entry <Down> +[code $this selectExperiment]
00261
00262 # packing
00263 grid columnconfigure $itk_component(heading) 1 -weight 1
00264 grid columnconfigure $itk_component(heading) 2 -pad 5
00265 grid columnconfigure $itk_component(heading) 4 -weight 1
00266 grid columnconfigure $itk_component(heading) 5 -pad 5
00267 grid columnconfigure $itk_component(heading) 7 -weight 1
00268 grid columnconfigure $itk_component(heading) 8 -pad 5
00269
00270 grid $itk_component(experimentBoxLabel) -row 0 -column 0 -sticky ew -pady 2
00271 grid $itk_component(experimentBox) -row 0 -column 1 -sticky ew -pady 2 -columnspan 4
00272 grid $itk_component(totalScoreLabel) -row 1 -column 0 -sticky ew -pady 2
00273 grid $itk_component(totalScore) -row 1 -column 1 -sticky ew -pady 2
00274 grid $itk_component(noErrorsLabel) -row 2 -column 0 -sticky ew -pady 2
00275 grid $itk_component(noErrors) -row 2 -column 1 -sticky ew -pady 2
00276 grid $itk_component(noSolutionsLabel) -row 3 -column 0 -sticky ew -pady 2
00277 grid $itk_component(noSolutions) -row 3 -column 1 -sticky ew -pady 2
00278
00279 grid $itk_component(totalTimeLabel) -row 1 -column 3 -sticky ew -pady 2
00280 grid $itk_component(totalTime) -row 1 -column 4 -sticky ew -pady 2
00281 grid $itk_component(totalSolTimeLabel) -row 2 -column 3 -sticky ew -pady 2
00282 grid $itk_component(totalSolTime) -row 2 -column 4 -sticky ew -pady 2
00283 grid $itk_component(totalSoftTimeLabel) -row 3 -column 3 -sticky ew -pady 2
00284 grid $itk_component(totalSoftTime) -row 3 -column 4 -sticky ew -pady 2
00285
00286 grid $itk_component(totalStructRecallLabel) -row 0 -column 6 -sticky ew -pady 2
00287 grid $itk_component(totalStructRecall) -row 0 -column 7 -sticky ew -pady 2
00288 grid $itk_component(totalLabelledRecallLabel) -row 1 -column 6 -sticky ew -pady 2
00289 grid $itk_component(totalLabelledRecall) -row 1 -column 7 -sticky ew -pady 2
00290 grid $itk_component(totalLexicalRecallLabel) -row 2 -column 6 -sticky ew -pady 2
00291 grid $itk_component(totalLexicalRecall) -row 2 -column 7 -sticky ew -pady 2
00292 grid $itk_component(totalStrictRecallLabel) -row 3 -column 6 -sticky ew -pady 2
00293 grid $itk_component(totalStrictRecall) -row 3 -column 7 -sticky ew -pady 2
00294
00295 eval itk_initialize $args
00296 setModified
00297 #.main registerDocument $this => this part has been moved to
YadaMain::newDocument
00298 }
00299
00300
00301 ## ----------------------------------------------------------------------------
00302 ## activationHandle
00303 ## ----------------------------------------------------------------------------
00304 body
YadaRunner::activationHandle {} {
00305 chain ;# call
YadaRunnableDocument::activationHandle
00306
00307
# get the previous selection
00308
set box $itk_component(experimentBox)
00309 set experimentName [$box get]
00310
00311 # default experiments to choose
00312 if {$experimentName ==
""} {
00313 set experimentName
"<none>"
00314 }
00315
00316 set experimentNames [.main getActiveExperiments]
00317
00318 set listOfEntries [[$box component list] get 0 end]
00319
if {$listOfEntries != $experimentNames} {
00320 $box clear list
00321 eval $box insert list end $experimentNames
00322 selectExperiment $experimentName
00323 }
00324
00325
if { $hasView ==
"true" && [lastChanged] !=
"" } {
00326
if { [lastChanged] > $_lastModificationTime } {
00327
if { [askNewLoad] } {
00328 load
00329 }
else {
00330 setModified
00331 }
00332 }
00333 }
00334
00335 }
00336
00337
## ----------------------------------------------------------------------------
00338
## clear
00339
## ----------------------------------------------------------------------------
00340
body
YadaRunner::clear {} {
00341 chain ;# call
YadaRunnableDocument::clear
00342
00343
# reset the table
00344
set table $itk_component(table)
00345 $table setCell \
00346 0,0 "wordgraph" \
00347 0,1 "values" \
00348 0,2 "score" \
00349 0,3 "errors" \
00350 0,4 "time" \
00351 0,5 "sol.time" \
00352 0,6 "soft time" \
00353 0,7 "struct" \
00354 0,8 "labelled" \
00355 0,9 "lexical" \
00356 0,10 "strict"
00357
00358
00359 $table tag config default -anchor e
00360 $table tag config error -bg red3 -fg white -anchor e -relief flat
00361 $table tag config colored -bg gray80 -anchor e
00362
00363 $table tag config sel -fg "" -bg "" -relief raised -bd 1
00364 $table tag config active -anchor w -fg black -bg gray -relief sunk -bd 1
00365 $table tag config title -font {-adobe-helvetica-medium-r-normal--12-*-*-*-*-*-*-*} -bg #a3a3a3 -fg white
00366 $table tag config runner -fg red3 -bg #a3a3a3
00367 $table tag raise runner title
00368
00369 $table width 0 15 1 5 2 15 3 10 4 15 5 15 6 15 7 10 8 10 9 10 10 10
00370
00371
# reset scores of selected wordgraphs
00372
#_resetDataOf "[_getActiveWordgraphs]"
00373
00374 _computeStatistics
00375 }
00376
00377
00378
## ----------------------------------------------------------------------------
00379
## _analyseDocument
00380
## ----------------------------------------------------------------------------
00381
body
YadaRunner::_analyseDocument {document experiment} {
00382
00383 # default analysis
00384
YadaRunnableDocument::_analyseDocument $document $experiment
00385
00386
# the wordgraph is needed at least
00387
if {$_analyseResult(wordgraph) ==
""} {
00388 print
"ERROR: no information available in this run\n"
00389
return
00390 }
00391
00392
# save score and edge data
00393
set _scoreOf($_analyseResult(wordgraph)) $_analyseResult(score)
00394 set _structHitsOf($_analyseResult(wordgraph)) $_analyseResult(structHits)
00395 set _labelledHitsOf($_analyseResult(wordgraph)) $_analyseResult(labelledHits)
00396 set _lexicalHitsOf($_analyseResult(wordgraph)) $_analyseResult(lexicalHits)
00397 set _strictHitsOf($_analyseResult(wordgraph)) $_analyseResult(strictHits)
00398 set _triesOf($_analyseResult(wordgraph)) $_analyseResult(tries)
00399
00400 set structRecall [expr $_analyseResult(structHits) * 100.0 / $_analyseResult(tries)]
00401 set labelledRecall [expr $_analyseResult(labelledHits) * 100.0 / $_analyseResult(tries)]
00402 set lexicalRecall [expr $_analyseResult(lexicalHits) * 100.0 / $_analyseResult(tries)]
00403 set strictRecall [expr $_analyseResult(strictHits) * 100.0 / $_analyseResult(tries)]
00404
00405 # add the collected data to the table
00406 _insertData \
00407 $_analyseResult(wordgraph) \
00408 $_analyseResult(noValues) \
00409 [format "%4.3e" $_analyseResult(score)] \
00410 [expr $_analyseResult(tries) - $_analyseResult(lexicalHits)] \
00411 $_analyseResult(totalTime) \
00412 $_analyseResult(solutionTime) \
00413 $_analyseResult(softTime) \
00414 [format "%3.2f" $structRecall ] \
00415 [format "%3.2f" $labelledRecall ] \
00416 [format "%3.2f" $lexicalRecall ] \
00417 [format "%3.2f" $strictRecall ]
00418
00419 setModified
00420 }
00421
00422 ## ----------------------------------------------------------------------------
00423 ## _computeStatistics
00424 ## ----------------------------------------------------------------------------
00425 body
YadaRunner::_computeStatistics {} {
00426 chain
00427
00428 set table $itk_component(table)
00429 set rmax [$table cget -rows]
00430 set cmax [expr [$table cget -cols] -2]
00431
00432 set _totalWordgraphs 0
00433 set _totalScore 0
00434 set _noSolutions 0
00435 set _noErrors 0
00436 set _totalSolTime 0
00437 set _totalSoftTime 0
00438 set _totalTime 0
00439 set _totalStructRecall 0
00440 set _totalLabelledRecall 0
00441 set _totalLexicalRecall 0
00442 set _totalStrictRecall 0
00443
00444 set totalTries 0
00445 set totalStructHits 0
00446 set totalLabelledHits 0
00447 set totalLexicalHits 0
00448 set totalStrictHits 0
00449
00450 for {set row 1} {$row < $rmax} {incr row} {
00451
00452 set dataRow [$table getCell $row,0 $row,$cmax]
00453 set noValues [lindex $dataRow 1]
00454
if {$noValues ==
""} {
00455
continue
00456 }
00457
00458 set wordgraph [lindex $dataRow 0]
00459 set errors [lindex $dataRow 3]
00460 set time [lindex $dataRow 4]
00461 set solTime [lindex $dataRow 5]
00462 set softTime [lindex $dataRow 6]
00463
00464 incr _totalWordgraphs
00465 incr _totalTime $time
00466 incr _totalSolTime $solTime
00467 incr _totalSoftTime $softTime
00468 incr _noErrors $errors
00469
00470 set _totalScore [expr $_totalScore + $_scoreOf($wordgraph)]
00471
if {$_scoreOf($wordgraph) > 0.0} {
00472 incr _noSolutions
00473 }
00474
00475 incr totalTries $_triesOf($wordgraph)
00476 incr totalStructHits $_structHitsOf($wordgraph)
00477 incr totalLabelledHits $_labelledHitsOf($wordgraph)
00478 incr totalLexicalHits $_lexicalHitsOf($wordgraph)
00479 incr totalStrictHits $_strictHitsOf($wordgraph)
00480 }
00481
00482 if {$totalTries > 0} {
00483 set _totalStructRecall [expr $totalStructHits * 100.0 / $totalTries ]
00484 set _totalLabelledRecall [expr $totalLabelledHits * 100.0 / $totalTries ]
00485 set _totalLexicalRecall [expr $totalLexicalHits * 100.0 / $totalTries ]
00486 set _totalStrictRecall [expr $totalStrictHits * 100.0 / $totalTries ]
00487 }
00488
00489 _showStatistics
00490 }
00491
00492
## ----------------------------------------------------------------------------
00493
## _showStatistics
00494
## ----------------------------------------------------------------------------
00495
body
YadaRunner::_showStatistics {} {
00496 $itk_component(totalTime) configure -state normal
00497 $itk_component(totalSoftTime) configure -state normal
00498 $itk_component(totalSolTime) configure -state normal
00499 $itk_component(totalScore) configure -state normal
00500 $itk_component(totalStructRecall) configure -state normal
00501 $itk_component(totalLabelledRecall) configure -state normal
00502 $itk_component(totalLexicalRecall) configure -state normal
00503 $itk_component(totalStrictRecall) configure -state normal
00504
00505 $itk_component(totalTime) delete 0 end
00506 $itk_component(totalSolTime) delete 0 end
00507 $itk_component(totalSoftTime) delete 0 end
00508 $itk_component(totalScore) delete 0 end
00509 $itk_component(totalStructRecall) delete 0 end
00510 $itk_component(totalLabelledRecall) delete 0 end
00511 $itk_component(totalLexicalRecall) delete 0 end
00512 $itk_component(totalStrictRecall) delete 0 end
00513
00514 $itk_component(totalScore) insert 0 [format "%.4f" $_totalScore]
00515 $itk_component(totalTime) insert 0 "[timeToString $_totalTime]"
00516 $itk_component(totalSolTime) insert 0 "[timeToString $_totalSolTime]"
00517 $itk_component(totalSoftTime) insert 0 "[timeToString $_totalSoftTime]"
00518 $itk_component(totalStructRecall) insert 0 [format "%.4f%%" $_totalStructRecall]
00519 $itk_component(totalLabelledRecall) insert 0 [format "%.4f%%" $_totalLabelledRecall]
00520 $itk_component(totalLexicalRecall) insert 0 [format "%.4f%%" $_totalLexicalRecall]
00521 $itk_component(totalStrictRecall) insert 0 [format "%.4f%%" $_totalStrictRecall]
00522
00523 $itk_component(totalTime) configure -state disabled
00524 $itk_component(totalSolTime) configure -state disabled
00525 $itk_component(totalSoftTime) configure -state disabled
00526 $itk_component(totalScore) configure -state disabled
00527 $itk_component(totalStructRecall) configure -state disabled
00528 $itk_component(totalLabelledRecall) configure -state disabled
00529 $itk_component(totalLexicalRecall) configure -state disabled
00530 $itk_component(totalStrictRecall) configure -state disabled
00531 }
00532
00533 ## ----------------------------------------------------------------------------
00534 ## _judgeRow
00535 ## ----------------------------------------------------------------------------
00536 body
YadaRunner::_judgeRow {row} {
00537 set errors [$itk_component(table) getCell $row,3]
00538 set score [$itk_component(table) getCell $row,2]
00539 if {$errors > 0 || $score == 0.0} {
00540
return "error"
00541 }
else {
00542
if {[expr $row % 2]} {
00543
return "default"
00544 }
else {
00545
return "colored"
00546 }
00547 }
00548 }
00549
00550
## ----------------------------------------------------------------------------
00551
## _getTypeOfColumn
00552
## ----------------------------------------------------------------------------
00553
body
YadaRunner::_getTypeOfColumn {colNo} {
00554
return $_typeOfColumn($colNo)
00555 }
00556
00557
## ----------------------------------------------------------------------------
00558
## _resetDataOf
00559
## ----------------------------------------------------------------------------
00560
body YadaRunner::_resetDataOf {wordgraphs} {
00561 chain $wordgraphs
00562 foreach wordgraph $wordgraphs {
00563 set _scoreOf($wordgraph) 0.0
00564 set _triesOf($wordgraph) 0
00565 set _structHitsOf($wordgraph) 0
00566 set _labelledHitsOf($wordgraph) 0
00567 set _lexicalHitsOf($wordgraph) 0
00568 set _strictHitsOf($wordgraph) 0
00569 }
00570 }
00571
00572
## ----------------------------------------------------------------------------
00573
## Serializes Object into a DOM-XML-Node
00574
## @return root DOM node representing the Grammar-Object (root tag <yada>)
00575
## ----------------------------------------------------------------------------
00576
body
YadaRunner::toDOM {} {
00577 global env
00578
00579 set document [dom createDocument
"yada"]
00580 set root [$document documentElement]
00581
00582 set nodeRunner [$document createElement
"runner"]
00583
00584
00585 set experimentName [$itk_component(experimentBox) get]
00586
00587 set nodeConfig [$document createElement "config"]
00588 $nodeConfig setAttribute "name" $experimentName
00589 $nodeConfig setAttribute "xmlns:xlink" "http:
00590 $nodeConfig setAttribute "xlink:type" "simple"
00591 $nodeConfig setAttribute "xlink:href" [.main getPersistanceFileNameForExperiment $experimentName]
00592
00593 set nodeStats [$document createElement "stats"]
00594 $nodeStats setAttribute "score" $_totalScore
00595 $nodeStats setAttribute "numErrors" $_noErrors
00596 $nodeStats setAttribute "numSolutions" $_noSolutions
00597 $nodeStats setAttribute "time" $_totalTime
00598 $nodeStats setAttribute "solTime" $_totalSolTime
00599 $nodeStats setAttribute "softTime" $_totalSoftTime
00600 $nodeStats setAttribute "structRecall" $_totalStructRecall
00601 $nodeStats setAttribute "labelRecall" $_totalLabelledRecall
00602 $nodeStats setAttribute "lexicalRecall" $_totalLexicalRecall
00603 $nodeStats setAttribute "strictRecall" $_totalStrictRecall
00604
00605 $root appendChild $nodeRunner
00606 $nodeRunner appendChild $nodeConfig
00607 $nodeRunner appendChild $nodeStats
00608
00609 set table $itk_component(table)
00610
00611 set rmax [$table cget -rows]
00612 set cmax [expr [$table cget -cols] -2]
00613
00614
00615 for {set row 1} {$row < $rmax} {incr row} {
00616 set dataRow [$table getCell $row,0 $row,$cmax]
00617
if {[lindex $dataRow 2] ==
""} {
00618
continue
00619 }
00620
00621 set wordgraphName [lindex $dataRow 0]
00622
00623 set nodeWordgraph [$document createElement
"wordgraph"]
00624 $nodeWordgraph setAttribute
"name" $wordgraphName
00625 $nodeWordgraph setAttribute
"values" [lindex $dataRow 1]
00626 $nodeWordgraph setAttribute
"score" [lindex $dataRow 2]
00627 $nodeWordgraph setAttribute
"errors" [lindex $dataRow 3]
00628 $nodeWordgraph setAttribute
"time" [lindex $dataRow 4]
00629 $nodeWordgraph setAttribute
"solTime" [lindex $dataRow 5]
00630 $nodeWordgraph setAttribute
"softTime" [lindex $dataRow 6]
00631 $nodeWordgraph setAttribute
"structRecall" [lindex $dataRow 7]
00632 $nodeWordgraph setAttribute
"labelRecall" [lindex $dataRow 8]
00633 $nodeWordgraph setAttribute
"lexicalRecall" [lindex $dataRow 9]
00634 $nodeWordgraph setAttribute
"strictRecall" [lindex $dataRow 10]
00635
00636 $nodeWordgraph setAttribute
"structHits" $_structHitsOf($wordgraphName)
00637 $nodeWordgraph setAttribute "labelledHits" $_labelledHitsOf($wordgraphName)
00638 $nodeWordgraph setAttribute "lexicalHits" $_lexicalHitsOf($wordgraphName)
00639 $nodeWordgraph setAttribute "strictHits" $_strictHitsOf($wordgraphName)
00640 $nodeWordgraph setAttribute "tries" $_triesOf($wordgraphName)
00641
00642 $nodeRunner appendChild $nodeWordgraph
00643
00644 }
00645
00646 return $root
00647
00648 }
00649
00650
00651
00652 ## ----------------------------------------------------------------------------
00653 ## Initialize Object with DOM node (that has saved the object state)
00654 ## @param rootNode root DOM-Node (Tag <yada>)
00655 ## ----------------------------------------------------------------------------
00656 body
YadaRunner::fromDOM { rootNode } {
00657 clear
00658
00659
## handles case, when no XML file is available
00660
if { $rootNode ==
"" } {
00661
#puts "*** Reevaluate runner [$selectedExperiment cget -name] ***"
00662
loadUpdatedWordgraphs
00663 _computeStatistics
00664 setModified
00665
return
00666 }
00667
00668
00669 set xpath
"/yada/runner"
00670
00671 set nodesWordgraph [$rootNode selectNodes $xpath/wordgraph]
00672 set someWordgraphsUpdated
""
00673
00674
## list of wordgraph names that must not be loaded from xml document file
00675
set updatedWordgraphs [_getUpdatedWordgraphNames]
00676 set activeWordgraphs [_getActiveWordgraphs]
00677
00678
00679
## if there is no selection, all wordgraphs are active
00680
if { $activeWordgraphs ==
"" } {
00681 set activeWordgraphs [_getWordgraphs]
00682 }
00683
00684
00685
## if wordgraph is marked and not in the document file, try to load it from separate wordgraph file
00686
set unsavedWordgraphs {}; ## list of marked wordgraphs, that are not saved in the DOM node
00687 foreach activeWordgraph $activeWordgraphs {
00688 set nodeActiveWordgraph [$rootNode find name $activeWordgraph]
00689
00690
if { $nodeActiveWordgraph ==
"" } {
00691 lappend unsavedWordgraphs $activeWordgraph
00692 }
00693 }
00694
00695
## determine wordgraphs that can be loaded from a file
00696
set wordgraphsWithExistantFiles {}; ## list of wordgraphs, that are not in the DOM node, but there exists some alternative wordgraph XML file to load from
00697 foreach wordgraph $unsavedWordgraphs {
00698 set fileName [$selectedExperiment getXmlFileName $wordgraph]
00699
00700
if {[file exists $fileName]} {
00701 lappend wordgraphsWithExistantFiles $wordgraph
00702 }
00703 }
00704
00705
00706
## try to load active wordgraphs from <wordgraph-id>.xml.gz
00707
if { [llength $wordgraphsWithExistantFiles] > 0 } {
00708
#puts "Load updated files '$wordgraphsWithExistantFiles', '$unsavedWordgraphs'"
00709
eval loadUpdatedWordgraphs $wordgraphsWithExistantFiles
00710 }
00711
00712
00713
00714
#puts "Active Wordgraphs: $activeWordgraphs"
00715
00716 foreach node $nodesWordgraph {
00717 set wordgraph [$node getAttribute
"name"]
00718
#puts "Handle Wordgraph $wordgraph"
00719
00720
## only load wordgraphs from the document file, if there is no updated wordgraph xml file
00721
## and if it is also active
00722
if { [lsearch -exact $updatedWordgraphs $wordgraph] != -1 && [lsearch -exact $activeWordgraphs $wordgraph] != -1} {
00723 print
"INFO: Wordgraph $wordgraph has been updated...need to load from `[_getXMLFileName $wordgraph]'\n"
00724 set someWordgraphsUpdated
"true"
00725
continue
00726 }
00727
00728
## Do not load from document file if it is not active
00729
if { [lsearch -exact $activeWordgraphs $wordgraph] == -1 } {
00730
continue
00731 }
00732
00733 print
"INFO: Load Wordgraph $wordgraph from document file `[getPersistanceFileName]'\n"
00734
00735 set values [$node getAttribute
"values"]
00736 set score [$node getAttribute
"score"]
00737 set errors [$node getAttribute
"errors"]
00738 set time [$node getAttribute
"time"]
00739 set solTime [$node getAttribute
"solTime"]
00740 set softTime [$node getAttribute
"softTime"]
00741 set structRecall [$node getAttribute
"structRecall"]
00742 set labelRecall [$node getAttribute
"labelRecall"]
00743 set lexicalRecall [$node getAttribute
"lexicalRecall"]
00744 set strictRecall [$node getAttribute
"strictRecall"]
00745
00746 set _scoreOf($wordgraph) $score
00747 set _structHitsOf($wordgraph) [$node getAttribute "structHits"]
00748 set _labelledHitsOf($wordgraph) [$node getAttribute "labelledHits"]
00749 set _lexicalHitsOf($wordgraph) [$node getAttribute "lexicalHits"]
00750 set _strictHitsOf($wordgraph) [$node getAttribute "strictHits"]
00751 set _triesOf($wordgraph) [$node getAttribute "tries"]
00752
00753 _insertData $wordgraph\
00754 $values\
00755 $score\
00756 $errors\
00757 $time\
00758 $solTime\
00759 $softTime\
00760 $structRecall\
00761 $labelRecall\
00762 $lexicalRecall\
00763 $strictRecall
00764
00765 }
00766
00767 if { [_isModified $rootNode] ==
"false"} {
00768 set nodeStats [$rootNode selectNodes $xpath/stats]
00769 set _totalScore [$nodeStats getAttribute
"score"]
00770 set _noErrors [$nodeStats getAttribute
"numErrors"]
00771 set _noSolutions [$nodeStats getAttribute
"numSolutions"]
00772 set _totalTime [$nodeStats getAttribute
"time"]
00773 set _totalSolTime [$nodeStats getAttribute
"solTime"]
00774 set _totalSoftTime [$nodeStats getAttribute
"softTime"]
00775 set _totalStructRecall [$nodeStats getAttribute
"structRecall"]
00776 set _totalLabelledRecall [$nodeStats getAttribute
"labelRecall"]
00777 set _totalLexicalRecall [$nodeStats getAttribute
"lexicalRecall"]
00778 set _totalStrictRecall [$nodeStats getAttribute
"strictRecall"]
00779 }
00780
00781
## load updated wordgraph xml files instead of corresponding document file's entries
00782
if { $someWordgraphsUpdated !=
"" } {
00783
#puts "Wordgraphs updated: $updatedWordgraphs"
00784
eval loadUpdatedWordgraphs $updatedWordgraphs
00785 }
00786
00787
## if only a subset of wordgraphs has been loaded from the document file,
00788
## you need to recompute statistics
00789
if { [_isModified $rootNode]==
"true" } {
00790 _computeStatistics
00791 print
"INFO: Need to recompute statistics\n"
00792 setModified
00793 }
else {
00794
## use saved statistics from document
00795
print
"INFO: Load statistics from document file `[getPersistanceFileName]'\n"
00796 _showStatistics
00797 resetModified
00798 }
00799 }
00800
00801
00802
00803
#body YadaRunner::save {{fileName ""}} {
00804
# YadaPlainDocument::save
00805
# set experimentName [$itk_component(experimentBox) get]
00806
# set experiment [.main getExperiment $experimentName]
00807
00808
#if {0} {
00809
00810
# if {$fileName == "" } {
00811
# set fileName [.fileSelector activate \
00812
# -title "Select a file" \
00813
# -width 500 \
00814
# -height 400 \
00815
# -filter {"*.html"} \
00816
# -mode "singlefile" \
00817
# ]
00818
# if {$fileName == ""} {
00819
# return
00820
# }
00821
# }
00822
00823
# set fileId [open $fileName w]
00824
# puts $fileId [_toHtml]
00825
# close $fileId
00826
#} else {
00827
# puts [_toHtml]
00828
#}
00829
#
00830
#}
00831
00832
## ----------------------------------------------------------------------------
00833
## toHtml
00834
## ----------------------------------------------------------------------------
00835
body
YadaRunner::_toHtml {} {
00836 set experimentName [$itk_component(experimentBox) get]
00837 set table $itk_component(table)
00838 set titles [$table getCell 0,0 0,9]
00839 set cmax [expr [$table cget -cols] -2]
00840 set rmax [$table cget -rows]
00841
00842 # head
00843 append result \
00844 "<!DOCTYPE html PUBLIC \"-
00845 "<html xmlns=\"http:
00846 "<head>\n" \
00847 " <title>
YadaRunner $experimentName</title>\n" \
00848 "</head>\n" \
00849 "<body>\n"
00850
00851 # summary table
00852 append result \
00853 "<!-- begin summary table -->\n" \
00854 "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n" \
00855 "<tr>\n"
00856
00857 append result "<td width=\"33%\"><table class=\"yadaTable\" >\n"
00858 append result " <tr><td class=\"yadaHeader\" align=\"left\">Experiment:</td><td class=\"yadaCell\">$experimentName</td></tr>\n"
00859 append result " <tr><td class=\"yadaHeader\" align=\"left\">Score: </td><td class=\"yadaCell\">$_totalScore</td></tr>\n"
00860 append result " <tr><td class=\"yadaHeader\" align=\"left\">No.Solutions: </td><td class=\"yadaCell\">$_noSolutions</td></tr>\n"
00861 append result "</table></td>\n"
00862 append result "<td width=\"33%\"><table>\n"
00863 append result " <tr><td class=\"yadaHeader\" align=\"left\">Time: </td><td class=\"yadaCell\">$_totalTime</td></tr>\n"
00864 append result " <tr><td class=\"yadaHeader\" align=\"left\">Sol.Time: </td><td class=\"yadaCell\">$_totalSolTime</td></tr>\n"
00865 append result " <tr><td class=\"yadaHeader\" align=\"left\">Soft.Time: </td><td class=\"yadaCell\">$_totalSoftTime</td></tr>\n"
00866 append result "</table></td>\n"
00867 append result "<td width=\"33%\"><table>\n"
00868 append result " <tr><td class=\"yadaHeader\" align=\"left\">StructRecall: </td><td class=\"yadaCell\">$_totalStructRecall</td></tr>\n"
00869 append result " <tr><td class=\"yadaHeader\" align=\"left\">LexicalRecall: </td><td class=\"yadaCell\">$_totalLexicalRecall</td></tr>\n"
00870 append result " <tr><td class=\"yadaHeader\" align=\"left\">StrictRecall: </td><td class=\"yadaCell\">$_totalStrictRecall</td></tr>\n"
00871 append result "</table></td>\n"
00872
00873 # close summary table
00874 append result \
00875 "</tr>\n" \
00876 "</table>\n" \
00877 "<!-- end summary table -->\n"
00878
00879 # data title row
00880 append result \
00881 "<!-- begin data table -->\n" \
00882 "<table class=\"yadaTable\" width=\"100%\" border=\"0\">\n" \
00883 "<tr>\n"
00884
00885 foreach title $titles {
00886 append result
" <th class=\"yadaHeader\" align=\"left\">$title</th>\n"
00887 }
00888 append result
"</tr>\n"
00889
00890
# date rows
00891
for {set row 1} {$row < $rmax} {incr row} {
00892 set dataRow [$table getCell $row,0 $row,$cmax]
00893
if {[lindex $dataRow 2] ==
""} {
00894
continue
00895 }
00896 set isFirst 1
00897 append result
"<tr>\n"
00898 foreach cellItem $dataRow {
00899
if {$isFirst} {
00900 set isFirst 0
00901 append result
"<td class=\"yadaHeader\"><code>$cellItem</code></td>\n"
00902 }
else {
00903 append result
"<td class=\"yadaCell\"><code>$cellItem</code></td>\n"
00904 }
00905 }
00906 append result
"</tr>\n"
00907 }
00908
00909
# close data table
00910
append result \
00911
"</tr>\n" \
00912
"</table>\n" \
00913
"<!-- end data table -->\n" \
00914
00915
# tail
00916
append result \
00917
"</body>\n" \
00918
"</html>\n"
00919
00920
return $result
00921 }
00922
00923
00924
## ----------------------------------------------------------------------------
00925
## Gets unique file name from YadaMain application object to save object state
00926
## ----------------------------------------------------------------------------
00927
body
YadaRunner::getPersistanceFileName {} {
00928 set experimentName
""
00929
00930
## may fail, if gui is not fully initialized
00931
catch {set experimentName [$selectedExperiment cget -name]}
00932
00933
return [.main getPersistanceFileNameForRunner $experimentName]
00934 }
00935
00936
00937
## ----------------------------------------------------------------------------
00938
## Update toolbar, menubar and titlebar
00939
## ----------------------------------------------------------------------------
00940
body
YadaRunner::displayTitle {} {
00941
00942 ## Do not display, if runner document invisible
00943
if { $hasView ==
"false" } {
00944
return
00945 }
00946
00947
if { ![
catch {set experimentName [[_getSelectedExperiment] cget -name]}] } {
00948 set title
"$name-$experimentName"
00949 }
else {
00950 set title
"$name"
00951 }
00952
00953
if { [isModified] && $name !=
"<none>" } {
00954 wm title .
"$title *** changed *** "
00955 }
else {
00956 wm title .
"$title"
00957 }
00958
00959 set loadButton [$itk_component(toolbar) component loadButton]
00960 set saveButton [$itk_component(toolbar) component saveButton]
00961
00962 if { [hasSavedState] } {
00963 $itk_component(fileMenu) entryconfigure 0 -state normal
00964 $loadButton configure -state normal
00965 } else {
00966 $itk_component(fileMenu) entryconfigure 0 -state disabled
00967 $loadButton configure -state disabled
00968 }
00969
00970 if { [isModified] && [string compare $name
"<none>"] != 0 } {
00971 $itk_component(fileMenu) entryconfigure 1 -state normal
00972 $saveButton configure -state normal
00973 } else {
00974 $itk_component(fileMenu) entryconfigure 1 -state disabled
00975 $saveButton configure -state disabled
00976 }
00977 }
00978
00979
00980 ## ----------------------------------------------------------------------------
00981 ## Returns a list of selected wordgraphs that are not in the xml document
00982 ## in their most recent state and have to be loaded from wordgraph xml file;
00983 ## a wordgraph is in the list, if there exists some corresponding wordgraph xml file
00984 ## and it is newer than the document xml file
00985 ## ----------------------------------------------------------------------------
00986 body
YadaRunner::_getUpdatedWordgraphNames {} {
00987
00988 ## for invisible runner objects, selected experiment has to be set by configure command
00989
if { $hasView ==
"true" } {
00990 set selectedExperiment [_getSelectedExperiment]
00991 }
00992
00993 set activeWordgraphs [_getActiveWordgraphs]
00994
00995 set modifiedWordgraphs {}
00996
00997
if {$selectedExperiment ==
""} {
00998
return ""
00999 }
01000
01001
if {$activeWordgraphs ==
""} {
01002 set activeWordgraphs [_getWordgraphs]
01003 }
01004
01005 set documentFileName [getPersistanceFileName].gz
01006
01007 foreach wordgraph $activeWordgraphs {
01008 set wordgraphFileName [$selectedExperiment getXmlFileName $wordgraph]
01009 file stat $documentFileName statDocumentFile
01010
01011
01012
if { [
catch {file stat $wordgraphFileName statWordgraphFile}] } {
01013
continue
01014 }
01015
01016
if { [expr { $statDocumentFile(ctime) < $statWordgraphFile(ctime) }] } {
01017 lappend modifiedWordgraphs $wordgraph
01018 }
01019 }
01020
return $modifiedWordgraphs
01021
01022 }
01023
01024
## ----------------------------------------------------------------------------
01025
## Returns list of wordgraph names saved in the runner document xml file
01026
## @param rootNode root domNode of document's xml file
01027
## ----------------------------------------------------------------------------
01028
body
YadaRunner::_getSavedWordgraphNames { rootNode } {
01029 set xpath
"/yada/runner"
01030 set nodesWordgraph [$rootNode selectNodes $xpath/wordgraph]
01031
01032 set listOfNames {}
01033 foreach node $nodesWordgraph {
01034 lappend listOfNames [$node getAttribute
"name"]
01035 }
01036
01037
return $listOfNames
01038
01039 }
01040
01041
01042
## ----------------------------------------------------------------------------
01043
## Returns true, if document file is not synchronized with actual document,
01044
## false otherwise
01045
## @param rootNode root domNode of document's xml file
01046
## ----------------------------------------------------------------------------
01047
body
YadaRunner::_isModified {rootNode} {
01048 set savedWordgraphNames [_getSavedWordgraphNames $rootNode]
01049 set loadedWordgraphNames [_getLoadedWordgraphNames]
01050
01051 foreach wordgraph $savedWordgraphNames {
01052
if { [lsearch -exact $loadedWordgraphNames $wordgraph] == -1 } {
01053
return "true"
01054 }
01055 }
01056
01057 foreach loadedWordgraph $loadedWordgraphNames {
01058
if { [lsearch -exact $savedWordgraphNames $loadedWordgraph] == -1} {
01059
return "true"
01060 }
01061 }
01062
return "false"
01063 }
01064
01065
## ----------------------------------------------------------------------------
01066
## Gets all loaded wordgraphs (i.e. the wordgraphs that appear in the
01067
## document's table)
01068
## @return list of currently loaded wordgraphs
01069
## ----------------------------------------------------------------------------
01070
body
YadaRunner::_getLoadedWordgraphNames {} {
01071 set table $itk_component(table)
01072 set rmax [$table cget -rows]
01073 set cmax [expr [$table cget -cols] -2]
01074
01075 set loadedWordgraphNames {}
01076
01077
for {set row 1} {$row < $rmax} {incr row} {
01078
01079 set dataRow [$table getCell $row,0 $row,$cmax]
01080 set noValues [lindex $dataRow 1]
01081
if {$noValues ==
""} {
01082
continue
01083 }
else {
01084 lappend loadedWordgraphNames [lindex $dataRow 0]
01085 }
01086 }
01087
01088
return $loadedWordgraphNames
01089 }
01090
01091
## ----------------------------------------------------------------------------
01092
## Override base class implementation
01093
## ----------------------------------------------------------------------------
01094
body
YadaRunner::reload {} {
01095 load
01096 }
01097
01098
## ----------------------------------------------------------------------------
01099
## Returns value of private attribute
01100
## ----------------------------------------------------------------------------
01101
body YadaRunner::getTotalTime {} {
01102
return $_totalTime
01103 }
01104
01105
## ----------------------------------------------------------------------------
01106
## Returns value of private attribute
01107
## ----------------------------------------------------------------------------
01108
body YadaRunner::getTotalSolTime {} {
01109
return $_totalSolTime
01110 }
01111
01112
## ----------------------------------------------------------------------------
01113
## Returns value of private attribute
01114
## ----------------------------------------------------------------------------
01115
body YadaRunner::getTotalSoftTime {} {
01116
return $_totalSoftTime
01117 }
01118
01119
## ----------------------------------------------------------------------------
01120
## Returns value of private attribute
01121
## ----------------------------------------------------------------------------
01122
body YadaRunner::getTotalStructRecall {} {
01123
return $_totalStructRecall
01124 }
01125
01126
01127
## ----------------------------------------------------------------------------
01128
## Returns value of private attribute
01129
## ----------------------------------------------------------------------------
01130
body YadaRunner::getTotalLabelRecall {} {
01131
return $_totalLabelledRecall
01132 }
01133
01134
01135
## ----------------------------------------------------------------------------
01136
## Returns value of private attribute
01137
## ----------------------------------------------------------------------------
01138
body YadaRunner::getTotalLexRecall {} {
01139
return $_totalLexicalRecall
01140 }
01141
01142
## ----------------------------------------------------------------------------
01143
## Returns value of private attribute
01144
## ----------------------------------------------------------------------------
01145
body YadaRunner::getTotalScore {} {
01146
return $_totalScore
01147 }
01148
01149
## ----------------------------------------------------------------------------
01150
## Overridden to handle missing file to load from
01151
## ----------------------------------------------------------------------------
01152
body YadaRunner::load {} {
01153
if { $hasView ==
"true" } {
01154 set oldCursors [
setBusy]
01155 }
01156
01157 set zippedFileName [getPersistanceFileName].gz
01158
if { ![file exists $zippedFileName]} {
01159
if { $hasView ==
"true" } {
01160
resetBusy $oldCursors
01161
#error "File $zippedFileName not found."
01162
}
else {
01163 fromDOM
""
01164
return
01165 }
01166 fromDOM
""
01167
return
01168 }
01169 set fileID [open
"|zcat $zippedFileName" {RDONLY}]
01170
01171
## save change date of document file, may be overridden in method fromDOM,
01172
## if it loads more recent data from other files
01173
file stat $zippedFileName persistantStateFileAttribs
01174
01175 set xmlData [read $fileID]
01176 close $fileID
01177 set document [dom parse $xmlData]
01178 resetModified
01179
## Modified state may be changed by overridden fromDOM methods
01180
fromDOM [$document documentElement]
01181
01182
if { $hasView ==
"true"} {
01183
resetBusy $oldCursors
01184 displayTitle
01185 }
01186
01187 updateModificationTime
01188 }
01189
01190
01191
01192
01193
01194