« lib/WordNet/SenseRelate/Preprocess/Compounds.pm
↑ Summary
lib/WordNet/SenseRelate/Algorithm/Global.pm »
| 1 | #!/usr/local/bin/perl -w | ||
| 2 | # (Updated: $Id: disamb-gui.pl,v 1.7 2006/12/24 12:18:47 sidz1979 Exp $) | ||
| 3 | # | ||
| 4 | # disamb-gui.pl version 0.09 | ||
| 5 | # | ||
| 6 | # Program that reads in a Senseval-2 formatted lexical sample file, and | ||
| 7 | # disambiguates the instances using WordNet::SenseRelate::TargetWord. | ||
| 8 | # | ||
| 9 | # Copyright (c) 2005 | ||
| 10 | # | ||
| 11 | # Ted Pedersen, University of Minnesota, Duluth | ||
| 12 | # tpederse@d.umn.edu | ||
| 13 | # | ||
| 14 | # Satanjeev Banerjee, Carnegie Mellon University | ||
| 15 | # banerjee+@cs.cmu.edu | ||
| 16 | # | ||
| 17 | # Siddharth Patwardhan, University of Utah | ||
| 18 | # sidd@cs.utah.edu | ||
| 19 | # | ||
| 20 | # This program is free software; you can redistribute it and/or | ||
| 21 | # modify it under the terms of the GNU General Public License | ||
| 22 | # as published by the Free Software Foundation; either version 2 | ||
| 23 | # of the License, or (at your option) any later version. | ||
| 24 | # This program is distributed in the hope that it will be useful, | ||
| 25 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 26 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 27 | # GNU General Public License for more details. | ||
| 28 | # | ||
| 29 | # You should have received a copy of the GNU General Public License | ||
| 30 | # along with this program; if not, write to the Free Software | ||
| 31 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
| 32 | # | ||
| 33 | #----------------------------------------------------------------------------- | ||
| 34 | |||
| 35 | # Uses: | ||
| 36 | use strict; | ||
| 37 | use WordNet::SenseRelate::Reader::Senseval2; | ||
| 38 | use WordNet::SenseRelate::TargetWord; | ||
| 39 | use WordNet::SenseRelate::Tools; | ||
| 40 | use Getopt::Long; | ||
| 41 | use Gtk; | ||
| 42 | |||
| 43 | # Now get the options! | ||
| 44 | our ($opt_config, $opt_wnpath, $opt_help, $opt_version); | ||
| 45 | &GetOptions("config=s", "wnpath=s", "help", "version"); | ||
| 46 | |||
| 47 | # My global variables | ||
| 48 | my $VERSION = '0.09'; | ||
| 49 | my $options = {}; | ||
| 50 | my $lastDir = undef; | ||
| 51 | my $instanceData = undef; | ||
| 52 | my $wntools; | ||
| 53 | my $targetWord; | ||
| 54 | my $error; | ||
| 55 | my $esColor = {}; | ||
| 56 | my @warnings = (); | ||
| 57 | my %posMap = ('n' => 'NOUN', | ||
| 58 | 'v' => 'VERB', | ||
| 59 | 'a' => 'ADJECTIVE', | ||
| 60 | 'r' => 'ADVERB'); | ||
| 61 | my %moduleNames = ('PREPROCESS' => ['WordNet::SenseRelate::Preprocess::Compounds'], | ||
| 62 | 'POSTPROCESS' => [], | ||
| 63 | 'CONTEXT' => ['WordNet::SenseRelate::Context::NearestWords'], | ||
| 64 | 'ALGORITHM' => ['WordNet::SenseRelate::Algorithm::Local', | ||
| 65 | 'WordNet::SenseRelate::Algorithm::Global', | ||
| 66 | 'WordNet::SenseRelate::Algorithm::SenseOne', | ||
| 67 | 'WordNet::SenseRelate::Algorithm::Random']); | ||
| 68 | my %moduleOptions = ('WordNet::SenseRelate::Preprocess::Compounds' => {}, | ||
| 69 | 'WordNet::SenseRelate::Context::NearestWords' => {'contextpos' => 's!!0!!nvar', | ||
| 70 | 'windowsize' => 'i!!0!!5', | ||
| 71 | 'windowstop' => 'f!!0!!'}, | ||
| 72 | 'WordNet::SenseRelate::Algorithm::Local' => {'measure' => 'm!!0!!WordNet::Similarity::vector', | ||
| 73 | 'measureconfig' => 'f!!0!!'}, | ||
| 74 | 'WordNet::SenseRelate::Algorithm::Global' => {'measure' => 'm!!0!!WordNet::Similarity::vector', | ||
| 75 | 'measureconfig' => 'f!!0!!'}, | ||
| 76 | 'WordNet::SenseRelate::Algorithm::SenseOne' => {}, | ||
| 77 | 'WordNet::SenseRelate::Algorithm::Random' => {}); | ||
| 78 | |||
| 79 | # If help is requested | ||
| 80 | if (defined $opt_help) | ||
| 81 | { | ||
| 82 | &printHelp(); | ||
| 83 | exit; | ||
| 84 | } | ||
| 85 | |||
| 86 | # If version information is requested | ||
| 87 | if (defined $opt_version) | ||
| 88 | { | ||
| 89 | &printVersion(); | ||
| 90 | exit; | ||
| 91 | } | ||
| 92 | |||
| 93 | # Load configuration options, if config file specified. | ||
| 94 | # (Pop warning message box, if error reading config file) | ||
| 95 | # Else set up default configuration | ||
| 96 | if(defined $opt_config) | ||
| 97 | { | ||
| 98 | # Make all the options undefined first | ||
| 99 | $options = {}; | ||
| 100 | $options->{preprocess} = []; | ||
| 101 | $options->{preprocessconfig} = []; | ||
| 102 | $options->{postprocess} = []; | ||
| 103 | $options->{postprocessconfig} = []; | ||
| 104 | $options->{context} = undef; | ||
| 105 | $options->{contextconfig} = undef; | ||
| 106 | $options->{algorithm} = undef; | ||
| 107 | $options->{algorithmconfig} = undef; | ||
| 108 | $options->{wntools} = undef; | ||
| 109 | |||
| 110 | # Read the configuration file | ||
| 111 | my $optStruct = &readConfigFile($opt_config); | ||
| 112 | if (!defined $optStruct) | ||
| 113 | { | ||
| 114 | &askHelp("disamb.pl: Configuration file format error.\n"); | ||
| 115 | $options = {}; | ||
| 116 | } | ||
| 117 | else | ||
| 118 | { | ||
| 119 | # Now get the options from the options structure | ||
| 120 | # First, the preprocess modules and options | ||
| 121 | if (defined $optStruct->{'PREPROCESS'}) | ||
| 122 | { | ||
| 123 | foreach my $element (@{$optStruct->{'PREPROCESS'}}) | ||
| 124 | { | ||
| 125 | push(@{$options->{preprocess}}, $element->{'name'}); | ||
| 126 | delete $element->{'name'}; | ||
| 127 | push(@{$options->{preprocessconfig}}, $element); | ||
| 128 | } | ||
| 129 | } | ||
| 130 | |||
| 131 | # Next, the postprocess modules and options | ||
| 132 | if (defined $optStruct->{'POSTPROCESS'}) | ||
| 133 | { | ||
| 134 | foreach my $element (@{$optStruct->{'POSTPROCESS'}}) | ||
| 135 | { | ||
| 136 | push(@{$options->{postprocess}}, $element->{'name'}); | ||
| 137 | delete $element->{'name'}; | ||
| 138 | push(@{$options->{postprocessconfig}}, $element); | ||
| 139 | } | ||
| 140 | } | ||
| 141 | |||
| 142 | # Next, get the context selection module and options | ||
| 143 | if (defined $optStruct->{'CONTEXT'}) | ||
| 144 | { | ||
| 145 | |||
| 146 | # There should be only one context selection module specified | ||
| 147 | &askHelp("disamb.pl: Multiple context selection modules specified in configuration file. Using first.") | ||
| 148 | if (scalar(@{$optStruct->{'CONTEXT'}}) > 1); | ||
| 149 | |||
| 150 | # Get the context selection module name, and options | ||
| 151 | # If none are specified, the default will be used | ||
| 152 | my $element = shift(@{$optStruct->{'CONTEXT'}}); | ||
| 153 | if (defined $element && defined $element->{'name'}) | ||
| 154 | { | ||
| 155 | $options->{context} = $element->{'name'}; | ||
| 156 | delete $element->{'name'}; | ||
| 157 | $options->{contextconfig} = $element; | ||
| 158 | } | ||
| 159 | } | ||
| 160 | |||
| 161 | # Next, get the algorithm module and options | ||
| 162 | if (defined $optStruct->{'ALGORITHM'}) | ||
| 163 | { | ||
| 164 | |||
| 165 | # Only one algorithm module must be specified | ||
| 166 | &askHelp("disamb.pl: Multiple algorithm modules specified in configuration file. Using first.") | ||
| 167 | if (scalar(@{$optStruct->{'ALGORITHM'}}) > 1); | ||
| 168 | |||
| 169 | # Get the algorithm module name, and options | ||
| 170 | # If none are specified, then the default will be used | ||
| 171 | my $element = shift(@{$optStruct->{'ALGORITHM'}}); | ||
| 172 | if (defined $element && defined $element->{'name'}) | ||
| 173 | { | ||
| 174 | $options->{algorithm} = $element->{'name'}; | ||
| 175 | delete $element->{'name'}; | ||
| 176 | $options->{algorithmconfig} = $element; | ||
| 177 | } | ||
| 178 | } | ||
| 179 | } | ||
| 180 | } | ||
| 181 | |||
| 182 | # Load WordNet::SenseRelate::Tools... | ||
| 183 | # Exit with warning message, if unable to load... | ||
| 184 | print STDERR "Loading WordNet::SenseRelate::Tools... "; | ||
| 185 | $wntools = WordNet::SenseRelate::Tools->new($opt_wnpath); | ||
| 186 | if(!defined $wntools) | ||
| 187 | { | ||
| 188 | print STDERR "disamb-gui.pl: Unable to load WordNet::SenseRelate::Tools.\n"; | ||
| 189 | print STDERR "Type \'disamb-gui.pl --help\' for help.\n"; | ||
| 190 | exit; | ||
| 191 | } | ||
| 192 | print STDERR "done.\n"; | ||
| 193 | $options->{'wntools'} = $wntools; | ||
| 194 | |||
| 195 | # Load WordNet::SenseRelate::TargetWord... | ||
| 196 | # Exit with warning message, if unable to load... | ||
| 197 | print STDERR "Loading WordNet::SenseRelate::TargetWord... "; | ||
| 198 | ($targetWord, $error) = WordNet::SenseRelate::TargetWord->new($options, 1); | ||
| 199 | if (!defined $targetWord) | ||
| 200 | { | ||
| 201 | print STDERR "$error\n"; | ||
| 202 | exit; | ||
| 203 | } | ||
| 204 | print STDERR "done.\n"; | ||
| 205 | |||
| 206 | # Call "readXMLFile", if an argument was passed | ||
| 207 | if(scalar(@ARGV) > 0) | ||
| 208 | { | ||
| 209 | print STDERR "Reading XML data... "; | ||
| 210 | $instanceData = WordNet::SenseRelate::Reader::Senseval2->new($ARGV[0]); | ||
| 211 | &askHelp("Error reading XML file.") if(!defined $instanceData); | ||
| 212 | print STDERR "done.\n"; | ||
| 213 | } | ||
| 214 | |||
| 215 | # Initialize Gtk. | ||
| 216 | print STDERR "Starting interface... \n"; | ||
| 217 | set_locale Gtk; | ||
| 218 | init Gtk; | ||
| 219 | |||
| 220 | # Initialize colors | ||
| 221 | $esColor->{'red'} = 0xFFFF; | ||
| 222 | $esColor->{'green'} = 0xD000; | ||
| 223 | $esColor->{'blue'} = 0xD000; | ||
| 224 | my $cmap = Gtk::Gdk::Colormap->get_system(); | ||
| 225 | &askHelp("Couldn't allocate green color.") unless(defined($cmap->color_alloc($esColor))); | ||
| 226 | |||
| 227 | # Build the graphical user interface | ||
| 228 | # Create the main window... | ||
| 229 | my $window = Gtk::Window->new('toplevel'); | ||
| 230 | $window->set_usize(800, 515); | ||
| 231 | $window->set_policy(0, 0, 1); | ||
| 232 | #$window->set_resizable(0); | ||
| 233 | $window->signal_connect('destroy', sub{ Gtk->exit(0); }); | ||
| 234 | $window->set_title("WordNet::SenseRelate::TargetWord"); | ||
| 235 | $window->set_position('center'); | ||
| 236 | $window->border_width(0); | ||
| 237 | |||
| 238 | # Create a menubar | ||
| 239 | my @menu_items = ( { path => '/_File', | ||
| 240 | type => '<Branch>' }, | ||
| 241 | { path => '/File/_Open', | ||
| 242 | accelerator => '<control>O', | ||
| 243 | callback => \&readFileDialog }, | ||
| 244 | { path => '/File/_Setup', | ||
| 245 | accelerator => '<control>S', | ||
| 246 | callback => \&setupDialog }, | ||
| 247 | { path => '/File/sep1', | ||
| 248 | type => '<Separator>'}, | ||
| 249 | { path => '/File/E_xit', | ||
| 250 | callback => sub { Gtk->exit(0); } }, | ||
| 251 | { path => '/_Help', | ||
| 252 | type => '<Branch>' }, | ||
| 253 | { path => '/_Help/About', | ||
| 254 | callback => \&showAbout } ); | ||
| 255 | my $accel_group = new Gtk::AccelGroup(); | ||
| 256 | my $item_factory = new Gtk::ItemFactory('Gtk::MenuBar', '<main>', $accel_group); | ||
| 257 | $item_factory->create_items(@menu_items); | ||
| 258 | $window->add_accel_group($accel_group); | ||
| 259 | my $menubar = $item_factory->get_widget('<main>'); | ||
| 260 | $menubar->show(); | ||
| 261 | |||
| 262 | # Create a text input box | ||
| 263 | my $textBox = Gtk::Text->new(); | ||
| 264 | $textBox->set_usize(450, 200); | ||
| 265 | $textBox->set_editable(0); | ||
| 266 | $textBox->set_word_wrap(1); | ||
| 267 | $textBox->set_line_wrap(1); | ||
| 268 | $textBox->show(); | ||
| 269 | |||
| 270 | # Create the scrollbar | ||
| 271 | my $vscrollbar = Gtk::VScrollbar->new($textBox->vadj); | ||
| 272 | $vscrollbar->show(); | ||
| 273 | |||
| 274 | # Create a HBox | ||
| 275 | my $textHBox = Gtk::HBox->new(0, 0); | ||
| 276 | $textHBox->pack_end($vscrollbar, 0, 0, 0); | ||
| 277 | $textHBox->pack_end($textBox, 0, 0, 0); | ||
| 278 | $textHBox->show(); | ||
| 279 | |||
| 280 | # Create instance label | ||
| 281 | my $inLabel = Gtk::Label->new("Instance ID: \nLexical Element: \nAnswer: \nTarget part-of-speech:"); | ||
| 282 | $inLabel->set_justify('left'); | ||
| 283 | $inLabel->show(); | ||
| 284 | my $inFrame = Gtk::Frame->new(""); | ||
| 285 | $inFrame->add($inLabel); | ||
| 286 | $inFrame->show(); | ||
| 287 | |||
| 288 | # Create VBox for text and labels | ||
| 289 | my $instanceVBox = Gtk::VBox->new(0, 5); | ||
| 290 | $instanceVBox->pack_end($inFrame, 0, 0, 0); | ||
| 291 | $instanceVBox->pack_start($textHBox, 1, 1, 0); | ||
| 292 | $instanceVBox->show(); | ||
| 293 | |||
| 294 | # Create clist | ||
| 295 | my $clist = Gtk::CList->new_with_titles("Id", "Lexelt", "Target POS", " Answer"); | ||
| 296 | $clist->set_selection_mode('browse'); | ||
| 297 | $clist->set_column_justification(0, 'center'); | ||
| 298 | $clist->set_column_justification(1, 'center'); | ||
| 299 | $clist->set_column_justification(2, 'center'); | ||
| 300 | $clist->set_column_justification(3, 'left'); | ||
| 301 | $clist->set_column_width(0, 70); | ||
| 302 | $clist->set_column_width(1, 70); | ||
| 303 | $clist->set_column_width(2, 70); | ||
| 304 | $clist->set_column_width(3, 110); | ||
| 305 | $clist->column_titles_active(); | ||
| 306 | $clist->show(); | ||
| 307 | |||
| 308 | # Create a Scrolled Window for CList | ||
| 309 | my $scrolled_window = Gtk::ScrolledWindow->new(); | ||
| 310 | $scrolled_window->set_policy('automatic', 'always'); | ||
| 311 | $scrolled_window->add($clist); | ||
| 312 | $scrolled_window->show(); | ||
| 313 | |||
| 314 | # Create HBox for clist-window and text-vbox | ||
| 315 | my $readerHBox = Gtk::HBox->new(0, 0); | ||
| 316 | $readerHBox->pack_end($instanceVBox, 0, 0, 0); | ||
| 317 | $readerHBox->pack_start($scrolled_window, 1, 1, 0); | ||
| 318 | $readerHBox->show(); | ||
| 319 | |||
| 320 | # Create output Label | ||
| 321 | my $outLabel = Gtk::Label->new("Selected Sense: "); | ||
| 322 | $outLabel->set_justify('left'); | ||
| 323 | $outLabel->show(); | ||
| 324 | |||
| 325 | # Create output textbox | ||
| 326 | my $outText = Gtk::Text->new(); | ||
| 327 | $outText->set_usize(600, 50); | ||
| 328 | $outText->set_editable(0); | ||
| 329 | $outText->set_word_wrap(1); | ||
| 330 | $outText->set_line_wrap(1); | ||
| 331 | $outText->show(); | ||
| 332 | |||
| 333 | # Create VBox for output | ||
| 334 | my $outVBox = Gtk::VBox->new(0, 0); | ||
| 335 | $outVBox->pack_start($outLabel, 0, 0, 0); | ||
| 336 | $outVBox->pack_end($outText, 1, 1, 0); | ||
| 337 | $outVBox->show(); | ||
| 338 | |||
| 339 | # Create disambiguate button | ||
| 340 | my $disambBox = Gtk::Button->new("Disambiguate"); | ||
| 341 | $disambBox->show(); | ||
| 342 | |||
| 343 | # Create table for button | ||
| 344 | my $disambTable = Gtk::Table->new(3, 1, 1); | ||
| 345 | $disambTable->attach_defaults($disambBox, 0, 1, 1, 2); | ||
| 346 | $disambTable->show(); | ||
| 347 | |||
| 348 | # Create HBox for button and output | ||
| 349 | my $pHBox = Gtk::HBox->new(0, 0); | ||
| 350 | $pHBox->pack_start($disambTable, 0, 0, 0); | ||
| 351 | $pHBox->pack_end($outVBox, 1, 1, 0); | ||
| 352 | $pHBox->show(); | ||
| 353 | |||
| 354 | # Create frame | ||
| 355 | my $pFrame = Gtk::Frame->new("Process"); | ||
| 356 | $pFrame->add($pHBox); | ||
| 357 | $pFrame->show(); | ||
| 358 | |||
| 359 | # Create a VBox | ||
| 360 | my $vbox = Gtk::VBox->new(0, 5); | ||
| 361 | $vbox->pack_start($menubar, 0, 0, 0); | ||
| 362 | $vbox->pack_start($readerHBox, 1, 1, 0); | ||
| 363 | $vbox->pack_start($pFrame, 0, 0, 0); | ||
| 364 | $vbox->show(); | ||
| 365 | |||
| 366 | # Set up all the signals | ||
| 367 | $clist->signal_connect('select_row', \&displayInstanceData); | ||
| 368 | $disambBox->signal_connect('clicked', \&disambiguateInstance); | ||
| 369 | |||
| 370 | # Show the main window | ||
| 371 | $window->add($vbox); | ||
| 372 | $window->show(); | ||
| 373 | |||
| 374 | # Put the data onto the form | ||
| 375 | &refreshGUI($instanceData); | ||
| 376 | |||
| 377 | # Display warnings from startup, if any | ||
| 378 | &displayStartupWarnings(@warnings) if(scalar(@warnings)); | ||
| 379 | |||
| 380 | # Gtk event loop | ||
| 381 | main Gtk; | ||
| 382 | |||
| 383 | # Should never get here | ||
| 384 | exit; | ||
| 385 | |||
| 386 | # Create read Senseval file dialog | ||
| 387 | sub readFileDialog | ||
| 388 | { | ||
| 389 | my $fDialog = Gtk::FileSelection->new("Select Senseval2 Lexical Sample File"); | ||
| 390 | $fDialog->set_policy(0, 0, 1); | ||
| 391 | # $fDialog->set_resizable(0); | ||
| 392 | $fDialog->set_position('center'); | ||
| 393 | $fDialog->border_width(0); | ||
| 394 | $fDialog->set_modal(1); | ||
| 395 | $fDialog->set_filename($lastDir) if(defined $lastDir); | ||
| 396 | |||
| 397 | # Connect Signals | ||
| 398 | $fDialog->ok_button->signal_connect("clicked", \&fileSelect, $fDialog); | ||
| 399 | $fDialog->cancel_button->signal_connect("clicked", sub{ $fDialog->destroy(); }); | ||
| 400 | |||
| 401 | # Display it | ||
| 402 | $fDialog->show(); | ||
| 403 | } | ||
| 404 | |||
| 405 | # This function is a callback for the file | ||
| 406 | # selection dialog. This is where the filename | ||
| 407 | # selected by the user is determined. | ||
| 408 | sub fileSelect | ||
| 409 | { | ||
| 410 | # Get the parameters | ||
| 411 | my ($widget, $dialog) = @_; | ||
| 412 | my $file; | ||
| 413 | |||
| 414 | # The dialog pointer must be given | ||
| 415 | return if(!defined $dialog); | ||
| 416 | |||
| 417 | # Get the filename | ||
| 418 | $file = $dialog->get_filename(); | ||
| 419 | $lastDir = $file if(defined $file); | ||
| 420 | $lastDir =~ s|\/[^\/]*$||; | ||
| 421 | $lastDir .= "/"; | ||
| 422 | $dialog->destroy(); | ||
| 423 | |||
| 424 | # Read the file | ||
| 425 | $instanceData = &readXMLFile($file); | ||
| 426 | |||
| 427 | # Refresh the GUI with the new data && remove "Reading file... " window | ||
| 428 | &refreshGUI($instanceData); | ||
| 429 | } | ||
| 430 | |||
| 431 | # This method loads a Senseval2 formatted XML file | ||
| 432 | sub readXMLFile | ||
| 433 | { | ||
| 434 | my $fname = shift; | ||
| 435 | |||
| 436 | # Show message box "Unable to read XML file" if not defined $fname && return | ||
| 437 | if(!defined $fname) | ||
| 438 | { | ||
| 439 | &showMessageBox("Error", "Unable to read XML file."); | ||
| 440 | return; | ||
| 441 | } | ||
| 442 | |||
| 443 | # Show "Reading file... " window | ||
| 444 | my $messybox = Gtk::Window->new('dialog'); | ||
| 445 | $messybox->set_usize(400, 100); | ||
| 446 | $messybox->set_policy(0, 0, 1); | ||
| 447 | # $messybox->set_resizable(0); | ||
| 448 | $messybox->set_title("Information: Reading XML File... Please Wait."); | ||
| 449 | $messybox->set_position('center'); | ||
| 450 | $messybox->border_width(0); | ||
| 451 | $messybox->set_modal(1); | ||
| 452 | |||
| 453 | #my $mesLab = Gtk::Label->new("Reading XML file. Please Wait."); | ||
| 454 | #$mesLab->set_justify('left'); | ||
| 455 | #$mesLab->show(); | ||
| 456 | |||
| 457 | my $mesLab = Gtk::Text->new(); | ||
| 458 | $mesLab->set_usize(200, 50); | ||
| 459 | $mesLab->set_editable(0); | ||
| 460 | $mesLab->set_word_wrap(1); | ||
| 461 | $mesLab->set_line_wrap(1); | ||
| 462 | $mesLab->freeze(); | ||
| 463 | $mesLab->insert(undef, undef, undef, "Reading XML file. Please Wait."); | ||
| 464 | $mesLab->thaw(); | ||
| 465 | $mesLab->show(); | ||
| 466 | |||
| 467 | my $meshbox = Gtk::VBox->new(0, 20); | ||
| 468 | $meshbox->pack_start($mesLab, 0, 0, 0); | ||
| 469 | $meshbox->show(); | ||
| 470 | |||
| 471 | $messybox->add($meshbox); | ||
| 472 | $messybox->show_now(); | ||
| 473 | |||
| 474 | # Read the XML file | ||
| 475 | my $reader = WordNet::SenseRelate::Reader::Senseval2->new($fname); | ||
| 476 | |||
| 477 | # Remove "Reading file... " window, && Show message box of errors, if any, && return | ||
| 478 | $messybox->destroy(); | ||
| 479 | if(!defined $reader || !ref($reader)) | ||
| 480 | { | ||
| 481 | &showMessageBox("Error", "Error reading XML file."); | ||
| 482 | return; | ||
| 483 | } | ||
| 484 | |||
| 485 | return $reader; | ||
| 486 | } | ||
| 487 | |||
| 488 | # Refresh the GUI with new data | ||
| 489 | sub refreshGUI | ||
| 490 | { | ||
| 491 | my $reader = shift; | ||
| 492 | return if(!defined $reader); | ||
| 493 | |||
| 494 | # Freeze the CList. | ||
| 495 | $clist->freeze(); | ||
| 496 | |||
| 497 | # Empty the CList. | ||
| 498 | $clist->clear(); | ||
| 499 | |||
| 500 | # Iterate through the data structure and | ||
| 501 | # add the entries to the CList. | ||
| 502 | foreach my $index (0 .. $reader->instanceCount() - 1) | ||
| 503 | { | ||
| 504 | my $theInst = $reader->instance($index); | ||
| 505 | my $theID = ""; | ||
| 506 | $theID = $theInst->{id} if(defined $theInst->{id}); | ||
| 507 | my $theLexelt = ""; | ||
| 508 | $theLexelt = $theInst->{lexelt} if(defined $theInst->{lexelt}); | ||
| 509 | my $tPOS = "NOUN"; | ||
| 510 | $tPOS = $theInst->{targetpos} if(defined $theInst->{targetpos}); | ||
| 511 | $tPOS = $posMap{$theInst->{targetpos}} if(defined $theInst->{targetpos} && $theInst->{targetpos} =~ /^[nvar]$/); | ||
| 512 | my $answerkey = ""; | ||
| 513 | $answerkey = $theInst->{answer} if(defined $theInst->{answer}); | ||
| 514 | $clist->append($theID, $theLexelt, $tPOS, $answerkey); | ||
| 515 | } | ||
| 516 | |||
| 517 | # Thaw the CList for the changes to suddenly | ||
| 518 | # show up on screen. | ||
| 519 | $clist->thaw(); | ||
| 520 | } | ||
| 521 | |||
| 522 | # Display the instance data of selected row | ||
| 523 | sub displayInstanceData | ||
| 524 | { | ||
| 525 | my @selected = $clist->selection(); | ||
| 526 | return if(scalar(@selected) <= 0); | ||
| 527 | my $index = shift(@selected); | ||
| 528 | $textBox->freeze(); | ||
| 529 | |||
| 530 | my $selectedInstance = $instanceData->instance($index); | ||
| 531 | return if(!defined $selectedInstance); | ||
| 532 | |||
| 533 | # Delete all the text in there. | ||
| 534 | my $tLength = $textBox->get_length(); | ||
| 535 | $textBox->set_point($tLength); | ||
| 536 | $textBox->backward_delete($tLength); | ||
| 537 | |||
| 538 | foreach my $textindex (0 .. scalar(@{$selectedInstance->{text}}) - 1) | ||
| 539 | { | ||
| 540 | my $background = undef; | ||
| 541 | $background = $esColor if($textindex == $selectedInstance->{head}); | ||
| 542 | my $printedStuff = $selectedInstance->{text}->[$textindex]; | ||
| 543 | $printedStuff =~ s/^\s+//; | ||
| 544 | $printedStuff =~ s/\s+$//; | ||
| 545 | $printedStuff =~ s/\[[^\]]*\]//g; | ||
| 546 | $textBox->insert(undef, undef, $background, $printedStuff); | ||
| 547 | $textBox->insert(undef, undef, undef, " "); | ||
| 548 | } | ||
| 549 | |||
| 550 | $textBox->thaw(); | ||
| 551 | |||
| 552 | my $daID = ""; | ||
| 553 | $daID = $selectedInstance->{id} if(defined $selectedInstance->{id}); | ||
| 554 | my $daLexelt = ""; | ||
| 555 | $daLexelt = $selectedInstance->{lexelt} if(defined $selectedInstance->{lexelt}); | ||
| 556 | my $daAns = ""; | ||
| 557 | $daAns = $selectedInstance->{answer} if(defined $selectedInstance->{answer}); | ||
| 558 | my $daPos = "NOUN"; | ||
| 559 | $daPos = $selectedInstance->{targetpos} if(defined $selectedInstance->{targetpos}); | ||
| 560 | $daPos = $posMap{$selectedInstance->{targetpos}} if(defined $selectedInstance->{targetpos} && $selectedInstance->{targetpos} =~ /^[nvar]$/); | ||
| 561 | $inLabel->set_text("Instance ID: $daID\nLexical Element: $daLexelt\nAnswer: $daAns\nTarget part-of-speech: $daPos"); | ||
| 562 | } | ||
| 563 | |||
| 564 | # Disambiguate the current instance | ||
| 565 | sub disambiguateInstance | ||
| 566 | { | ||
| 567 | my @selected = $clist->selection(); | ||
| 568 | return if(scalar(@selected) <= 0); | ||
| 569 | my $index = shift(@selected); | ||
| 570 | |||
| 571 | my $traceWindow = Gtk::Window->new('dialog'); | ||
| 572 | $traceWindow->set_usize(500, 400); | ||
| 573 | $traceWindow->set_policy(0, 0, 1); | ||
| 574 | # $traceWindow->set_resizable(0); | ||
| 575 | $traceWindow->set_title("Trace Information: Disambiguating Instance..."); | ||
| 576 | $traceWindow->set_position('center'); | ||
| 577 | $traceWindow->border_width(0); | ||
| 578 | $traceWindow->set_modal(1); | ||
| 579 | |||
| 580 | my $traceBox = Gtk::Text->new(); | ||
| 581 | $traceBox->set_usize(480, 360); | ||
| 582 | $traceBox->set_editable(0); | ||
| 583 | $traceBox->set_word_wrap(1); | ||
| 584 | $traceBox->set_line_wrap(1); | ||
| 585 | $traceBox->show(); | ||
| 586 | |||
| 587 | my $tracebar = Gtk::VScrollbar->new($traceBox->vadj); | ||
| 588 | $tracebar->show(); | ||
| 589 | |||
| 590 | my $traceHBox = Gtk::HBox->new(0, 0); | ||
| 591 | $traceHBox->pack_end($tracebar, 0, 0, 0); | ||
| 592 | $traceHBox->pack_end($traceBox, 0, 0, 0); | ||
| 593 | $traceHBox->show(); | ||
| 594 | |||
| 595 | my $closeButton = Gtk::Button->new("Close"); | ||
| 596 | $closeButton->signal_connect('clicked', sub{ $traceWindow->destroy(); }); | ||
| 597 | $closeButton->set_sensitive(0); | ||
| 598 | $closeButton->show(); | ||
| 599 | |||
| 600 | my $closeTable = Gtk::Table->new(1, 7); | ||
| 601 | $closeTable->attach_defaults($closeButton, 3, 4, 0, 1); | ||
| 602 | $closeTable->show(); | ||
| 603 | |||
| 604 | my $traceVBox = Gtk::VBox->new(); | ||
| 605 | $traceVBox->pack_start($traceHBox, 0, 0, 0); | ||
| 606 | $traceVBox->pack_start($closeTable, 0, 0, 0); | ||
| 607 | $traceVBox->show(); | ||
| 608 | |||
| 609 | $traceWindow->add($traceVBox); | ||
| 610 | $traceWindow->show_now(); | ||
| 611 | |||
| 612 | my ($sense, $errorStr) = $targetWord->disambiguate($instanceData->instance($index)); | ||
| 613 | $traceBox->insert(undef, undef, undef, $targetWord->getTraceString()); | ||
| 614 | if(!defined $sense) | ||
| 615 | { | ||
| 616 | $traceWindow->destroy(); | ||
| 617 | &showMessageBox("Error", $errorStr); | ||
| 618 | return; | ||
| 619 | } | ||
| 620 | |||
| 621 | $outLabel->set_text("Selected sense: $sense"); | ||
| 622 | |||
| 623 | $outText->freeze(); | ||
| 624 | # Delete all the text in there. | ||
| 625 | my $tLength = $outText->get_length(); | ||
| 626 | $outText->set_point($tLength); | ||
| 627 | $outText->backward_delete($tLength); | ||
| 628 | $outText->insert(undef, undef, undef, $wntools->{wn}->querySense($sense, "glos")); | ||
| 629 | $outText->thaw(); | ||
| 630 | |||
| 631 | $traceWindow->set_title("Trace Information"); | ||
| 632 | $closeButton->set_sensitive(1); | ||
| 633 | $closeButton->show(); | ||
| 634 | $traceWindow->show(); | ||
| 635 | } | ||
| 636 | |||
| 637 | # General purpose message box | ||
| 638 | sub showMessageBox | ||
| 639 | { | ||
| 640 | my $title = shift; | ||
| 641 | my $message = shift; | ||
| 642 | return if(!defined $title || !defined $message); | ||
| 643 | my $mbox = Gtk::Window->new('dialog'); | ||
| 644 | $mbox->set_usize(400, 100); | ||
| 645 | $mbox->set_policy(0, 0, 1); | ||
| 646 | # $mbox->set_resizable(0); | ||
| 647 | $mbox->set_title($title); | ||
| 648 | $mbox->set_position('center'); | ||
| 649 | $mbox->border_width(0); | ||
| 650 | $mbox->set_modal(1); | ||
| 651 | |||
| 652 | my $mesLabel = Gtk::Label->new($message); | ||
| 653 | $mesLabel->show(); | ||
| 654 | |||
| 655 | my $okButton = Gtk::Button->new("Ok"); | ||
| 656 | $okButton->signal_connect('clicked', sub{ $mbox->destroy(); }); | ||
| 657 | $okButton->show(); | ||
| 658 | |||
| 659 | my $okTable = Gtk::Table->new(1, 5, 1); | ||
| 660 | $okTable->attach_defaults($okButton, 2, 3, 0, 1); | ||
| 661 | $okTable->show(); | ||
| 662 | |||
| 663 | my $mesBox = Gtk::VBox->new(0, 20); | ||
| 664 | $mesBox->pack_start($mesLabel, 0, 0, 0); | ||
| 665 | $mesBox->pack_start($okTable, 0, 0, 0); | ||
| 666 | $mesBox->show(); | ||
| 667 | |||
| 668 | $mbox->add($mesBox); | ||
| 669 | $mbox->show(); | ||
| 670 | } | ||
| 671 | |||
| 672 | # Create read setup options dialog | ||
| 673 | sub setupDialog | ||
| 674 | { | ||
| 675 | # Create the setup window | ||
| 676 | my $setupWindow = Gtk::Window->new('dialog'); | ||
| 677 | $setupWindow->set_usize(600, 350); | ||
| 678 | $setupWindow->set_policy(0, 0, 1); | ||
| 679 | $setupWindow->set_title("WordNet::SenseRelate::TargetWord Setup: Select Modules"); | ||
| 680 | $setupWindow->set_position('center'); | ||
| 681 | $setupWindow->border_width(0); | ||
| 682 | $setupWindow->set_modal(1); | ||
| 683 | |||
| 684 | my $prelist = Gtk::CList->new_with_titles("Preprocess Modules"); | ||
| 685 | $prelist->set_selection_mode('multiple'); | ||
| 686 | $prelist->set_column_justification(0, 'center'); | ||
| 687 | $prelist->set_column_width(0, 250); | ||
| 688 | $prelist->column_titles_passive(); | ||
| 689 | foreach my $mod (@{$moduleNames{'PREPROCESS'}}) | ||
| 690 | { | ||
| 691 | $prelist->append($mod); | ||
| 692 | } | ||
| 693 | $prelist->show(); | ||
| 694 | |||
| 695 | # Create a Scrolled Window for CList | ||
| 696 | my $scroll = Gtk::ScrolledWindow->new(); | ||
| 697 | $scroll->set_policy('automatic', 'always'); | ||
| 698 | $scroll->set_usize(300, 150); | ||
| 699 | $scroll->add($prelist); | ||
| 700 | $scroll->show(); | ||
| 701 | |||
| 702 | my $postlist = Gtk::CList->new_with_titles("Postprocess Modules"); | ||
| 703 | $postlist->set_selection_mode('extended'); | ||
| 704 | $postlist->set_column_justification(0, 'center'); | ||
| 705 | $postlist->set_column_width(0, 70); | ||
| 706 | $postlist->column_titles_passive(); | ||
| 707 | foreach my $mod (@{$moduleNames{'POSTPROCESS'}}) | ||
| 708 | { | ||
| 709 | $postlist->append($mod); | ||
| 710 | } | ||
| 711 | $postlist->show(); | ||
| 712 | |||
| 713 | # Create a Scrolled Window for CList | ||
| 714 | my $scroll2 = Gtk::ScrolledWindow->new(); | ||
| 715 | $scroll2->set_policy('automatic', 'always'); | ||
| 716 | $scroll2->set_usize(300,150); | ||
| 717 | $scroll2->add($postlist); | ||
| 718 | $scroll2->show(); | ||
| 719 | |||
| 720 | # Create HBox for clist-window and text-vbox | ||
| 721 | my $modHBox = Gtk::HBox->new(0, 0); | ||
| 722 | $modHBox->pack_start($scroll, 0, 0, 0); | ||
| 723 | $modHBox->pack_start($scroll2, 1, 1, 0); | ||
| 724 | $modHBox->show(); | ||
| 725 | |||
| 726 | my $conlist = Gtk::CList->new_with_titles("Context Modules"); | ||
| 727 | $conlist->set_selection_mode('browse'); | ||
| 728 | $conlist->set_column_justification(0, 'center'); | ||
| 729 | $conlist->column_titles_passive(); | ||
| 730 | foreach my $mod (@{$moduleNames{'CONTEXT'}}) | ||
| 731 | { | ||
| 732 | $conlist->append($mod); | ||
| 733 | } | ||
| 734 | $conlist->show(); | ||
| 735 | |||
| 736 | # Create a Scrolled Window for CList | ||
| 737 | my $scroll3 = Gtk::ScrolledWindow->new(); | ||
| 738 | $scroll3->set_policy('automatic', 'always'); | ||
| 739 | $scroll3->set_usize(300, 150); | ||
| 740 | $scroll3->add($conlist); | ||
| 741 | $scroll3->show(); | ||
| 742 | |||
| 743 | my $algolist = Gtk::CList->new_with_titles("Algorithm Modules"); | ||
| 744 | $algolist->set_selection_mode('browse'); | ||
| 745 | $algolist->set_column_justification(0, 'center'); | ||
| 746 | $algolist->column_titles_passive(); | ||
| 747 | foreach my $mod (@{$moduleNames{'ALGORITHM'}}) | ||
| 748 | { | ||
| 749 | $algolist->append($mod); | ||
| 750 | } | ||
| 751 | $algolist->show(); | ||
| 752 | |||
| 753 | # Create a Scrolled Window for CList | ||
| 754 | my $scroll4 = Gtk::ScrolledWindow->new(); | ||
| 755 | $scroll4->set_policy('automatic', 'always'); | ||
| 756 | $scroll4->set_usize(300,150); | ||
| 757 | $scroll4->add($algolist); | ||
| 758 | $scroll4->show(); | ||
| 759 | |||
| 760 | # Create HBox for clist-window and text-vbox | ||
| 761 | my $modHBox2 = Gtk::HBox->new(0, 0); | ||
| 762 | $modHBox2->pack_start($scroll3, 0, 0, 0); | ||
| 763 | $modHBox2->pack_start($scroll4, 1, 1, 0); | ||
| 764 | $modHBox2->show(); | ||
| 765 | |||
| 766 | my $canButton = Gtk::Button->new("Cancel"); | ||
| 767 | $canButton->show(); | ||
| 768 | $canButton->signal_connect('clicked', sub{ $setupWindow->destroy(); }); | ||
| 769 | my $nextButton = Gtk::Button->new("Next >"); | ||
| 770 | $nextButton->show(); | ||
| 771 | $nextButton->signal_connect('clicked', \&setupModuleOptions, $setupWindow, $prelist, $postlist, $conlist, $algolist); | ||
| 772 | |||
| 773 | my $cTable = Gtk::Table->new(1, 5); | ||
| 774 | $cTable->attach_defaults($canButton, 1, 2, 0, 1); | ||
| 775 | $cTable->attach_defaults($nextButton, 3, 4, 0, 1); | ||
| 776 | $cTable->show(); | ||
| 777 | |||
| 778 | # Create VBox for clist-window and text-vbox | ||
| 779 | my $modVBox = Gtk::VBox->new(0, 0); | ||
| 780 | $modVBox->pack_start($modHBox, 0, 0, 0); | ||
| 781 | $modVBox->pack_start($modHBox2, 1, 1, 0); | ||
| 782 | $modVBox->pack_end($cTable, 0, 0, 0); | ||
| 783 | $modVBox->show(); | ||
| 784 | |||
| 785 | $setupWindow->add($modVBox); | ||
| 786 | $setupWindow->show(); | ||
| 787 | } | ||
| 788 | |||
| 789 | sub setupModuleOptions | ||
| 790 | { | ||
| 791 | my $widget = shift; | ||
| 792 | my $prevWindow = shift; | ||
| 793 | my $prelist = shift; | ||
| 794 | my $postlist = shift; | ||
| 795 | my $conlist = shift; | ||
| 796 | my $algolist = shift; | ||
| 797 | |||
| 798 | my @preMods = (); | ||
| 799 | my @postMods = (); | ||
| 800 | my @conMod = (); | ||
| 801 | my @algoMod = (); | ||
| 802 | my %codes = ('i' => 'Integer', | ||
| 803 | 'f' => 'File Name', | ||
| 804 | 's' => 'String', | ||
| 805 | 'm' => 'Module Name'); | ||
| 806 | |||
| 807 | @preMods = $prelist->selection() if(defined $prelist); | ||
| 808 | @postMods = $postlist->selection() if(defined $postlist); | ||
| 809 | @conMod = $conlist->selection() if(defined $conlist); | ||
| 810 | @algoMod = $algolist->selection() if(defined $algolist); | ||
| 811 | |||
| 812 | $prevWindow->destroy(); | ||
| 813 | |||
| 814 | my $setupWindow = Gtk::Window->new('dialog'); | ||
| 815 | $setupWindow->set_usize(700, 350); | ||
| 816 | $setupWindow->set_policy(0, 0, 1); | ||
| 817 | $setupWindow->set_title("WordNet::SenseRelate::TargetWord Setup: Select Module Options"); | ||
| 818 | $setupWindow->set_position('center'); | ||
| 819 | $setupWindow->border_width(0); | ||
| 820 | $setupWindow->set_modal(1); | ||
| 821 | |||
| 822 | my $modVBox = Gtk::VBox->new(0, 0); | ||
| 823 | |||
| 824 | my %textboxHash; | ||
| 825 | my $moduleList = {preprocess => [], | ||
| 826 | postprocess => [], | ||
| 827 | context => undef, | ||
| 828 | algorithm => undef}; | ||
| 829 | |||
| 830 | foreach my $presel (@preMods) | ||
| 831 | { | ||
| 832 | my $mName = $moduleNames{'PREPROCESS'}->[$presel]; | ||
| 833 | push(@{$moduleList->{preprocess}}, $mName); | ||
| 834 | foreach my $oName (keys(%{$moduleOptions{$mName}})) | ||
| 835 | { | ||
| 836 | my $theCode = $moduleOptions{$mName}->{$oName}; | ||
| 837 | my ($typo, $reqd, $defval) = split(/!!/, $theCode); | ||
| 838 | my $label = Gtk::Label->new("$mName $oName ($codes{$typo}, ".(($reqd)?(""):("Not "))."Required) "); | ||
| 839 | $label->show(); | ||
| 840 | my $tbox = Gtk::Entry->new(); | ||
| 841 | $tbox->set_text($defval) if(defined $defval && $defval ne ""); | ||
| 842 | $tbox->show(); | ||
| 843 | $textboxHash{$mName}{$oName} = $tbox; | ||
| 844 | my $hhbox = Gtk::HBox->new(0, 0); | ||
| 845 | $hhbox->pack_start($label, 0, 0, 0); | ||
| 846 | $hhbox->pack_end($tbox, 1, 1, 0); | ||
| 847 | $hhbox->show(); | ||
| 848 | $modVBox->pack_start($hhbox, 0, 0, 0); | ||
| 849 | } | ||
| 850 | } | ||
| 851 | |||
| 852 | foreach my $postsel (@postMods) | ||
| 853 | { | ||
| 854 | my $mName = $moduleNames{'POSTPROCESS'}->[$postsel]; | ||
| 855 | push(@{$moduleList->{postprocess}}, $mName); | ||
| 856 | foreach my $oName (keys(%{$moduleOptions{$mName}})) | ||
| 857 | { | ||
| 858 | my $theCode = $moduleOptions{$mName}->{$oName}; | ||
| 859 | my ($typo, $reqd, $defval) = split(/!!/, $theCode); | ||
| 860 | my $label = Gtk::Label->new("$mName $oName ($codes{$typo}, ".(($reqd)?(""):("Not "))."Required) "); | ||
| 861 | $label->show(); | ||
| 862 | my $tbox = Gtk::Entry->new(); | ||
| 863 | $tbox->set_text($defval) if(defined $defval && $defval ne ""); | ||
| 864 | $tbox->show(); | ||
| 865 | $textboxHash{$mName}{$oName} = $tbox; | ||
| 866 | my $hhbox = Gtk::HBox->new(0, 0); | ||
| 867 | $hhbox->pack_start($label, 0, 0, 0); | ||
| 868 | $hhbox->pack_end($tbox, 1, 1, 0); | ||
| 869 | $hhbox->show(); | ||
| 870 | $modVBox->pack_start($hhbox, 0, 0, 0); | ||
| 871 | } | ||
| 872 | } | ||
| 873 | |||
| 874 | my $consel = shift(@conMod); | ||
| 875 | if(defined $consel && $consel ne "") | ||
| 876 | { | ||
| 877 | my $mName = $moduleNames{'CONTEXT'}->[$consel]; | ||
| 878 | $moduleList->{context} = $mName; | ||
| 879 | foreach my $oName (keys(%{$moduleOptions{$mName}})) | ||
| 880 | { | ||
| 881 | my $theCode = $moduleOptions{$mName}->{$oName}; | ||
| 882 | my ($typo, $reqd, $defval) = split(/!!/, $theCode); | ||
| 883 | my $label = Gtk::Label->new("$mName $oName ($codes{$typo}, ".(($reqd)?(""):("Not "))."Required) "); | ||
| 884 | $label->show(); | ||
| 885 | my $tbox = Gtk::Entry->new(); | ||
| 886 | $tbox->set_text($defval) if(defined $defval && $defval ne ""); | ||
| 887 | $tbox->show(); | ||
| 888 | $textboxHash{$mName}{$oName} = $tbox; | ||
| 889 | my $hhbox = Gtk::HBox->new(0, 0); | ||
| 890 | $hhbox->pack_start($label, 0, 0, 0); | ||
| 891 | $hhbox->pack_end($tbox, 1, 1, 0); | ||
| 892 | $hhbox->show(); | ||
| 893 | $modVBox->pack_start($hhbox, 0, 0, 0); | ||
| 894 | } | ||
| 895 | } | ||
| 896 | |||
| 897 | my $algosel = shift(@algoMod); | ||
| 898 | if(defined $algosel && $algosel ne "") | ||
| 899 | { | ||
| 900 | my $mName = $moduleNames{'ALGORITHM'}->[$algosel]; | ||
| 901 | $moduleList->{algorithm} = $mName; | ||
| 902 | foreach my $oName (keys(%{$moduleOptions{$mName}})) | ||
| 903 | { | ||
| 904 | my $theCode = $moduleOptions{$mName}->{$oName}; | ||
| 905 | my ($typo, $reqd, $defval) = split(/!!/, $theCode); | ||
| 906 | my $label = Gtk::Label->new("$mName $oName ($codes{$typo}, ".(($reqd)?(""):("Not "))."Required) "); | ||
| 907 | $label->show(); | ||
| 908 | my $tbox = Gtk::Entry->new(); | ||
| 909 | $tbox->set_text($defval) if(defined $defval && $defval ne ""); | ||
| 910 | $tbox->show(); | ||
| 911 | $textboxHash{$mName}{$oName} = $tbox; | ||
| 912 | my $hhbox = Gtk::HBox->new(0, 0); | ||
| 913 | $hhbox->pack_start($label, 0, 0, 0); | ||
| 914 | $hhbox->pack_end($tbox, 1, 1, 0); | ||
| 915 | $hhbox->show(); | ||
| 916 | $modVBox->pack_start($hhbox, 0, 0, 0); | ||
| 917 | } | ||
| 918 | } | ||
| 919 | |||
| 920 | my $canButton = Gtk::Button->new("Cancel"); | ||
| 921 | $canButton->show(); | ||
| 922 | $canButton->signal_connect('clicked', sub{ $setupWindow->destroy(); }); | ||
| 923 | my $nextButton = Gtk::Button->new("Next >"); | ||
| 924 | $nextButton->show(); | ||
| 925 | $nextButton->signal_connect('clicked', \&getOptionsFromFields, $setupWindow, $moduleList, \%textboxHash); | ||
| 926 | |||
| 927 | my $cTable = Gtk::Table->new(1, 5); | ||
| 928 | $cTable->attach_defaults($canButton, 1, 2, 0, 1); | ||
| 929 | $cTable->attach_defaults($nextButton, 3, 4, 0, 1); | ||
| 930 | $cTable->show(); | ||
| 931 | |||
| 932 | # Create VBox for clist-window and text-vbox | ||
| 933 | $modVBox->pack_end($cTable, 0, 0, 0); | ||
| 934 | $modVBox->show(); | ||
| 935 | |||
| 936 | $setupWindow->add($modVBox); | ||
| 937 | $setupWindow->show(); | ||
| 938 | } | ||
| 939 | |||
| 940 | sub getOptionsFromFields | ||
| 941 | { | ||
| 942 | my $widget = shift; | ||
| 943 | my $prevWindow = shift; | ||
| 944 | my $modList = shift; | ||
| 945 | my $textList = shift; | ||
| 946 | |||
| 947 | $modList->{preprocessconfig} = []; | ||
| 948 | $modList->{postprocessconfig} = []; | ||
| 949 | $modList->{contextconfig} = undef; | ||
| 950 | $modList->{algorithmconfig} = undef; | ||
| 951 | $modList->{wntools} = $wntools; | ||
| 952 | |||
| 953 | foreach my $premod ($modList->{preprocess}) | ||
| 954 | { | ||
| 955 | my $modOptions = {}; | ||
| 956 | if(exists $textList->{$premod}) | ||
| 957 | { | ||
| 958 | foreach my $theopt (keys %{$textList->{$premod}}) | ||
| 959 | { | ||
| 960 | my $theText = $textList->{$premod}->{$theopt}->get_text(); | ||
| 961 | $modOptions->{$theopt} = $theText if(defined $theText && $theText ne ""); | ||
| 962 | } | ||
| 963 | } | ||
| 964 | push(@{$modList->{preprocessconfig}}, $modOptions); | ||
| 965 | } | ||
| 966 | |||
| 967 | foreach my $premod ($modList->{postprocess}) | ||
| 968 | { | ||
| 969 | my $modOptions = {}; | ||
| 970 | if(exists $textList->{$premod}) | ||
| 971 | { | ||
| 972 | foreach my $theopt (keys %{$textList->{$premod}}) | ||
| 973 | { | ||
| 974 | my $theText = $textList->{$premod}->{$theopt}->get_text(); | ||
| 975 | $modOptions->{$theopt} = $theText if(defined $theText && $theText ne ""); | ||
| 976 | } | ||
| 977 | } | ||
| 978 | push(@{$modList->{postprocessconfig}}, $modOptions); | ||
| 979 | } | ||
| 980 | |||
| 981 | my $conmod = $modList->{context}; | ||
| 982 | if(defined $conmod && $conmod ne "") | ||
| 983 | { | ||
| 984 | my $modOptions = {}; | ||
| 985 | if(exists $textList->{$conmod}) | ||
| 986 | { | ||
| 987 | foreach my $theopt (keys %{$textList->{$conmod}}) | ||
| 988 | { | ||
| 989 | my $theText = $textList->{$conmod}->{$theopt}->get_text(); | ||
| 990 | $modOptions->{$theopt} = $theText if(defined $theText && $theText ne ""); | ||
| 991 | } | ||
| 992 | } | ||
| 993 | $modList->{contextconfig} = $modOptions; | ||
| 994 | } | ||
| 995 | |||
| 996 | $conmod = $modList->{algorithm}; | ||
| 997 | if(defined $conmod && $conmod ne "") | ||
| 998 | { | ||
| 999 | my $modOptions = {}; | ||
| 1000 | if(exists $textList->{$conmod}) | ||
| 1001 | { | ||
| 1002 | foreach my $theopt (keys %{$textList->{$conmod}}) | ||
| 1003 | { | ||
| 1004 | my $theText = $textList->{$conmod}->{$theopt}->get_text(); | ||
| 1005 | $modOptions->{$theopt} = $theText if(defined $theText && $theText ne ""); | ||
| 1006 | } | ||
| 1007 | } | ||
| 1008 | $modList->{algorithmconfig} = $modOptions; | ||
| 1009 | } | ||
| 1010 | |||
| 1011 | $prevWindow->destroy(); | ||
| 1012 | |||
| 1013 | # Load WordNet::SenseRelate::TargetWord... | ||
| 1014 | # Exit with warning message, if unable to load... | ||
| 1015 | # Show "Loading TargetWord... " window | ||
| 1016 | my $messybox = Gtk::Window->new('dialog'); | ||
| 1017 | $messybox->set_usize(400, 100); | ||
| 1018 | $messybox->set_policy(0, 0, 1); | ||
| 1019 | # $messybox->set_resizable(0); | ||
| 1020 | $messybox->set_title("Information: Reloading WordNet::SenseRelate::TargetWord... Please Wait."); | ||
| 1021 | $messybox->set_position('center'); | ||
| 1022 | $messybox->border_width(0); | ||
| 1023 | $messybox->set_modal(1); | ||
| 1024 | |||
| 1025 | #my $mesLab = Gtk::Label->new("Reading XML file. Please Wait."); | ||
| 1026 | #$mesLab->set_justify('left'); | ||
| 1027 | #$mesLab->show(); | ||
| 1028 | |||
| 1029 | my $mesLab = Gtk::Text->new(); | ||
| 1030 | $mesLab->set_usize(200, 50); | ||
| 1031 | $mesLab->set_editable(0); | ||
| 1032 | $mesLab->set_word_wrap(1); | ||
| 1033 | $mesLab->set_line_wrap(1); | ||
| 1034 | $mesLab->freeze(); | ||
| 1035 | $mesLab->insert(undef, undef, undef, "Reloading WordNet::SenseRelate::TargetWord. Please Wait."); | ||
| 1036 | $mesLab->thaw(); | ||
| 1037 | $mesLab->show(); | ||
| 1038 | |||
| 1039 | my $meshbox = Gtk::VBox->new(0, 20); | ||
| 1040 | $meshbox->pack_start($mesLab, 0, 0, 0); | ||
| 1041 | $meshbox->show(); | ||
| 1042 | |||
| 1043 | $messybox->add($meshbox); | ||
| 1044 | $messybox->show_now(); | ||
| 1045 | |||
| 1046 | my ($newTargetWord, $newError) = WordNet::SenseRelate::TargetWord->new($modList, 1); | ||
| 1047 | |||
| 1048 | # Remove "Reloading... " window, && Show message box of errors, if any, && return | ||
| 1049 | $messybox->destroy(); | ||
| 1050 | if(!defined $newTargetWord || !ref($newTargetWord)) | ||
| 1051 | { | ||
| 1052 | &showMessageBox("Error", "Error loading module: $newError"); | ||
| 1053 | return; | ||
| 1054 | } | ||
| 1055 | |||
| 1056 | $targetWord = $newTargetWord; | ||
| 1057 | } | ||
| 1058 | |||
| 1059 | # Create Help->About window | ||
| 1060 | sub showAbout | ||
| 1061 | { | ||
| 1062 | # Create the about window | ||
| 1063 | my $about = Gtk::Window->new('dialog'); | ||
| 1064 | $about->set_usize(360, 250); | ||
| 1065 | $about->set_policy(0, 0, 1); | ||
| 1066 | $about->set_title("About WordNet::SenseRelate::TargetWord"); | ||
| 1067 | $about->set_position('center'); | ||
| 1068 | $about->border_width(0); | ||
| 1069 | $about->set_modal(1); | ||
| 1070 | |||
| 1071 | # Create a TextBox | ||
| 1072 | my $aboutText = Gtk::Text->new(); | ||
| 1073 | $aboutText->set_editable(0); | ||
| 1074 | $aboutText->set_word_wrap(1); | ||
| 1075 | $aboutText->set_line_wrap(1); | ||
| 1076 | $aboutText->set_usize(360, 220); | ||
| 1077 | my $name = "-misc-fixed-bold-r-normal--15-140-75-75-c-90-iso8859-1"; | ||
| 1078 | my $fixed_font = Gtk::Gdk::Font->load($name); | ||
| 1079 | $aboutText->insert($fixed_font, undef, undef, "\n WordNet::SenseRelate::TargetWord\n\n"); | ||
| 1080 | $name = "-misc-fixed-medium-r-normal--14-130-75-75-c-70-iso8859-1"; | ||
| 1081 | $fixed_font = Gtk::Gdk::Font->load($name); | ||
| 1082 | $aboutText->insert($fixed_font, undef, undef, " v$VERSION\n"); | ||
| 1083 | $aboutText->insert($fixed_font, undef, undef, " Copyright (c) 2005\n\n"); | ||
| 1084 | $aboutText->insert($fixed_font, undef, undef, " Ted Pedersen\n"); | ||
| 1085 | $aboutText->insert($fixed_font, undef, undef, " tpederse\@d.umn.edu\n\n"); | ||
| 1086 | $aboutText->insert($fixed_font, undef, undef, " Siddharth Patwardhan\n"); | ||
| 1087 | $aboutText->insert($fixed_font, undef, undef, " sidd\@cs.utah.edu\n\n"); | ||
| 1088 | $aboutText->insert($fixed_font, undef, undef, " Satanjeev Banerjee\n"); | ||
| 1089 | $aboutText->insert($fixed_font, undef, undef, " banerjee+\@cs.cmu.edu\n"); | ||
| 1090 | $aboutText->show(); | ||
| 1091 | |||
| 1092 | # Create a close Button | ||
| 1093 | my $aboutButton = Gtk::Button->new("Close"); | ||
| 1094 | $aboutButton->signal_connect('clicked', sub{ $about->destroy(); }); | ||
| 1095 | $aboutButton->show(); | ||
| 1096 | |||
| 1097 | # Create a VBox | ||
| 1098 | my $aboutVBox = Gtk::VBox->new(0, 5); | ||
| 1099 | $aboutVBox->pack_start($aboutText, 0, 0, 0); | ||
| 1100 | $aboutVBox->pack_start($aboutButton, 0, 0, 0); | ||
| 1101 | $aboutVBox->show(); | ||
| 1102 | |||
| 1103 | # Display it | ||
| 1104 | $about->add($aboutVBox); | ||
| 1105 | $about->show(); | ||
| 1106 | } | ||
| 1107 | |||
| 1108 | # Show startup warnings | ||
| 1109 | sub displayStartupWarnings | ||
| 1110 | { | ||
| 1111 | return if(scalar(@_) <= 0); | ||
| 1112 | my $mbox = Gtk::Window->new('dialog'); | ||
| 1113 | $mbox->set_usize(400, 150); | ||
| 1114 | $mbox->set_policy(0, 0, 1); | ||
| 1115 | # $mbox->set_resizable(0); | ||
| 1116 | $mbox->set_title("Warning(s)"); | ||
| 1117 | $mbox->set_position('center'); | ||
| 1118 | $mbox->border_width(0); | ||
| 1119 | $mbox->set_modal(1); | ||
| 1120 | |||
| 1121 | my $message = "Warning(s):\n".(join("\n", @_))."\n"; | ||
| 1122 | my $mesLabel = Gtk::Label->new($message); | ||
| 1123 | $mesLabel->show(); | ||
| 1124 | |||
| 1125 | my $okButton = Gtk::Button->new("Ok"); | ||
| 1126 | $okButton->signal_connect('clicked', sub{ $mbox->destroy(); }); | ||
| 1127 | $okButton->show(); | ||
| 1128 | |||
| 1129 | my $okTable = Gtk::Table->new(1, 5, 1); | ||
| 1130 | $okTable->attach_defaults($okButton, 2, 3, 0, 1); | ||
| 1131 | $okTable->show(); | ||
| 1132 | |||
| 1133 | my $mesBox = Gtk::VBox->new(0, 20); | ||
| 1134 | $mesBox->pack_start($mesLabel, 0, 0, 0); | ||
| 1135 | $mesBox->pack_start($okTable, 0, 0, 0); | ||
| 1136 | $mesBox->show(); | ||
| 1137 | |||
| 1138 | $mbox->add($mesBox); | ||
| 1139 | $mbox->show(); | ||
| 1140 | } | ||
| 1141 | |||
| 1142 | # Subroutine that reads the options file | ||
| 1143 | sub readConfigFile | ||
| 1144 | { | ||
| 1145 | my $fname = shift; | ||
| 1146 | |||
| 1147 | if(!open(CONFIG, "$fname")) | ||
| 1148 | { | ||
| 1149 | &askHelp("disamb-gui.pl: Unable to open specified configuration file."); | ||
| 1150 | return undef; | ||
| 1151 | } | ||
| 1152 | my $line = <CONFIG>; | ||
| 1153 | $line =~ s/[\r\f\n]//; | ||
| 1154 | $line =~ s/^\s+//; | ||
| 1155 | $line =~ s/\s+$//; | ||
| 1156 | if ($line !~ /^WordNet::SenseRelate::TargetWord$/) | ||
| 1157 | { | ||
| 1158 | &askHelp("disamb.pl: File format error (in header) in config file."); | ||
| 1159 | return undef; | ||
| 1160 | } | ||
| 1161 | my $struct = {}; | ||
| 1162 | my $section = ""; | ||
| 1163 | my $modname = ""; | ||
| 1164 | my $modata = undef; | ||
| 1165 | |||
| 1166 | while ($line = <CONFIG>) | ||
| 1167 | { | ||
| 1168 | $line =~ s/[\r\f\n]//; | ||
| 1169 | $line =~ s/\#.*//; | ||
| 1170 | $line =~ s/^\s+//; | ||
| 1171 | $line =~ s/\s+$//; | ||
| 1172 | if ($line =~ /\[SECTION:([^\]]*)\]/) | ||
| 1173 | { | ||
| 1174 | $section = $1; | ||
| 1175 | $struct->{$section} = [] | ||
| 1176 | if ( defined $section | ||
| 1177 | && $section ne "" | ||
| 1178 | && !exists($struct->{$section})); | ||
| 1179 | } | ||
| 1180 | elsif ($line =~ /\[START\s+([^\]]+)\]/) | ||
| 1181 | { | ||
| 1182 | return undef if (!defined $section || $section eq ""); | ||
| 1183 | $modname = $1; | ||
| 1184 | $modata = {}; | ||
| 1185 | } | ||
| 1186 | elsif ($line =~ /\[END\]/) | ||
| 1187 | { | ||
| 1188 | return undef | ||
| 1189 | if ( !defined $section | ||
| 1190 | || $section eq "" | ||
| 1191 | || !defined $modname | ||
| 1192 | || $modname eq ""); | ||
| 1193 | return undef if (!defined $modata); | ||
| 1194 | $modata->{'name'} = $modname; | ||
| 1195 | push(@{$struct->{$section}}, $modata); | ||
| 1196 | $modname = ""; | ||
| 1197 | $modata = undef; | ||
| 1198 | } | ||
| 1199 | elsif ($line =~ /([^=]+)\s*=\s*([^=]+)/) | ||
| 1200 | { | ||
| 1201 | return undef | ||
| 1202 | if ( !defined $section | ||
| 1203 | || !defined $modname | ||
| 1204 | || $section eq "" | ||
| 1205 | || $modname eq ""); | ||
| 1206 | $modata->{$1} = $2; | ||
| 1207 | } | ||
| 1208 | elsif ($line ne "") | ||
| 1209 | { | ||
| 1210 | return undef; | ||
| 1211 | } | ||
| 1212 | } | ||
| 1213 | close(CONFIG); | ||
| 1214 | |||
| 1215 | return $struct; | ||
| 1216 | } | ||
| 1217 | |||
| 1218 | # function to output help messages for this program | ||
| 1219 | sub printHelp | ||
| 1220 | { | ||
| 1221 | print "Performs Word Sense Disambiguation on Senseval-2 lexical sample data\n"; | ||
| 1222 | print "(graphical interface to WordNet::SenseRelate::TargetWord).\n"; | ||
| 1223 | print "Usage: disamb-gui.pl [ [--config FILE] [--wnpath WNPATH] [XMLFILE] | --help | --version]\n"; | ||
| 1224 | print "--config Specifies a configuration file (FILE) to set up the\n"; | ||
| 1225 | print " various configuration options.\n"; | ||
| 1226 | print "--wnpath WNPATH specifies the path of the WordNet data files.\n"; | ||
| 1227 | print " Ordinarily, this path is determined from the \$WNHOME\n"; | ||
| 1228 | print " environment variable. But this option overides this\n"; | ||
| 1229 | print " behavior.\n"; | ||
| 1230 | print "--help Displays this help screen.\n"; | ||
| 1231 | print "--version Displays version information.\n\n"; | ||
| 1232 | } | ||
| 1233 | |||
| 1234 | # function to output "ask for help" message when the user's goofed up! | ||
| 1235 | sub askHelp | ||
| 1236 | { | ||
| 1237 | my $message = shift; | ||
| 1238 | push(@warnings, $message) if (defined $message && $message ne ""); | ||
| 1239 | } | ||
| 1240 | |||
| 1241 | # Subroutine to print the version information | ||
| 1242 | sub printVersion | ||
| 1243 | { | ||
| 1244 | print "disamb-gui.pl version $VERSION\n"; | ||
| 1245 | print "Copyright (c) 2005 Ted Pedersen, Satanjeev Banerjee, and Siddharth Patwardhan.\n"; | ||
| 1246 | } | ||
| 1247 | |||
| 1248 | __END__ |