Changeset 15872 for gsdl/trunk/perllib/plugins/GISExtractor.pm
- Timestamp:
- 2008-06-05T09:29:32+12:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gsdl/trunk/perllib/plugins/GISExtractor.pm
r15865 r15872 1 1 ########################################################################### 2 2 # 3 # GIS BasPlug.pm --base class to enhance plugins with GIS capabilities3 # GISExtractor.pm -- extension base class to enhance plugins with GIS capabilities 4 4 # A component of the Greenstone digital library software 5 5 # from the New Zealand Digital Library Project at the … … 24 24 ########################################################################### 25 25 26 package GISBasPlug; 26 package GISExtractor; 27 28 use PrintInfo; 27 29 28 30 use util; 29 use locale;30 31 31 32 use gsprintf 'gsprintf'; … … 33 34 no strict 'refs'; # allow filehandles to be variables and viceversa 34 35 no strict 'subs'; 36 35 37 #field categories in DataBase files 36 38 #$LAT = 3; … … 42 44 43 45 BEGIN { 44 die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'}; 45 } 46 47 48 use BasPlug; # uses BasPlug, but is not inherited 49 50 51 my $options = { 'name' => "GISBasPlug", 52 'desc' => "{GISBasPlug.desc}", 46 @GISExtractor::ISA = ('PrintInfo'); 47 } 48 49 50 my $arguments = 51 [ { 'name' => "extract_placenames", 52 'desc' => "{GISExtractor.extract_placenames}", 53 'type' => "flag", 54 'reqd' => "no" }, 55 { 'name' => "gazetteer", 56 'desc' => "{GISExtractor.gazetteer}", 57 'type' => "string", 58 'reqd' => "no" }, 59 { 'name' => "place_list", 60 'desc' => "{GISExtractor.place_list}", 61 'type' => "flag", 62 'reqd' => "no" } ]; 63 64 65 my $options = { 'name' => "GISExtractor", 66 'desc' => "{GISExtractor.desc}", 53 67 'abstract' => "yes", 54 'inherits' => "no" }; 68 'inherits' => "yes", 69 'args' => $arguments }; 55 70 56 71 57 72 sub new { 58 my $class = shift (@_); 59 my $plugin_name = shift (@_); 60 61 my $self = {}; 62 $self->{'plugin_type'} = "GISBasPlug"; 63 64 $self->{'option_list'} = [ $options ]; 73 my ($class) = shift (@_); 74 my ($pluginlist,$inputargs,$hashArgOptLists) = @_; 75 push(@$pluginlist, $class); 76 77 # can we indicate that these are not available if the map data is not there?? 78 #if (has_mapdata()) { 79 push(@{$hashArgOptLists->{"ArgList"}},@{$arguments}); 80 push(@{$hashArgOptLists->{"OptList"}},$options); 81 #} 82 my $self = new PrintInfo($pluginlist, $inputargs, $hashArgOptLists); 83 84 if ($self->{'extract_placenames'}) { 85 86 my $outhandle = $self->{'outhandle'}; 87 88 my $places_ref 89 = $self->loadGISDatabase($outhandle,$self->{'gazetteer'}); 90 91 if (!defined $places_ref) { 92 print $outhandle "Warning: Error loading mapdata gazetteer \"$self->{'gazetteer'}\"\n"; 93 print $outhandle " No placename extraction will take place.\n"; 94 $self->{'extract_placenames'} = undef; 95 } 96 else { 97 $self->{'places'} = $places_ref; 98 } 99 } 65 100 66 101 return bless $self, $class; 67 } 68 69 sub init { 70 } 71 72 sub print_xml_usage 102 103 } 104 105 106 sub extract_gis_metadata 73 107 { 74 BasPlug::print_xml_usage(@_); 75 } 76 77 sub print_xml 78 { 79 BasPlug::print_xml(@_); 80 } 81 82 sub print_txt_usage 83 { 84 BasPlug::print_txt_usage(@_); 85 } 86 87 sub determine_description_offset 88 { 89 BasPlug::determine_description_offset(@_); 90 } 91 sub print_plugin_usage 92 { 93 my $plugindesc = $options->{'desc'}; 94 95 if (defined($plugindesc)) { 96 gsprintf(STDERR, "$plugindesc\n\n"); 97 } 98 99 } 100 101 sub set_incremental 102 { 103 BasPlug::set_incremental(@_); 108 my $self = shift (@_); 109 my ($doc_obj) = @_; 110 111 if ($self->{'extract_placenames'}) { 112 my $thissection = $doc_obj->get_top_section(); 113 while (defined $thissection) { 114 my $text = $doc_obj->get_text($thissection); 115 $self->extract_placenames (\$text, $doc_obj, $thissection) if $text =~ /./; 116 $thissection = $doc_obj->get_next_section ($thissection); 117 } 118 } 119 104 120 } 105 121 … … 255 271 $doc_obj->associate_file($tempfile, "places.txt", "text/plain"); 256 272 $self->{'places_filename'} = $tempfile; 273 257 274 my %countries = (); 258 275 … … 283 300 284 301 #this line removes apostrophes from placenames (they break the javascript function) 285 $$textref =~ s/(javascript:popUp.*?)(\w)'(\w)/$1$2$3/g; 302 $$textref =~ s/(javascript:popUp.*?)(\w)'(\w)/$1$2$3/g; #' (to get emacs colours back) 286 303 287 304 #for displaying map of document, count num of places from each country … … 314 331 if ($self->{'verbosity'} > 2); 315 332 } 333 334 sub clean_up_temp_files { 335 my $self = shift(@_); 336 337 if(defined($self->{'places_filename'}) && -e $self->{'places_filename'}){ 338 &util::rm($self->{'places_filename'}); 339 } 340 $self->{'places_filename'} = undef; 341 342 }
Note:
See TracChangeset
for help on using the changeset viewer.