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

alllexemes.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 ## AllLexemes - manage the CDG lexicon. 00013 ## 00014 ## 00015 ## \author Michael Daum 00016 ## $Id: alllexemes.tcl,v 1.31 2004/10/11 13:50:05 micha Exp $ 00017 ## ---------------------------------------------------------------------------- 00018 class AllLexemes { 00019 inherit DataBrowser 00020 00021 00022 # public methods 00023 public method init_data {} 00024 public method getAllWords {} 00025 public method getCData {id}; ## \type TclString 00026 public method refreshrow {row lexeme}; ## \type TclNumber, LexiconItem 00027 00028 constructor {args} {}; ## \type TclList 00029 00030 # private methods 00031 private method _init_data {} 00032 private method displaybutton_action {} 00033 private method editbutton_action {} 00034 00035 00036 # private variables 00037 private variable lexemes; ## \type TclArray 00038 }; 00039 00040 ## ---------------------------------------------------------------------------- 00041 ## constructor 00042 ## ---------------------------------------------------------------------------- 00043 body AllLexemes::constructor {args} { 00044 set _idColumnIndex 0 00045 set table $itk_component(table) 00046 $table configure -cols 4 00047 00048 itk_component add displaybutton { 00049 button $itk_component(childsite).display\ 00050 -anchor w \ 00051 -text "Display" \ 00052 -command [code $this displaybutton_action] 00053 } { } 00054 00055 itk_component add editbutton { 00056 button $itk_component(childsite).edit\ 00057 -anchor w \ 00058 -text "Edit" \ 00059 -command [code $this editbutton_action] 00060 } { } 00061 00062 # packing 00063 pack \ 00064 $itk_component(displaybutton) \ 00065 $itk_component(editbutton) \ 00066 -side left -padx 3 00067 00068 # get the initial data 00069 _init_data 00070 00071 # register the helpmessages 00072 .cdgmain help sethelpstr \ 00073 $itk_component(table) \ 00074 "Click selects row, Ctrl-Click selects more rows, NW cell selects all" \ 00075 $itk_component(displaybutton) "Print out this lexeme in the shell" \ 00076 $itk_component(editbutton) "Call editor for this lexeme" 00077 00078 eval itk_initialize $args 00079 } 00080 00081 00082 00083 ## ---------------------------------------------------------------------------- 00084 ## call _init_data if necessary 00085 ## ---------------------------------------------------------------------------- 00086 body AllLexemes::init_data {} { 00087 00088 if {[InputStruct_xcdglexiconToDate_get [inputCurrentGrammar_get]]} { 00089 return 00090 } 00091 00092 .cdgmain busy compute "Init Lexemes" [code $this _init_data] 00093 00094 } 00095 00096 ## ---------------------------------------------------------------------------- 00097 ## get data from the cdg tool 00098 ## ---------------------------------------------------------------------------- 00099 body AllLexemes::_init_data {} { 00100 00101 set table $itk_component(table) 00102 $table configure -state normal 00103 $table clear all 00104 $table delete rows 1 [$table cget -rows] 00105 $table tag config default 00106 $table tag config colored -bg gray80 00107 $table setCell row 0,0 { "" "file" "form" } 00108 $table width 0 25 1 15 2 10 3 10 00109 00110 # prepare 00111 foreach id [array names lexemes] { 00112 unset lexemes($id) 00113 } 00114 00115 # import data to Tcl 00116 set lexicon [InputStruct_lexicon_get [inputCurrentGrammar_get]]] 00117 set lexiconIterator [hashIteratorNew $lexicon] 00118 00119 while {[set forms [hashIteratorNextValue $lexiconIterator]] != "NULL"} { 00120 for {set l $forms} { $l != "NULL" } { set l [listNext $l ] } { 00121 set entry [listElement $l] 00122 set id [LexiconItemStruct_description_get $entry] 00123 set lexemes($id) $entry 00124 } 00125 } 00126 00127 hashIteratorDelete $lexiconIterator 00128 _setCount [hashSize $lexicon] 00129 set r 1 00130 foreach id [lsort [array names lexemes]] { 00131 set lexeme $lexemes($id) 00132 refreshrow $r $lexeme 00133 incr r 00134 if {[expr $r % 500] == 0} { 00135 update 00136 } 00137 } 00138 00139 setSelection 00140 InputStruct_xcdglexiconToDate_set [inputCurrentGrammar_get] 1 00141 00142 $table configure -state disabled 00143 } 00144 00145 00146 ## ---------------------------------------------------------------------------- 00147 ## Wrapper to allow use of base class definition of refreshid 00148 ## ---------------------------------------------------------------------------- 00149 body AllLexemes::getCData {id} { 00150 return [getlexeme $id] 00151 } 00152 00153 00154 ## ---------------------------------------------------------------------------- 00155 ## fill a row with the values from a specific lexeme. 00156 ## ---------------------------------------------------------------------------- 00157 body AllLexemes::refreshrow {row lexeme} { 00158 set table $itk_component(table) 00159 # lexeme name 00160 set id [LexiconItemStruct_description_get $lexeme] 00161 00162 # base name of defining file 00163 regexp "\[^/\]*$" [LexiconItemStruct_filename_get $lexeme] basename 00164 00165 # form 00166 set form [LexiconItemStruct_word_get $lexeme] 00167 00168 $itk_component(table) setCell row $row,0 \ 00169 [list $id $basename $form ] 00170 00171 } 00172 00173 00174 ## ---------------------------------------------------------------------------- 00175 ## display the lexeme in the shell 00176 ## ---------------------------------------------------------------------------- 00177 body AllLexemes::displaybutton_action {} { 00178 foreach id $_selection { commandEval "lexicon $id" } 00179 } 00180 00181 ## ---------------------------------------------------------------------------- 00182 ## call editor for the declaration. 00183 ## ---------------------------------------------------------------------------- 00184 body AllLexemes::editbutton_action {} { 00185 00186 # avoid flickering 00187 if {$_selection == ""} return 00188 00189 # build list of filenames 00190 set target "" 00191 foreach id $_selection { 00192 00193 # I suppose most editors grok "+<linenum> file" nowadays... 00194 set lexeme $lexemes($id) 00195 set linenum [LexiconItemStruct_lineNo_get $lexeme] 00196 set filename [LexiconItemStruct_filename_get $lexeme] 00197 append target "+$linenum $filename " 00198 } 00199 00200 # build command line 00201 regsub -all "%f" "/bin/sh -c \"[.cdgmain cget -editor]\"" $target command 00202 00203 # execute 00204 if {[catch {eval exec $command >/dev/null &} errMsg]} { 00205 ::cmd::Puts "ERROR: $errMsg" 00206 } 00207 00208 } 00209 00210 00211 ## ---------------------------------------------------------------------------- 00212 ## Return list of all known words 00213 ## ---------------------------------------------------------------------------- 00214 body AllLexemes::getAllWords {} { 00215 init_data 00216 return [array names lexemes] 00217 }

XCDG 0.95 (20 Oct 2004)