Index: trunk/gsdl/perllib/plugins/BasPlug.pm
===================================================================
--- trunk/gsdl/perllib/plugins/BasPlug.pm	(revision 9351)
+++ trunk/gsdl/perllib/plugins/BasPlug.pm	(revision 9398)
@@ -26,4 +26,8 @@
 package BasPlug;
 
+BEGIN {
+    die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
+}
+
 eval {require bytes};
 
@@ -48,4 +52,7 @@
 use printusage;
 
+use GISBasPlug;
+
+@ISA = ( GISBasPlug );
 
 my $unicode_list =
@@ -106,5 +113,5 @@
 	'desc' => "{BasPlug.markup_acronyms}",
 	'type' => "flag",
-	'reqd' => "no" },  
+	'reqd' => "no" },
       { 'name' => "extract_keyphrases",
 	'desc' => "{BasPlug.extract_keyphrases}",
@@ -147,4 +154,19 @@
 	'reqd' => "no" } ];
 
+my $gis_arguments = 
+    [ { 'name' => "extract_placenames",
+	'desc' => "{GISBasPlug.extract_placenames}",
+	'type' => "flag",
+	'reqd' => "no" },
+      { 'name' => "gazetteer",
+	'desc' => "{GISBasPlug.gazetteer}",
+	'type' => "string",
+	'reqd' => "no" },
+      { 'name' => "place_list",
+	'desc' => "{GISBasPlug.place_list}",
+	'type' => "flag",
+	'reqd' => "no" } ];
+
+
 my $options = { 'name'     => "BasPlug",
 		'desc'     => "{BasPlug.desc}",
@@ -301,4 +323,9 @@
     my $self = {};
     $self->{'plugin_type'} = "BasPlug";
+
+    if (GISBasPlug::has_mapdata()) {
+	push(@$arguments,@$gis_arguments);
+    }
+
     my $enc = "^(";
     map {$enc .= "$_|";} keys %$encodings::encodings;
@@ -328,9 +355,12 @@
 			 q^extract_language^, \$self->{'extract_language'},
 			 q^extract_acronyms^, \$self->{'extract_acronyms'}, 
-			 q^extract_keyphrases^, \$self->{'kea'}, 
-			 q^extract_keyphrase_options/.*/^, \$self->{'kea_options'},
+			 q^extract_keyphrases^, \$self->{'kea'}, #with extra options (UNDOCUMENTED)
+			 q^extract_keyphrase_options/.*/^, \$self->{'kea_options'}, #no extra options (UNDOCUMENTED)
 			 qq^input_encoding/$enc/auto^, \$self->{'input_encoding'},
 			 qq^default_encoding/$denc/utf8^, \$self->{'default_encoding'},
 			 q^extract_email^, \$self->{'extract_email'},
+			 q^extract_placenames^, \$self->{'extract_placenames'}, 
+			 q^gazetteer/.*/^, \$self->{'gazetteer'},
+			 q^place_list^, \$self->{'place_list'}, 
 			 q^markup_acronyms^, \$self->{'markup_acronyms'},
 			 q^default_language/.{2}/en^, \$self->{'default_language'},
@@ -367,5 +397,21 @@
 
     $self->{'cover_image'} = 0 if ($no_cover_image);
-    
+
+    if ($self->{'extract_placenames'}) {
+
+	my $outhandle = $self->{'outhandle'};
+
+	my $places_ref 
+	    = GISBasPlug::loadGISDatabase($outhandle,$self->{'gazetteer'});
+
+	if (!defined $places_ref) {
+	    print $outhandle "Warning: Error loading mapdata gazetteer \"$self->{'gazetteer'}\"\n";
+	    print $outhandle "         No placename extraction will take place.\n";
+	    $self->{'extract_placenames'} = undef;
+	}
+	else {
+	    $self->{'places'} = $places_ref;
+	}
+    }	
     return bless $self, $class;
 }
@@ -626,5 +672,5 @@
     my $smart_block = $self->{'smart_block'};
     my $smart_block_BN = $self->{'smart_block_BN'};
-    
+
     my $filename = $file;
     $filename = &util::filename_cat ($base_dir, $file) if $base_dir =~ /\w/;
@@ -663,5 +709,4 @@
 
     my ($filemeta) = $file =~ /([^\\\/]+)$/;
-
     # how do we know what encoding the filename is in?
     $doc_obj->add_metadata($doc_obj->get_top_section(), "Source", &ghtml::dmsafe($filemeta));
@@ -690,5 +735,5 @@
 
     $self->extra_metadata ($doc_obj, $doc_obj->get_top_section(), $metadata);
-    
+
     # do plugin specific processing of doc_obj
     unless (defined ($self->process (\$text, $pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli))) {
@@ -699,5 +744,5 @@
     $text='';
     undef $text;
-
+   
     # do any automatic metadata extraction
     $self->auto_extract_metadata ($doc_obj);
@@ -716,4 +761,9 @@
     $processor->process($doc_obj);
 
+    if(defined($self->{'places_filename'})){
+	&util::rm($self->{'places_filename'});
+	$self->{'places_filename'} = undef;
+    }
+
     $self->{'num_processed'} ++;
     undef $doc_obj;
@@ -784,4 +834,5 @@
     return $file_derived_title;
 }
+
 
 sub title_fallback
@@ -952,5 +1003,4 @@
     foreach my $field (keys(%$metadata)) {
 	# $metadata->{$field} may be an array reference
-
 	if ($field eq "gsdlassocfile_tobe") {
 	    # 'gsdlassocfile_tobe' is artificially introduced metadata
@@ -1063,9 +1113,15 @@
 	}
     } 
-
+    if ($self->{'extract_placenames'}) {
+	my $thissection = $doc_obj->get_top_section();
+	while (defined $thissection) {
+	    my $text = $doc_obj->get_text($thissection);
+	    $self->extract_placenames (\$text, $doc_obj, $thissection) if $text =~ /./;
+	    $thissection = $doc_obj->get_next_section ($thissection);
+	}
+    } 
 
     # adding kea keyphrases
-
-    if ($self->{'kea'}) {  
+    if ($self->{'kea'}) {
 	
 	my $thissection = $doc_obj->get_top_section();
@@ -1079,7 +1135,6 @@
 	    $thissection = $doc_obj->get_next_section ($thissection);
 	} 
-		
-
-	if($self->{'kea_options'}) {
+       
+	if ($self->{'kea_options'}) {
 	    #if kea options flag is set, call Kea with specified options 
 	    $list = &Kea::extract_KeyPhrases ($text, $self->{'kea_options'}); 
@@ -1088,5 +1143,5 @@
 	    $list = &Kea::extract_KeyPhrases ($text); 
 	}
-	if($list){ 
+	if ($list){
 	    # if a list of kea keyphrases was returned (ie not empty)
 	    &gsprintf(STDERR, "{BasPlug.keyphrases}: $list\n");
@@ -1104,7 +1159,5 @@
 	    }
 	}
-    }
- 
-    #end of kea 
+    } #end of kea 
 
     if ($self->{'first'}) {
