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

parse.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 ## Parse - OO wrapper for the parse C structure. 00013 ## 00014 ## This is an object oriented wrapper arround the C structure with 00015 ## the same name. All access to that C structure should be encapsulated 00016 ## by this class. All methods dealing directly with a C ParseStruct 00017 ## are called via this class. 00018 ## \todo There are rather some exceptions ;) (but why). 00019 ## 00020 ## \author Michael Daum, Kilian A. Foth, Dietmar Fünning 00021 ## (see also AUTHORS and THANKS for more) 00022 ## 00023 ## $Id parse.tcl$ 00024 ## ---------------------------------------------------------------------------- 00025 class Parse { 00026 00027 # private variables 00028 00029 ## pointer to the C structure 00030 private variable _cpointer 0; ## \type Parse 00031 00032 ## the height of a word in a dependency tree on a level. 00033 ## This hash mapps \c levelId x \c wordIndex to the word height. 00034 ## Note that this simply caches the values computed by parseWordHeight() 00035 ## and stores them at the tcl layer for faster access. 00036 ## \see getWordHeight(), shiftEdge() 00037 private variable _wordHeight; ## \type TclArray 00038 00039 ## the depth of a word in a dependency tree on a level. 00040 ## This hash mapps \c levelId x \c wordIndex to the word depth. 00041 ## Note that this simply caches the values computed by parseWordDepth() 00042 ## and stores the mat the tcl layer for faster access. 00043 ## \see getWordDepth(), shiftEdge() 00044 private variable _wordDepth; ## \type TclArray 00045 00046 ## the height of each tree on each level. 00047 ## This hash mapps the \c levelId to the height. Note that this 00048 ## simply caches the values computed by parseHeight(). 00049 ## \see getHeight(), shiftEdge() 00050 private variable _treeHeight ; ## \type TclArray 00051 00052 ## information about each word on each level. 00053 ## This has mapps the \c levelId x \c wordIndex to a boolean flag 00054 ## indicating whether the adressed word is being modified or not. 00055 private variable _isLeafNode ; ## \type TclArray 00056 00057 ## cache to speed up tree access. 00058 ## This hash stores all bindings for each level mapping \c levelId to 00059 ## the list of all bindings on that level. 00060 ## A binding is a list consisting of the following elements 00061 ## - the \c wordIndex 00062 ## - the \c modifiee index taken from the ParseStruct::verticesStructure 00063 ## - the \c label taken from the ParseStruct::verticesLabels 00064 ## - the \c index computed for this parse (see indexOf()) 00065 ## - the \c levelId to which this encoded binding belongs to 00066 ## \see getBindings(), swapLabel(), swapWord(), shiftEdge() 00067 private variable _bindings; ## \type TclArray 00068 00069 # public methods 00070 public method getBindings {levelId}; ## \type TclString 00071 public method getBindingById {bindingId}; ## \type TclString 00072 public method getBindingAt {levelId wordIndex}; ## \type TclString, TclNumber 00073 public method getHeight {levelId}; ## \type TclString 00074 public method getWordHeight {levelId wordInedx}; ## \type TclString, TclNumber 00075 public method getWordDepth {levelId wordInedx}; ## \type TclString, TclNumber 00076 public method getWidth {} 00077 public method getModifiers {levelId wordIndex}; ## \type TclString, TclNumber 00078 public method getModifiee {levelId wordIndex}; ## \type TclString, TclNumber 00079 public method getId {} 00080 public method getLatticeId {} 00081 public method getUserName {} 00082 public method getDate {} 00083 public method getGrammarFiles {} 00084 public method getSearchStrategy {} 00085 public method getComment {} 00086 public method getSolutionNo {} 00087 public method getNoSolutions {} 00088 public method getLevels {} 00089 public method getLabels {} 00090 public method getLexemes {} 00091 public method getCurrentReading {wordIndex}; ## \type TclNumber 00092 public method getLexiconItem {wordIndex}; ## \type TclNumber 00093 public method getValue {wordIndex}; ## \type TclNumber 00094 public method getBadness {} 00095 public method getScore {} 00096 public method getViolations {} 00097 public method getWords {} 00098 public method getWord {wordIndex}; ## \type TclNumber 00099 public method verify {} 00100 public method swapWord {wordIndex description}; ## \type TclNumber, TclString 00101 public method optimizeLabel {levelId wordIndex}; ## \type TclString, TclNumber 00102 public method optimizeWord {wordIndex}; ## \type TclNumber 00103 public method optimizeStructure {levelId wordIndex}; ## \type TclNumber, TclNumber 00104 public method swapLabel {levelId wordIndex label}; ## \type TclString, TclNumber, TclString 00105 public method shiftEdge {levelId wordIndex targetIndex}; ## \type TclString, TclNumber, TclNumber 00106 public method isAbstract {} 00107 public method isLeafNode {levelId wordIndex}; ## \type TclString, TclNumber 00108 public method register {} 00109 public method mirror {} 00110 public method toAnno {} 00111 public method init {cpointer}; ## \type Parse 00112 public method indexOf {levelId wordIndex}; ## \type TclString, TclNumber 00113 00114 constructor {args} {}; ## \type TclList 00115 }; 00116 00117 ## ---------------------------------------------------------------------------- 00118 ## constructor 00119 ## ---------------------------------------------------------------------------- 00120 body Parse::constructor {args} { 00121 00122 set _cpointer 0 00123 eval configure $args 00124 } 00125 00126 ## ---------------------------------------------------------------------------- 00127 ## attach a C structure to this instance. 00128 ## 00129 ## @param cpointer a pointer to a @ref ParseStruct 00130 ## Every Parse can only be initialized once. 00131 ## ---------------------------------------------------------------------------- 00132 body Parse::init {cpointer} { 00133 if {$_cpointer != 0} { 00134 error "ERROR: this parse is already attached to a C structure" 00135 } 00136 00137 set _cpointer $cpointer 00138 } 00139 00140 ## ---------------------------------------------------------------------------- 00141 ## get all bindings on a given level. 00142 ## This method retrieves all bindings of the unerlying Parse. 00143 ## \see getBindingsAt 00144 ## \param levelId the id of the level whose bindings we are interested in. 00145 ## \returns a TclList of all bindings (that is a list of lists) 00146 ## \see Parse::_bindings for an explanation of the list format 00147 ## ---------------------------------------------------------------------------- 00148 body Parse::getBindings {levelId} { 00149 00150 if {![info exists _bindings($levelId)]} { 00151 set _bindings($levelId) "" 00152 set noWords [getWidth] 00153 for {set i 0} {$i < $noWords} {incr i} { 00154 lappend _bindings($levelId) [getBindingAt $levelId $i] 00155 } 00156 } 00157 00158 return $_bindings($levelId) 00159 } 00160 00161 ## ---------------------------------------------------------------------------- 00162 ## get the binding at a position on a level. 00163 ## This is the lowest access function to the ParseStruct. All information 00164 ## retrieved from the ParseStruct is cached in Parse::_bindings for faster 00165 ## access. This cache 00166 ## only gets invalidated by swapWord(), swapLabel() or shiftEdge(). 00167 ## Thereby caching should be \em mostly transparent. 00168 ## \note The cache gets out of sync if the C layer changes the Parse structure 00169 ## without using this Tcl layer. 00170 ## \param levelId the id of the level whose binding we are interested in. 00171 ## \param wordIndex the index of the word of the parse. 00172 ## \returns a TclList of the binding information 00173 ## \see Parse::_bindings for an explanation of the list format 00174 ## ---------------------------------------------------------------------------- 00175 body Parse::getBindingAt {levelId wordIndex} { 00176 00177 set index [indexOf $levelId $wordIndex] 00178 set modifiee [intVectorElementAt [ParseStruct_verticesStructure_get $_cpointer] $index] 00179 set labelPointer [vectorElement [ParseStruct_verticesLabels_get $_cpointer] $index] 00180 set label [pointer2string $labelPointer] 00181 return [list $wordIndex $modifiee $label $index $levelId ] 00182 } 00183 00184 ## ---------------------------------------------------------------------------- 00185 ## get the bindings of a given index. 00186 ## This comes done to the binding that is pointed to by a constraint violation. 00187 ## Its \c nodeBindingIndex1 and \c nodeBindingIndex2 correspond to the binding 00188 ## index, that is the third element in the bindings list (see Parse::_bindings). 00189 ## \todo This method is inefficient as we search thru all bindings for 00190 ## the given id. 00191 ## Alas extra hash shall soothe thee, as we damn the ancillary storage hassle. 00192 ## \param id the node binding index in the parse (see indexOf()) 00193 ## \returns the binding list or an empty list if a binding of index \c id isn't 00194 ## there. 00195 ## \see Parse::_bindings for an explanation of the bindings list format. 00196 ## ---------------------------------------------------------------------------- 00197 body Parse::getBindingById {id} { 00198 foreach levelId [getLevels] { 00199 foreach binding [getBindings $levelId] { 00200 if {[lindex $binding 3] == $id} { 00201 return $binding 00202 } 00203 } 00204 } 00205 return "" 00206 } 00207 00208 ## ---------------------------------------------------------------------------- 00209 ## get all modifiers of a word on a level. 00210 ## This method does not boil down to getBindingAt() as you would expect but 00211 ## sacrifies clean design for speed accessing the ParseStruct::verticesStruct 00212 ## directly retrieving what we want. 00213 ## \param levelId the id of the level whose binding we are interested in. 00214 ## \param wordIndex the index of the word of the parse. 00215 ## \returns a list of all modifiers of the given word. 00216 ## ---------------------------------------------------------------------------- 00217 body Parse::getModifiers {levelId wordIndex} { 00218 set modifiers "" 00219 set noWords [getWidth] 00220 set vertices [ParseStruct_verticesStructure_get $_cpointer] 00221 00222 for {set i 0} {$i < $noWords} {incr i} { 00223 set index [indexOf $levelId $i] 00224 set modifieeIndex [intVectorElementAt $vertices $index] 00225 if {$wordIndex == $modifieeIndex} { 00226 lappend modifiers $i 00227 } 00228 } 00229 00230 return $modifiers 00231 } 00232 00233 ## ---------------------------------------------------------------------------- 00234 ## get the modifiee of a word on a level. 00235 ## This method lets you access the ParseStruct::verticesStruct easily. 00236 ## \param levelId the id of the level whose binding we are interested in. 00237 ## \param wordIndex the index of the word of the parse. 00238 ## \returns the modifiee index of the given word. 00239 ## ---------------------------------------------------------------------------- 00240 body Parse::getModifiee {levelId wordIndex} { 00241 00242 set index [indexOf $levelId $wordIndex] 00243 return [intVectorElementAt [ParseStruct_verticesStructure_get $_cpointer] $index] 00244 } 00245 00246 ## ---------------------------------------------------------------------------- 00247 ## get all violations of the current parse. 00248 ## Information is taken from the Parse::violations and then taken appart 00249 ## meticulously for you. We return a list of violations each 00250 ## with the following format in the following order: 00251 ## - the \c name of the violation 00252 ## - the \c first node binding index (aka. the binding id - see getBindingById()) 00253 ## - the \c second node binding index 00254 ## - the \c score of the violation 00255 ## \returns the violations as described above, that is a list of lists. 00256 ## ---------------------------------------------------------------------------- 00257 body Parse::getViolations {} { 00258 00259 set violations [ParseStruct_violations_get $_cpointer] 00260 set result "" 00261 00262 for {set l $violations} {$l != "NULL" } {set l [listNext $l]} { 00263 set viola [listElement $l] 00264 set constraint [ConstraintViolationStruct_constraint_get $viola] 00265 set name [ConstraintStruct_id_get $constraint] 00266 set score [ConstraintViolationStruct_penalty_get $viola] 00267 set b1 [ConstraintViolationStruct_nodeBindingIndex1_get $viola] 00268 set b2 [ConstraintViolationStruct_nodeBindingIndex2_get $viola] 00269 00270 # translate LV index to vertex number 00271 set b1 [parseRmap $_cpointer $b1] 00272 set b2 [parseRmap $_cpointer $b2] 00273 lappend result [list $name $b1 $b2 $score ] 00274 } 00275 00276 return $result 00277 } 00278 00279 ## ---------------------------------------------------------------------------- 00280 ## Get all levels of the Parse. 00281 ## This method collects the ids of all levels contained in the current parse. 00282 ## So this is an easy accessor for ParseStruct::levels. 00283 ## \returns a list of \c levelIds 00284 ## ---------------------------------------------------------------------------- 00285 body Parse::getLevels {} { 00286 00287 set levels "" 00288 for {set l [ParseStruct_levels_get $_cpointer]} \ 00289 {$l != "NULL"} \ 00290 {set l [listNext $l]} { 00291 set item [listElement $l] 00292 set levelId [pointer2string $item] 00293 lappend levels $levelId 00294 } 00295 00296 # If all of the Parse's levels are also declared in the grammar, 00297 # make sure that the result conforms to the order in the grammar. 00298 set in_parse [split $levels] 00299 set in_grammar [getLevelSort] 00300 set sp [lsort $in_parse] 00301 set sg [lsort $in_grammar] 00302 if {"$sp" == "$sg"} { 00303 set levels $in_grammar 00304 } 00305 00306 return $levels 00307 00308 } 00309 00310 ## ---------------------------------------------------------------------------- 00311 ## get all labels. 00312 ## This method collects all labels from ParseStruct::labels for you. Actually 00313 ## this should be only a fallback whenever we cannot ask the grammar for its 00314 ## labels. 00315 ## \returns $_cpointer->labels as a Tcl list 00316 ## ---------------------------------------------------------------------------- 00317 body Parse::getLabels {} { 00318 00319 set labels "" 00320 for {set l [ParseStruct_labels_get $_cpointer]} \ 00321 {$l != "NULL" } \ 00322 {set l [listNext $l]} { 00323 set item [listElement $l] 00324 lappend labels [pointer2string $item] 00325 } 00326 00327 return $labels 00328 } 00329 00330 00331 ## ---------------------------------------------------------------------------- 00332 ## get all lexeme nodes of current parse. 00333 ## This method is only a wrapper for parseGetLexemNodes() converting the 00334 ## returned List into a TclList (I know this is lame) 00335 ## \returns a list of LexemNode items. 00336 ## ---------------------------------------------------------------------------- 00337 body Parse::getLexemes {} { 00338 00339 set result "" 00340 set nodes [parseGetLexemNodes $_cpointer] 00341 00342 for {set l $nodes} {$l != "NULL"} {set l [listNext $l]} { 00343 lappend result [listElement $l] 00344 } 00345 return $result 00346 } 00347 00348 ## ---------------------------------------------------------------------------- 00349 ## get the score of the current parse. 00350 ## This is a getter method for the ParseStruct::score. 00351 ## \returns a float. 00352 ## ---------------------------------------------------------------------------- 00353 body Parse::getScore {} { 00354 00355 return [ParseStruct_score_get $_cpointer] 00356 } 00357 00358 ## ---------------------------------------------------------------------------- 00359 ## get the id of the current parse. 00360 ## This is a getter method for the ParseStruct::id 00361 ## \returns a TclString 00362 ## ---------------------------------------------------------------------------- 00363 body Parse::getId {} { 00364 00365 return [ParseStruct_id_get $_cpointer] 00366 } 00367 00368 ## ---------------------------------------------------------------------------- 00369 ## get the date of the current parse. 00370 ## This is a wrapper for parseDate() in the C layer. 00371 ## \returns the date of creation of the current parse. 00372 ## ---------------------------------------------------------------------------- 00373 body Parse::getDate {} { 00374 return [parseDate $_cpointer] 00375 } 00376 00377 ## ---------------------------------------------------------------------------- 00378 ## get the search strategy. 00379 ## This method returns the information about the search strategy 00380 ## with which the current parse has been produced 00381 ## \returns a TclString 00382 ## ---------------------------------------------------------------------------- 00383 body Parse::getSearchStrategy {} { 00384 return [ParseStruct_searchStrategy_get $_cpointer] 00385 } 00386 00387 ## ---------------------------------------------------------------------------- 00388 ## get the comment of the current parse. 00389 ## This is a getter method for the ParseStruct::comment. 00390 ## \returns a TclString 00391 ## ---------------------------------------------------------------------------- 00392 body Parse::getComment {} { 00393 return [ParseStruct_comment_get $_cpointer] 00394 } 00395 00396 ## ---------------------------------------------------------------------------- 00397 ## get the number of solutions. 00398 ## This is the number of solutions this parse is one of. 00399 ## \see getSolutionNo() 00400 ## ---------------------------------------------------------------------------- 00401 body Parse::getNoSolutions {} { 00402 return [ParseStruct_noOfSolutions_get $_cpointer] 00403 } 00404 00405 ## ---------------------------------------------------------------------------- 00406 ## get the solution number. 00407 ## This is the solution number identifying this parse as being one of several 00408 ## solutions. 00409 ## \see getNoSolutions() 00410 ## ---------------------------------------------------------------------------- 00411 body Parse::getSolutionNo {} { 00412 return [ParseStruct_solutionNo $_cpointer] 00413 } 00414 00415 ## ---------------------------------------------------------------------------- 00416 ## get all grammar files. 00417 ## This gets all grammar files related to this parse, that is return the 00418 ## tcl-ized list of ParseStruct::grammarFiles. 00419 ## \returns a TclList of grammar file names. 00420 ## ---------------------------------------------------------------------------- 00421 body Parse::getGrammarFiles {} { 00422 set grammarFiles "" 00423 00424 for {set l [ParseStruct_grammarFiles_get $_cpointer]} \ 00425 {$l != "NULL"} {set l [listNext $l]} { 00426 set item [listElement $l] 00427 lappend grammarFiles [pointer2string $item] 00428 } 00429 00430 return $grammarFiles 00431 } 00432 00433 ## ---------------------------------------------------------------------------- 00434 ## get the lattice id. 00435 ## This method returns the \c latticeId this parse is annotating, that is 00436 ## return ParseStruct::latticeId. 00437 ## ---------------------------------------------------------------------------- 00438 body Parse::getLatticeId {} { 00439 return [ParseStruct_latticeId_get $_cpointer] 00440 } 00441 00442 ## ---------------------------------------------------------------------------- 00443 ## get the user name. 00444 ## This method returns the user who created this parse. 00445 ## ---------------------------------------------------------------------------- 00446 body Parse::getUserName {} { 00447 return [ParseStruct_userName_get $_cpointer] 00448 } 00449 00450 ## ---------------------------------------------------------------------------- 00451 ## get the badness value of the current parse. 00452 ## This method computes the badness of the current parse by itself looking 00453 ## up its constraint violations. The badness is given as a list containing 00454 ## - the number of hard violations 00455 ## - the number of soft violations 00456 ## - the remaining score not taking the hard violations into account. 00457 ## \returns a badness list as described above. 00458 ## ---------------------------------------------------------------------------- 00459 body Parse::getBadness {} { 00460 00461 if {[parseIsAbstract $_cpointer]} { 00462 return "n.a."; 00463 } else { 00464 set nohard 0 00465 set nosoft 0 00466 set soft 1.0 00467 foreach viola [getViolations] { 00468 set score [lindex $viola 3] 00469 if {$score == 0.0} { 00470 incr nohard 00471 } else { 00472 incr nosoft 00473 set soft [expr $soft * $score] 00474 } 00475 } 00476 return [list $nohard $nosoft $soft] 00477 } 00478 } 00479 00480 ## ---------------------------------------------------------------------------- 00481 ## get the height of the dependency tree on a given level. 00482 ## This method simply returns the parseHeight() of the current parse on 00483 ## the given level. Doing that it caches the result on the tcl layer for faster 00484 ## access. If the parse changes in structure (by shiftEdge()) this array 00485 ## gets invalidated again. 00486 ## \param levelId the id of the level we are interested in. 00487 ## \returns the tree height 00488 ## ---------------------------------------------------------------------------- 00489 body Parse::getHeight {levelId} { 00490 00491 if {![info exists _treeHeight($levelId)]} { 00492 set _treeHeight($levelId) [parseHeight $_cpointer $levelId] 00493 } 00494 00495 return $_treeHeight($levelId) 00496 } 00497 00498 ## ---------------------------------------------------------------------------- 00499 ## Wrapper for parseWordHeight(). 00500 ## This method simply returns the parseWordHeight() of a word on a level in 00501 ## the current parse. Afterwards results are cached at the tcl layer. Occasionally 00502 ## shiftEdge() nullifies this again. 00503 ## \param levelId the level we are interested in 00504 ## \param wordIndex the word we are interested in 00505 ## \returns the word height 00506 ## ---------------------------------------------------------------------------- 00507 body Parse::getWordHeight {levelId wordIndex} { 00508 00509 if {![info exists _wordHeight($levelId,$wordIndex)]} { 00510 set _wordHeight($levelId,$wordIndex) \ 00511 [parseWordHeight $_cpointer $levelId $wordIndex] 00512 } 00513 00514 return $_wordHeight($levelId,$wordIndex) 00515 } 00516 00517 ## ---------------------------------------------------------------------------- 00518 ## get maximum distance of reachable leaves. 00519 ## This method works using the same caching logic like getWordHeight() and 00520 ## all the other methods that retrieve numbers from the C layer caching them 00521 ## on the tcl layer. 00522 ## \param levelId the level we are interested in 00523 ## \param wordIndex the word we are interested in 00524 ## \returns the word depth 00525 ## ---------------------------------------------------------------------------- 00526 body Parse::getWordDepth {levelId wordIndex} { 00527 00528 if {![info exists _wordDepth($levelId,$wordIndex)]} { 00529 set level [findLevel $levelId] 00530 if {$level == "NULL"} { 00531 error "level $levelId unknown" 00532 } 00533 set _wordDepth($levelId,$wordIndex) \ 00534 [parseWordDepth $_cpointer $level $wordIndex] 00535 } 00536 00537 return $_wordDepth($levelId,$wordIndex) 00538 } 00539 00540 00541 ## ---------------------------------------------------------------------------- 00542 ## get the number of words. 00543 ## Actually being a bad name for what it does this simply counts the 00544 ## number of words in the ParseStruct::words vector. 00545 ## ---------------------------------------------------------------------------- 00546 body Parse::getWidth {} { 00547 return [vectorSize [ParseStruct_words_get $_cpointer]] 00548 } 00549 00550 ## ---------------------------------------------------------------------------- 00551 ## get the words Vector of the current parse. 00552 ## This method does not attempt to extract all words from the ParseStruct::words 00553 ## vector but returns the Vector itself. 00554 ## \returns a Vector of Word items 00555 ## ---------------------------------------------------------------------------- 00556 body Parse::getWords {} { 00557 return [ParseStruct_words_get $_cpointer] 00558 } 00559 00560 ## ---------------------------------------------------------------------------- 00561 ## get a word from the parse. 00562 ## This method gets you the WordStruct at the given index 00563 ## \param wordIndex the word we want 00564 ## \returns a WordStruct 00565 ## ---------------------------------------------------------------------------- 00566 body Parse::getWord {wordIndex} { 00567 return [vectorElement [getWords] $wordIndex] 00568 } 00569 00570 ## ---------------------------------------------------------------------------- 00571 ## Return the description of the word currently selected at the 00572 ## timepoint $wordIndex. 00573 ## ---------------------------------------------------------------------------- 00574 body Parse::getCurrentReading {wordIndex} { 00575 return [WordStruct_description_get [getWord $wordIndex]] 00576 } 00577 00578 ## ---------------------------------------------------------------------------- 00579 ## Return a string representing the lexicon item currently selected at the 00580 ## timepoint $wordIndex. 00581 ## ---------------------------------------------------------------------------- 00582 body Parse::getValue {i} { 00583 return [parseFormatValue $_cpointer $i] 00584 } 00585 00586 ## ---------------------------------------------------------------------------- 00587 ## Return the lexicon item currently selected at the timepoint $wordIndex. 00588 ## ---------------------------------------------------------------------------- 00589 body Parse::getLexiconItem {i} { 00590 return [parseLexiconItem $_cpointer $i] 00591 } 00592 00593 ## ---------------------------------------------------------------------------- 00594 ## verify the current parse. 00595 ## This is method verifies the current parse using the first annotation 00596 ## linked to the same lattice, that is: this parse has a link to a lattice 00597 ## and there exist one or more annotations linked to this lattice; we take the 00598 ## first of them. 00599 ## \returns a ParseVerificationStruct or the empty string on an error 00600 ## ---------------------------------------------------------------------------- 00601 body Parse::verify {} { 00602 00603 set parseId [getId] 00604 set latId [getLatticeId] 00605 set lat [findLattice $latId] 00606 if {"$lat" != "NULL"} { 00607 for {set l [findAnnotations $lat 1]} \ 00608 {$l != "NULL"} \ 00609 {set l [listNext $l]} { 00610 set ae [listElement $l] 00611 set annoId [AnnoEntryStruct_id_get $ae] 00612 # if there is an annotation that has the same name as the parse, 00613 # do not use it for verification, that would be pointless. 00614 if {"$annoId" != "$parseId"} { 00615 return [parseVerify $_cpointer $ae] 00616 } 00617 } 00618 } 00619 return "" 00620 } 00621 00622 ## ---------------------------------------------------------------------------- 00623 ## exchange a word at a given index. 00624 ## This method uses parseSwapWord() to maniplulate the parse structure. 00625 ## Note that the Parse::_bindings array is invalidated completely here. 00626 ## ---------------------------------------------------------------------------- 00627 body Parse::swapWord {wordIndex description} { 00628 array unset _bindings 00629 parseSwapWord $_cpointer $wordIndex $description 00630 } 00631 00632 ## ---------------------------------------------------------------------------- 00633 ## exchange the label of a dependency edge. 00634 ## This method uses parseSwapLabel() to do the actual work. Note that the 00635 ## Parse::_bindings array is invalidated for this level. 00636 ## \param levelId the level we want to maniplulate 00637 ## \param wordIndex the word index of the dependency edge 00638 ## \param label the new label for this dependency edge 00639 ## ---------------------------------------------------------------------------- 00640 body Parse::swapLabel {levelId wordIndex label} { 00641 catch { unset _bindings($levelId) } 00642 parseSwapLabel $_cpointer [indexOf $levelId $wordIndex] $label 00643 } 00644 00645 ## ---------------------------------------------------------------------- 00646 ## Wrapper for parseOptimizeLabel(). 00647 ## 00648 body Parse::optimizeLabel {levelId wordIndex} { 00649 return [parseOptimizeLabel $_cpointer $levelId $wordIndex] 00650 } 00651 00652 ## ---------------------------------------------------------------------- 00653 ## Wrapper for parseOptimizeWord(). 00654 ## 00655 body Parse::optimizeWord {wordIndex} { 00656 return [parseOptimizeWord $_cpointer $wordIndex] 00657 } 00658 00659 ## ---------------------------------------------------------------------- 00660 ## Wrapper for parseOptimizeStructure(). 00661 ## 00662 body Parse::optimizeStructure {levelId wordIndex} { 00663 return [parseOptimizeStructure $_cpointer $levelId $wordIndex] 00664 } 00665 00666 00667 ## ---------------------------------------------------------------------------- 00668 ## redirect a dependency edge to a new modifiee. 00669 ## This method uses parseShiftEdge() to do the actual work. Note that the 00670 ## arrays Parse::_wordHeight, Parse::_wordDepth, Parse::_bindings and 00671 ## Parse::_treeHeight are invalidated for this level. 00672 ## \param levelId the level we want to maniplulate 00673 ## \param wordIndex the word index of the dependency edge 00674 ## \param targetIndex the index of the new modifiee 00675 ## ---------------------------------------------------------------------------- 00676 body Parse::shiftEdge {levelId wordIndex targetIndex} { 00677 array unset _wordHeight "$levelId,*" 00678 array unset _wordDepth "$levelId,*" 00679 array unset _isLeafNode "$levelId,*" 00680 catch { 00681 unset _bindings($levelId) 00682 unset _treeHeight($levelId) 00683 } 00684 parseShiftEdge $_cpointer [indexOf $levelId $wordIndex] $targetIndex 00685 } 00686 00687 ## ---------------------------------------------------------------------------- 00688 ## Wrapper for parseIndex(). 00689 ## ---------------------------------------------------------------------------- 00690 body Parse::indexOf {levelId wordIndex} { 00691 return [parseIndex $_cpointer $levelId $wordIndex] 00692 } 00693 00694 ## ---------------------------------------------------------------------------- 00695 ## get the abstraction state of the current parse. 00696 ## This is a straight delegation to parseIsAbstract(). 00697 ## \returns a bool. 00698 ## ---------------------------------------------------------------------------- 00699 body Parse::isAbstract {} { 00700 return [parseIsAbstract $_cpointer] 00701 } 00702 00703 ## ---------------------------------------------------------------------------- 00704 ## test whether a word on a given level is a leaf. 00705 ## This is done by examining the ParseStruct::verticesStruct storing the 00706 ## result into Parse::_isLeafNode at the index \c levelId x \c wordIndex. 00707 ## This caches information of the C layer in the tcl layer. Invalidating this 00708 ## cache is done when needed, i.e. in shiftEdge(). 00709 ## \param levelId the level we are interested in 00710 ## \param wordIndex the word index 00711 ## \returns 0 or 1 00712 ## ---------------------------------------------------------------------------- 00713 body Parse::isLeafNode {levelId wordIndex} { 00714 00715 if {![info exists _isLeafNode($levelId,$wordIndex)]} { 00716 set _isLeafNode($levelId,$wordIndex) 1 00717 set noWords [getWidth] 00718 set vertices [ParseStruct_verticesStructure_get $_cpointer] 00719 for {set i 0} {$i < $noWords} {incr i} { 00720 set index [indexOf $levelId $i] 00721 set modifieeIndex [intVectorElementAt $vertices $index] 00722 if {$wordIndex == $modifieeIndex} { 00723 set _isLeafNode($levelId,$wordIndex) 0 00724 break 00725 } 00726 } 00727 } 00728 00729 return $_isLeafNode($levelId,$wordIndex) 00730 } 00731 00732 ## ---------------------------------------------------------------------------- 00733 ## register the current parse to th C layer. 00734 ## This puts the C Parse into inputCurrentGrammar->parses. Actually this 00735 ## operation is blindly delegated to parseRegister(). 00736 ## ---------------------------------------------------------------------------- 00737 body Parse::register {} { 00738 parseRegister $_cpointer 00739 } 00740 00741 ## ---------------------------------------------------------------------------- 00742 ## compute the mirror edges. 00743 ## This is a straight delegation to parseMirror(). Note that all caches on 00744 ## the tcl layer are possibly invalidated now. 00745 ## ---------------------------------------------------------------------------- 00746 body Parse::mirror {} { 00747 array unset _wordHeight 00748 array unset _wordDepth 00749 array unset _isLeafNode 00750 array unset _bindings 00751 array unset _treeHeight 00752 parseMirror $_cpointer 00753 } 00754 00755 ## ---------------------------------------------------------------------------- 00756 ## convert the current parse to an annotation. 00757 ## This is a straight delegation to parse2annotation(). 00758 ## ---------------------------------------------------------------------------- 00759 body Parse::toAnno {} { 00760 return [parse2annotation $_cpointer] 00761 } 00762

XCDG 0.95 (20 Oct 2004)