Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

YadaExperiment.tcl

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 ## YadaExperiment - bundled information about a experiment. 00013 ## A YadaExperiment is the central object of the YADA application. It brings 00014 ## together all the parts that are needed to start YadaJob objects forking the parser 00015 ## process in the background and consuming the produced data. 00016 ## 00017 ## So a YadaExperiment 00018 ## - has a unique name, 00019 ## - needs a YadaGrammar, 00020 ## - needs a command to fork the parser 00021 ## - specifies a YadaMachine where all jobs are started on, 00022 ## - a script to be played to the parser itself and 00023 ## - a unique data directory where the results of the experiments are stored 00024 ## (two files per wordgraph: the standard output and the xml output data) 00025 ## 00026 ## All YadaExperiment objects are accessed via the YadaExperiments configuration 00027 ## document. YadaGrammars and YadaMachines that are available are configured separately. 00028 ## 00029 ## \ingroup YadaConfiguration 00030 ## \ingroup YadaScheduler 00031 ## 00032 ## \author Michael Daum 00033 ## 00034 ## $Id: YadaExperiment.tcl,v 1.11 2004/10/15 17:24:37 micha Exp $ 00035 ## ---------------------------------------------------------------------------- 00036 class YadaExperiment { 00037 inherit YadaConfigItem 00038 00039 # variables ---------------------------------------------------------------- 00040 00041 ## the name of the experiment 00042 #public variable name "" 00043 00044 ## the type of the experiment. 00045 ## The type of the experiment specifies the parsing flavour used. 00046 ## Possible sensefull values by now are 00047 ## - annotation (which is actually now parsing flavour but a way to compute 00048 ## parses via anno2parse()) 00049 ## - arcconsistency 00050 ## - frobbing 00051 ## - genetic 00052 ## - gls 00053 ## - incremental completion 00054 ## - isearch 00055 ## - netsearch 00056 ## - pruning 00057 ## - wfst 00058 public variable type "" 00059 00060 ## path to cdgp binary file 00061 public variable command "" 00062 00063 ## path where to store all computed data files 00064 public variable dataDir "" 00065 00066 ## YadaGrammar to appy this experiment. 00067 public variable grammarName "" 00068 00069 ## YadaMachine where to schedule resulting YadaJobs on. 00070 public variable machineName "localhost" 00071 00072 ## CDGP script to feed into the STDIN of a CdgProcess. 00073 public variable script "" 00074 00075 ## flag indicating whether this experiment is currently waiting for 00076 ## a YadaJob to finish. 00077 public variable isActive 1 00078 00079 ## flag indicating whether all data has been computed for this 00080 ## experiment, so no more YadaJobs are needed. 00081 public variable isComplete 0 00082 00083 ## flag indicating whether all statistics in all data has been 00084 ## collected or not. 00085 public variable isUpToDate 0 00086 00087 ## tcl command used to print a message. 00088 ## \see print() 00089 public variable printCommand "" 00090 00091 ## total scores collected in the experiments data files. 00092 public variable totalScore 0 00093 00094 ## labelled hits collected in the experiments data files. 00095 public variable labelledHits 0 00096 00097 ## strict hits collected in the experiments data files. 00098 public variable strictHits 0 00099 00100 ## lexical hits collected in the experiments data files. 00101 public variable lexicalHits 0 00102 00103 ## struct hits collected in the experiments data files. 00104 public variable structHits 0 00105 00106 ## total number of tries collected in the experiments data files. 00107 public variable totalTries 0 00108 00109 ## total time collected in the experiments data files. 00110 public variable totalTime 0 00111 00112 ## total solution time collected in the experiments data files. 00113 public variable totalSolTime 0 00114 00115 ## total soft time collected in the experiments data files. 00116 public variable totalSoftTime 0 00117 00118 # methods ------------------------------------------------------------------ 00119 public method clone {args}; ## \type TclList 00120 public method check {} 00121 public method start {job}; ## \type YadaJob 00122 public method print {message}; ## \type TclString 00123 public method resetStatistics {} 00124 public method getXmlFileName {wgName}; ## \type TclString 00125 public method getLogFileName {wgName}; ## \type TclString 00126 public method getDocFileName {} 00127 public method getPersistanceFileName {} ; ## overriding virtual method 00128 00129 00130 public method toDOM {} 00131 public method fromDOM {rootNode}; ## \type domNode 00132 00133 constructor {args} {}; ## \type TclList 00134 00135 }; 00136 00137 body YadaExperiment::toDOM {} { 00138 global env 00139 set document [dom createDocument "yada"] 00140 set root [$document documentElement] 00141 00142 set nodeConfigDoc [$document createElement "experiment"] 00143 00144 $nodeConfigDoc setAttribute "name" $name 00145 00146 $nodeConfigDoc setAttribute "type" $type 00147 00148 $nodeConfigDoc setAttribute "command" $command 00149 00150 $nodeConfigDoc setAttribute "dataDir" $dataDir 00151 00152 if { $isActive == 1 } { 00153 $nodeConfigDoc setAttribute "isActive" true 00154 } else { 00155 $nodeConfigDoc setAttribute "isActive" false 00156 } 00157 00158 00159 set nodeGrammar [$document createElement "grammarRef"] 00160 $nodeGrammar setAttribute "name" $grammarName 00161 $nodeGrammar setAttribute "xmlns:xlink" "http://www.w3.org/1999/xlink" 00162 $nodeGrammar setAttribute "xlink:type" "simple" 00163 $nodeGrammar setAttribute "xlink:href" [file join $env(YADA_DATA) ${grammarName}_grammarconfig.xml].gz 00164 00165 set nodeMachine [$document createElement "machineRef"] 00166 $nodeMachine setAttribute "name" $machineName 00167 $nodeMachine setAttribute "xmlns:xlink" "http://www.w3.org/1999/xlink" 00168 $nodeMachine setAttribute "xlink:type" "simple" 00169 $nodeMachine setAttribute "xlink:href" [file join $env(YADA_DATA) ${machineName}_machineconfig.xml].gz 00170 00171 set nodeScript [$document createElement "script"] 00172 00173 set nodeScriptText [$document createTextNode $script] 00174 00175 $root appendChild $nodeConfigDoc 00176 $nodeConfigDoc appendChild $nodeGrammar 00177 $nodeConfigDoc appendChild $nodeMachine 00178 $nodeConfigDoc appendChild $nodeScript 00179 $nodeScript appendChild $nodeScriptText 00180 00181 return $root 00182 } 00183 00184 00185 body YadaExperiment::fromDOM {rootNode} { 00186 set xpath "/yada/experiment" 00187 00188 set nodeExperiment [$rootNode selectNodes $xpath] 00189 set name [$nodeExperiment getAttribute "name"] 00190 00191 set type [$nodeExperiment getAttribute "type"] 00192 00193 set command [$nodeExperiment getAttribute "command"] 00194 00195 set dataDir [$nodeExperiment getAttribute "dataDir"] 00196 00197 set nodeGrammar [$rootNode selectNodes ${xpath}/grammarRef] 00198 set grammarName [$nodeGrammar getAttribute "name"] 00199 00200 set nodeMachine [$rootNode selectNodes ${xpath}/machineRef] 00201 set machineName [$nodeMachine getAttribute "name"] 00202 00203 set nodeScript [$rootNode selectNodes ${xpath}/script] 00204 set script [$nodeScript text] 00205 00206 00207 set attribActive [$nodeExperiment getAttribute "isActive"] 00208 00209 00210 if { [string compare $attribActive true] == 0} { 00211 set isActive 1 00212 } else { 00213 set isActive 0 00214 } 00215 00216 } 00217 00218 ## ---------------------------------------------------------------------------- 00219 ## constructor 00220 ## ---------------------------------------------------------------------------- 00221 body YadaExperiment::constructor {args} { 00222 global env 00223 eval configure $args 00224 00225 setModified 00226 00227 # check obliatory options 00228 if {"$name" == ""} { 00229 error "ERROR: unnamed experiment" 00230 } 00231 if {"$type" == ""} { 00232 error "ERROR: experiment $name untyped" 00233 } 00234 if {"$grammarName" == ""} { 00235 error "ERROR: experiment $name w/o grammar" 00236 } 00237 if {"$command" == ""} { 00238 error "ERROR: experiment $name has no command" 00239 } 00240 00241 # create default data store in 00242 # YADA_DATA/machineName/grammarName/type/name 00243 if {"$dataDir" == ""} { 00244 set dataDir [file join $::env(YADA_DATA) $machineName $grammarName $type $name] 00245 } 00246 00247 # security filter for dataDir 00248 if {$name != "<none>"} { 00249 set securityFilter {[\\\*\?\~\^\$\@\%\`\"\'\&\;\|<>\x00-\x1F]} ;# from twiki 00250 regsub -all $securityFilter $dataDir "" dataDir 00251 } 00252 00253 # check if the named experiment already exists 00254 foreach experiment [itcl_info object -class YadaExperiment] { 00255 if {$experiment == $this} { 00256 continue 00257 } 00258 if {[$experiment cget -name] == $name} { 00259 error "ERROR: experiment $name already exists" 00260 } 00261 if {[$experiment cget -dataDir] == $dataDir} { 00262 error "ERROR: experiment $name uses same store" 00263 } 00264 } 00265 00266 # create data store 00267 if {$name != "<none>" && ![file exists "$dataDir"]} { 00268 file mkdir "$dataDir" 00269 set isComplete 0 00270 } 00271 } 00272 00273 ## ---------------------------------------------------------------------------- 00274 ## clone 00275 ## ---------------------------------------------------------------------------- 00276 body YadaExperiment::clone {args} { 00277 set newExperiment [YadaExperiment ::#auto \ 00278 -name $name \ 00279 -type $type \ 00280 -command $command \ 00281 -dataDir $dataDir \ 00282 -grammarName $grammarName \ 00283 -machineName $machineName \ 00284 -script $script \ 00285 -isActive $isActive 00286 ] 00287 00288 eval $newExperiment configure $args 00289 00290 return $newExperiment 00291 } 00292 00293 ## ---------------------------------------------------------------------------- 00294 ## check 00295 ## ---------------------------------------------------------------------------- 00296 body YadaExperiment::check {} { 00297 00298 if {$name == "<none>"} { 00299 return 1 00300 } 00301 00302 if {$dataDir == "" || $grammarName == ""} { 00303 puts "Data-Dir or grammar not defined" 00304 return 0 00305 } 00306 00307 # check if the experiment is complete 00308 if {!$isComplete} { 00309 set grammar [.main getGrammar $grammarName] 00310 set wordgraphs [$grammar getSelection] 00311 set isComplete 1 00312 foreach wordgraph $wordgraphs { 00313 set file [getXmlFileName $wordgraph] 00314 if {![file exists $file]} { 00315 set isComplete 0 00316 break 00317 } 00318 } 00319 } 00320 00321 return $isComplete 00322 } 00323 00324 ## ---------------------------------------------------------------------------- 00325 ## start 00326 ## ---------------------------------------------------------------------------- 00327 body YadaExperiment::start {job} { 00328 set wordgraph [$job cget -wordgraphName] 00329 set grammar [.main getGrammar $grammarName] 00330 set process [$job cget -process] 00331 if {$process == ""} { 00332 error "ERROR: experiment cannot be applied to an unstarted job" 00333 } 00334 00335 # replace makros in the script 00336 set tmpScript $script 00337 foreach file [$grammar cget -files] { 00338 regsub -all -- "%load" $tmpScript "load $file\n%load" tmpScript 00339 } 00340 regsub -all -- "%load" $tmpScript "" tmpScript 00341 regsub -all -- "%wordgraph" $tmpScript $wordgraph tmpScript 00342 regsub -all -- "%path" $tmpScript $dataDir tmpScript 00343 00344 # start the script 00345 $process tell "$tmpScript\nquit\n" 00346 } 00347 00348 ## ---------------------------------------------------------------------------- 00349 ## print 00350 ## ---------------------------------------------------------------------------- 00351 body YadaExperiment::print {message} { 00352 if {$printCommand != ""} { 00353 $printCommand $message 00354 } 00355 } 00356 00357 ## ---------------------------------------------------------------------------- 00358 ## getXmlFileName 00359 ## ---------------------------------------------------------------------------- 00360 body YadaExperiment::getXmlFileName {wgName} { 00361 return [file join $dataDir ${wgName}.xml.gz] 00362 } 00363 00364 ## ---------------------------------------------------------------------------- 00365 ## getLogFileName 00366 ## ---------------------------------------------------------------------------- 00367 body YadaExperiment::getLogFileName {wgName} { 00368 return [file join $dataDir ${wgName}.log.gz] 00369 } 00370 00371 ## ---------------------------------------------------------------------------- 00372 ## getDocFileName 00373 ## ---------------------------------------------------------------------------- 00374 body YadaExperiment::getDocFileName {} { 00375 return [file join $dataDir yada.xml] 00376 } 00377 00378 ## ---------------------------------------------------------------------------- 00379 ## resetStatistics 00380 ## ---------------------------------------------------------------------------- 00381 body YadaExperiment::resetStatistics {} { 00382 set totalScore 0 00383 set labelledHits 0 00384 set structHits 0 00385 set lexicalHits 0 00386 set strictHits 0 00387 set totalTries 0 00388 set totalTime 0 00389 set totalSolTime 0 00390 set totalSoftTime 0 00391 set noSolutions 0 00392 set isUpToDate 0 00393 } 00394 00395 ## ---------------------------------------------------------------------------- 00396 ## callback for script. 00397 ## ---------------------------------------------------------------------------- 00398 configbody YadaExperiment::script { 00399 regsub -all {^\s+} $script "" script 00400 regsub -all {\n\s+} $script "\n" script 00401 } 00402 00403 00404 ## ---------------------------------------------------------------------------- 00405 ## Getting unique file name from registry 00406 ## ---------------------------------------------------------------------------- 00407 body YadaExperiment::getPersistanceFileName {} { 00408 return [.main getPersistanceFileNameForExperiment $name] 00409 } 00410

YADA 2.0-alpha (20 Oct 2004)