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

YadaMethod.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 ## YadaMethod - bundled information about a method. 00013 ## A YadaMethod is the central object of the YADA application. It brings 00014 ## together all the parts that are needed to compute a YadaJob forking a cdgp 00015 ## process in the background and consuming the so produced data. 00016 ## \ingroup YadaConfiguration 00017 ## \ingroup YadaScheduler 00018 ## 00019 ## \author Michael Daum 00020 ## $Id: YadaMethod.tcl,v 1.18 2003/02/07 16:55:13 micha Exp $ 00021 ## ---------------------------------------------------------------------------- 00022 class YadaMethod { 00023 inherit YadaConfigItem 00024 00025 # variables ---------------------------------------------------------------- 00026 00027 ## the name of the method 00028 public variable name "" 00029 00030 ## the type of the method. 00031 ## The type of the method specifies the parsing flavour used. 00032 ## Possible sensefull values by now are 00033 ## - annotation (which is actually now parsing flavour but a way to compute 00034 ## parses via anno2parse()) 00035 ## - arcconsistency 00036 ## - frobbing 00037 ## - genetic 00038 ## - gls 00039 ## - incremental completition 00040 ## - isearch 00041 ## - netsearch 00042 ## - pruning 00043 ## - wfst 00044 public variable type "" 00045 00046 ## path to cdgp binary file 00047 public variable command "" 00048 00049 ## path where to store all computed data files 00050 public variable dataDir "" 00051 00052 ## YadaGrammar to appy this method. 00053 public variable grammarName "" 00054 00055 ## YadaMachine where to schedule resulting YadaJobs on. 00056 public variable machineName "localhost" 00057 00058 ## CDGP script to feed into the STDIN of a CdgProcess. 00059 public variable script "" 00060 00061 ## flag indicating whether this method is currently waiting for 00062 ## a YadaJob to finish. 00063 public variable isActive 1 00064 00065 ## flag indicating whether all data has been computed for this 00066 ## method, so no more YadaJobs are needed. 00067 public variable isComplete 0 00068 00069 ## flag indicating whether all statistics in all data has been 00070 ## collected or not. 00071 public variable isUpToDate 0 00072 00073 ## tcl command used to print a message. 00074 ## \see print() 00075 public variable printCommand "" 00076 00077 ## total scores collected in the methods data files. 00078 public variable totalScore 0 00079 00080 ## labelled hits collected in the methods data files. 00081 public variable labelledHits 0 00082 00083 ## strict hits collected in the methods data files. 00084 public variable strictHits 0 00085 00086 ## lexical hits collected in the methods data files. 00087 public variable lexicalHits 0 00088 00089 ## struct hits collected in the methods data files. 00090 public variable structHits 0 00091 00092 ## total number of tries collected in the methods data files. 00093 public variable totalTries 0 00094 00095 ## total time collected in the methods data files. 00096 public variable totalTime 0 00097 00098 ## total solution time collected in the methods data files. 00099 public variable totalSolTime 0 00100 00101 ## total soft time collected in the methods data files. 00102 public variable totalSoftTime 0 00103 00104 # methods ------------------------------------------------------------------ 00105 public method clone {args}; ## \type TclList 00106 public method check {} 00107 public method apply {job}; ## \type YadaJob 00108 public method print {message}; ## \type TclString 00109 public method resetStatistics {} 00110 public method getXmlFileName {wgName}; ## \type TclString 00111 public method getLogFileName {wgName}; ## \type TclString 00112 public method getDocFileName {} 00113 00114 constructor {args} {}; ## \type TclList 00115 00116 }; 00117 00118 ## ---------------------------------------------------------------------------- 00119 ## constructor 00120 ## ---------------------------------------------------------------------------- 00121 body YadaMethod::constructor {args} { 00122 00123 eval configure $args 00124 00125 # check if the named method already exists 00126 foreach method [itcl_info object -class YadaMethod] { 00127 if {[$method cget -name] == $name && $method != $this} { 00128 error "ERROR: method $name already exists" 00129 } 00130 } 00131 00132 } 00133 00134 ## ---------------------------------------------------------------------------- 00135 ## clone 00136 ## ---------------------------------------------------------------------------- 00137 body YadaMethod::clone {args} { 00138 set newMethod [YadaMethod ::#auto \ 00139 -name $name \ 00140 -type $type \ 00141 -command $command \ 00142 -dataDir $dataDir \ 00143 -grammarName $grammarName \ 00144 -machineName $machineName \ 00145 -script $script \ 00146 -isActive $isActive 00147 ] 00148 00149 eval $newMethod configure $args 00150 00151 return $newMethod 00152 } 00153 00154 ## ---------------------------------------------------------------------------- 00155 ## check 00156 ## ---------------------------------------------------------------------------- 00157 body YadaMethod::check {} { 00158 00159 if {$name == "<none>"} { 00160 return 1 00161 } 00162 00163 if {$dataDir == "" || $grammarName == ""} { 00164 return 0 00165 } 00166 00167 if {![file exists "$dataDir"]} { 00168 file mkdir "$dataDir" 00169 set isComplete 0 00170 } else { 00171 00172 # check if the method is complete 00173 if {!$isComplete} { 00174 set grammar [.main getGrammar $grammarName] 00175 set wordgraphs [$grammar getSelection] 00176 set isComplete 1 00177 foreach wordgraph $wordgraphs { 00178 set file [getXmlFileName $wordgraph] 00179 if {![file exists $file]} { 00180 set isComplete 0 00181 break 00182 } 00183 } 00184 } 00185 } 00186 00187 return $isComplete 00188 } 00189 00190 ## ---------------------------------------------------------------------------- 00191 ## apply 00192 ## ---------------------------------------------------------------------------- 00193 body YadaMethod::apply {job} { 00194 set wordgraph [$job cget -wordgraphName] 00195 set grammar [.main getGrammar $grammarName] 00196 set process [$job cget -process] 00197 if {$process == ""} { 00198 error "ERROR: method cannot be applied to an unstarted job" 00199 } 00200 00201 # replace makros in the script 00202 set tmpScript $script 00203 foreach file [$grammar getFiles] { 00204 regsub -all -- "%load" $tmpScript "load $file\n%load" tmpScript 00205 } 00206 regsub -all -- "%load" $tmpScript "" tmpScript 00207 regsub -all -- "%wordgraph" $tmpScript $wordgraph tmpScript 00208 regsub -all -- "%path" $tmpScript $dataDir tmpScript 00209 00210 # apply the script 00211 $process tell "$tmpScript\nquit\n" 00212 } 00213 00214 ## ---------------------------------------------------------------------------- 00215 ## print 00216 ## ---------------------------------------------------------------------------- 00217 body YadaMethod::print {message} { 00218 if {$printCommand != ""} { 00219 $printCommand $message 00220 } 00221 } 00222 00223 ## ---------------------------------------------------------------------------- 00224 ## getXmlFileName 00225 ## ---------------------------------------------------------------------------- 00226 body YadaMethod::getXmlFileName {wgName} { 00227 return [file join $dataDir ${wordgraph}.xml.gz] 00228 } 00229 00230 ## ---------------------------------------------------------------------------- 00231 ## getLogFileName 00232 ## ---------------------------------------------------------------------------- 00233 body YadaMethod::getLogFileName {wgName} { 00234 return [file join $dataDir ${wordgraph}.log.gz] 00235 } 00236 00237 ## ---------------------------------------------------------------------------- 00238 ## getDocFileName 00239 ## ---------------------------------------------------------------------------- 00240 body YadaMethod::getDocFileName {} { 00241 return [file join $dataDir yada.xml] 00242 } 00243 00244 ## ---------------------------------------------------------------------------- 00245 ## resetStatistics 00246 ## ---------------------------------------------------------------------------- 00247 body YadaMethod::resetStatistics {} { 00248 set totalScore 0 00249 set labelledHits 0 00250 set structHits 0 00251 set lexicalHits 0 00252 set strictHits 0 00253 set totalTries 0 00254 set totalTime 0 00255 set totalSolTime 0 00256 set totalSoftTime 0 00257 set noSolutions 0 00258 set isUpToDate 0 00259 } 00260 00261 ## ---------------------------------------------------------------------------- 00262 ## callback for script. 00263 ## ---------------------------------------------------------------------------- 00264 configbody YadaMethod::script { 00265 regsub -all {^\s+} $script "" script 00266 regsub -all {\n\s+} $script "\n" script 00267 } 00268

YADA 2.0-alpha (20 Oct 2004)