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

allwordgraphs.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 ## AllWordgraphs - manage all grammar wordgraphs. 00013 ## 00014 ## \author Michael Daum (see also AUTHORS and THANKS for more) 00015 ## $Id: allwordgraphs.tcl,v 1.70 2004/10/13 06:57:13 micha Exp $ 00016 ## ---------------------------------------------------------------------------- 00017 class AllWordgraphs { 00018 inherit DataBrowser 00019 00020 00021 # public methods 00022 public method getNext {latticeId}; ## \type TclString 00023 public method getPrev {latticeId}; ## \type TclString 00024 public method getAllLatticeIds {}; 00025 00026 # replaces getwordgraph 00027 public method getCData {id}; ## \type TclString 00028 00029 public method refreshrow {row id}; ## \type TclNumber, TclString 00030 00031 00032 00033 constructor {args} {}; ## \type TclList 00034 00035 # protected methods 00036 public method init_data {} 00037 00038 # private methods 00039 private method _init_data {} 00040 private method newbutton_action {} 00041 private method annobutton_action {} 00042 private method icbutton_action {} 00043 private method interactivebutton_action {} 00044 private method newnet {} 00045 00046 00047 # private variables 00048 00049 ## hash mapping wordgraph ids to their C structure 00050 private variable wordgraph; ## \type TclArray 00051 00052 ## list of ids sorted as in the table 00053 private variable allsorted 00054 00055 ## list of selected ids will be stored in inherited 00056 ## protected variable DataBrowser::_selection 00057 }; 00058 00059 ## ---------------------------------------------------------------------------- 00060 ## constructor 00061 ## ---------------------------------------------------------------------------- 00062 body AllWordgraphs::constructor {args} { 00063 set _idColumnIndex 0 00064 set table $itk_component(table) 00065 $table configure -cols 2 -colstretchmode last \ 00066 -cellanchor w -selecttype cell 00067 00068 itk_component add newbutton { 00069 button $itk_component(childsite).new \ 00070 -anchor w \ 00071 -text "New" \ 00072 -command [code $this newbutton_action] 00073 } { } 00074 00075 itk_component add newnetbutton { 00076 button $itk_component(childsite).newnet\ 00077 -anchor w \ 00078 -text "New Net" \ 00079 -command [code $this newnet] 00080 } { } 00081 00082 itk_component add annobutton { 00083 button $itk_component(childsite).annotation\ 00084 -anchor w \ 00085 -text "Annotations" \ 00086 -command [code $this annobutton_action] 00087 } { } 00088 00089 itk_component add icbutton { 00090 button $itk_component(childsite).ic\ 00091 -anchor w \ 00092 -text "IC" \ 00093 -command [code $this icbutton_action] 00094 } { } 00095 00096 itk_component add interactivebutton { 00097 button $itk_component(childsite).interactive\ 00098 -anchor w \ 00099 -text "Interactive" \ 00100 -command [code $this interactivebutton_action] 00101 } { } 00102 00103 itk_component add newnetDialog { 00104 NewnetDialog $itk_interior.newnetDialog \ 00105 -master . \ 00106 -title "Xcdg: Newnet" \ 00107 -modality application 00108 } { } 00109 00110 # packing 00111 pack $itk_component(newbutton) \ 00112 $itk_component(newnetbutton) \ 00113 $itk_component(annobutton) \ 00114 $itk_component(icbutton) \ 00115 $itk_component(interactivebutton) \ 00116 -side left -padx 3 00117 00118 # register the helpmessages 00119 .cdgmain help sethelpstr \ 00120 $itk_component(newbutton) "Input a new wordgraph" \ 00121 $itk_component(newnetbutton) "Compute a new constraint net" \ 00122 $itk_component(annobutton) "Find the corresponding parse in the input" \ 00123 $itk_component(icbutton) "Apply incremental search to the utterance" \ 00124 $itk_component(interactivebutton) "Parse user-supplied input." \ 00125 $itk_component(entryfield) "Enter a wordgraph-id" \ 00126 $itk_component(table) "Click to select" 00127 00128 # get the initial data 00129 _init_data 00130 00131 eval itk_initialize $args 00132 } 00133 00134 ## ---------------------------------------------------------------------------- 00135 ## fill a row with the values from a specific wordgraph. 00136 ## \param row row index to insert data 00137 ## \param ptr Pointer to lattice_id 00138 ## ---------------------------------------------------------------------------- 00139 body AllWordgraphs::refreshrow {row ptr} { 00140 set table $itk_component(table) 00141 set id [LatticeStruct_id_get $ptr] 00142 $table setCell $row,0 [LatticeStruct_id_get $ptr] 00143 00144 set sentence "" 00145 for {set m [LatticeStruct_arcs_get $ptr]}\ 00146 {$m != "NULL"} \ 00147 {set m [listNext $m]} { 00148 00149 set arc [listElement $m] 00150 append sentence " [ArcStruct_word_get $arc]" 00151 } 00152 $table setCell $row,1 $sentence 00153 } 00154 00155 00156 00157 00158 ## ---------------------------------------------------------------------------- 00159 ## call _init_data if necessary 00160 ## ---------------------------------------------------------------------------- 00161 body AllWordgraphs::init_data {} { 00162 00163 if {[InputStruct_xcdgwordgraphsToDate_get [inputCurrentGrammar_get]]} { 00164 return 00165 } 00166 00167 .cdgmain busy compute "Init Word Graphs" [code $this _init_data] 00168 } 00169 00170 00171 00172 ## ---------------------------------------------------------------------------- 00173 ## get the data from the cdg-tool 00174 ## ---------------------------------------------------------------------------- 00175 body AllWordgraphs::_init_data {} { 00176 00177 set table $itk_component(table) 00178 $table configure -state normal 00179 $table clear all 00180 $table delete rows 1 [$table cget -rows] 00181 $table tag config default 00182 $table tag config colored -bg gray80 00183 $table width 0 20 00184 $table setCell row 0,0 { "Id" "Words" } 00185 00186 array unset wordgraph 00187 set m [InputStruct_lattices_get [inputCurrentGrammar_get]] 00188 for {set l $m} { $l != "NULL" } { set l [listNext $l ] } { 00189 set lattice [listElement $l] 00190 set lattice_id [LatticeStruct_id_get $lattice] 00191 set wordgraph($lattice_id) $lattice 00192 } 00193 00194 set r 1 00195 set list [inputGetSortedLatticeNames [inputCurrentGrammar_get]] 00196 _setCount [listSize $list] 00197 for {set l $list} { $l != "NULL" } { set l [listNext $l ] } { 00198 00199 set name [pointer2string [listElement $l]] 00200 lappend allsorted $name 00201 set lattice $wordgraph($name) 00202 refreshrow $r $lattice 00203 incr r 00204 00205 if {[expr $r % 100] == 0} { 00206 update idletask 00207 } 00208 00209 } 00210 listDelete $list; 00211 00212 setSelection 00213 00214 InputStruct_xcdgwordgraphsToDate_set [inputCurrentGrammar_get] 1 00215 $table configure -state disabled 00216 } 00217 00218 ## ---------------------------------------------------------------------------- 00219 ## actions to take place on pressing the newbutton 00220 ## ---------------------------------------------------------------------------- 00221 body AllWordgraphs::newbutton_action {} { 00222 .cdgmain confirm "Under Construction\nPlease use `inputwordgraph' in the shell." 00223 } 00224 00225 ## ---------------------------------------------------------------------------- 00226 ## actions to take place on pressing the annobutton 00227 ## ---------------------------------------------------------------------------- 00228 body AllWordgraphs::annobutton_action {} { 00229 00230 if {$_selection == ""} { 00231 ::cmd::Puts "ERROR: Please select a wordgraph" 00232 return 00233 } 00234 00235 foreach item $_selection { 00236 set lat [findLattice $item] 00237 if {$lat == "NULL"} { 00238 ::cmd::Puts "ERROR: no lattice `$item' found." 00239 return 00240 } 00241 for {set l [findAnnotations $lat 1]} {$l != "NULL" } {set l [listNext $l]} { 00242 set id [AnnoEntryStruct_id_get [listElement $l]] 00243 set parse [.cdgmain parses getCData $id] 00244 .cdgmain parses showparse $id 00245 } 00246 } 00247 } 00248 00249 ## ---------------------------------------------------------------------------- 00250 ## actions to take place on pressing the icbutton 00251 ## ---------------------------------------------------------------------------- 00252 body AllWordgraphs::icbutton_action {} { 00253 00254 if {$_selection == ""} { 00255 ::cmd::Puts "ERROR: Please select a wordgraph" 00256 return 00257 } 00258 00259 foreach id $_selection { 00260 ::cmd::IC $id 00261 } 00262 } 00263 00264 ## ---------------------------------------------------------------------------- 00265 ## actions to take place on pressing the interactivebutton 00266 ## ---------------------------------------------------------------------------- 00267 body AllWordgraphs::interactivebutton_action {} { 00268 00269 # if there already is an interactive window, do nothing 00270 foreach vis [itcl::find objects -isa VisParses] { 00271 if {[$vis cget -title] == "IC:interactive"} { 00272 ::cmd::Puts "ERROR: There already is an open interactive window." 00273 return 00274 } 00275 } 00276 00277 # build a window to display results 00278 set interactiveWindow [VisParses ".#auto" \ 00279 -title "Xcdg - Interactive parsing" \ 00280 -iconname "Interactive" \ 00281 -interactive 1 ] 00282 00283 # call IC in interactive mode 00284 ::cmd::IC interactive 00285 00286 00287 } 00288 00289 ## ---------------------------------------------------------------------------- 00290 ## actions taking place when the newnetbutton is pressed 00291 ## ---------------------------------------------------------------------------- 00292 body AllWordgraphs::newnet {} { 00293 00294 if {"$_selection" != ""} { 00295 $itk_component(newnetDialog) activate $_selection 00296 } 00297 } 00298 00299 ## ---------------------------------------------------------------------------- 00300 ## get pointer to a lattice_id, cache it in array wordgraph 00301 ## ---------------------------------------------------------------------------- 00302 body AllWordgraphs::getCData {id} { 00303 if {![info exists wordgraph($id)]} { 00304 set found 0 00305 set lattice [findLattice [string2pointer $id]] 00306 if {$lattice == "NULL"} { 00307 return "NULL" 00308 } 00309 set wordgraph($id) $lattice 00310 } 00311 return $wordgraph($id) 00312 } 00313 00314 00315 00316 ## ---------------------------------------------------------------------------- 00317 ## get the lattice next after $id. 00318 ## ---------------------------------------------------------------------------- 00319 body AllWordgraphs::getNext {latticeId} { 00320 00321 init_data 00322 if {![info exists wordgraph($latticeId)]} { 00323 return "" 00324 } 00325 set ids [getAllLatticeIds] 00326 set index [lsearch -exact $ids $latticeId] 00327 set index [expr $index + 1] 00328 return [lindex $ids $index] 00329 00330 } 00331 00332 ## ---------------------------------------------------------------------------- 00333 ## Show the annotation for the lattice above $id. 00334 ## ---------------------------------------------------------------------------- 00335 body AllWordgraphs::getPrev {latticeId} { 00336 00337 init_data 00338 if {![info exists wordgraph($latticeId)]} { 00339 return "" 00340 } 00341 set ids [getAllLatticeIds] 00342 set index [lsearch -exact $ids $latticeId] 00343 set index [expr $index - 1] 00344 return [lindex $ids $index] 00345 } 00346 00347 00348 ## ---------------------------------------------------------------------------- 00349 ## Return list of all lattices' names 00350 ## ---------------------------------------------------------------------------- 00351 body AllWordgraphs::getAllLatticeIds {} { 00352 init_data 00353 return $allsorted 00354 }

XCDG 0.95 (20 Oct 2004)