Index: /gsdl/trunk/perllib/plugins/AcronymExtractor.pm
===================================================================
--- /gsdl/trunk/perllib/plugins/AcronymExtractor.pm	(revision 15867)
+++ /gsdl/trunk/perllib/plugins/AcronymExtractor.pm	(revision 15867)
@@ -0,0 +1,153 @@
+package AcronymExtractor;
+
+use acronym;
+use PrintInfo;
+
+BEGIN {
+    @AcronymExtractor::ISA = ('PrintInfo');
+}
+
+my $arguments = [
+      { 'name' => "extract_acronyms",
+	'desc' => "{AcronymExtractor.extract_acronyms}",
+	'type' => "flag",
+	'reqd' => "no" },
+      { 'name' => "markup_acronyms",
+	'desc' => "{AcronymExtractor.markup_acronyms}",
+	'type' => "flag",
+	'reqd' => "no" } ];
+
+my $options = { 'name'     => "AcronymExtractor",
+		'desc'     => "{AcronymExtractor.desc}",
+		'abstract' => "yes",
+		'inherits' => "yes",
+		'args'     => $arguments };
+
+
+sub new {
+    my ($class) = shift (@_);
+    my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
+    push(@$pluginlist, $class);
+
+    if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});}
+    if(defined $options) { push(@{$hashArgOptLists->{"OptList"}},$options)};
+
+    my $self = new PrintInfo($pluginlist, $inputargs, $hashArgOptLists);
+
+    return bless $self, $class;
+
+}
+
+
+# initialise metadata extractors
+sub initialise_acronym_extractor {
+    my $self = shift (@_);
+
+    if ($self->{'extract_acronyms'} || $self->{'markup_acronyms'}) {
+	&acronym::initialise_acronyms();
+    }
+}
+
+# finalise metadata extractors
+sub finalise_acronym_extractor {
+    my $self = shift (@_);
+
+    if ($self->{'extract_acronyms'} || $self->{'markup_acronyms'}) {
+	&acronym::finalise_acronyms();
+    }
+}
+
+# extract metadata
+sub extract_acronym_metadata {
+
+    my $self = shift (@_);
+    my ($doc_obj) = @_;
+    
+
+    if ($self->{'extract_acronyms'}) {
+	my $thissection = $doc_obj->get_top_section();
+	while (defined $thissection) {
+	    my $text = $doc_obj->get_text($thissection);
+	    $self->extract_acronyms (\$text, $doc_obj, $thissection) if $text =~ /./;
+	    $thissection = $doc_obj->get_next_section ($thissection);
+	}
+    }
+    
+    if ($self->{'markup_acronyms'}) {
+	my $thissection = $doc_obj->get_top_section();
+	while (defined $thissection) {
+	    my $text = $doc_obj->get_text($thissection);
+	    $text = $self->markup_acronyms ($text, $doc_obj, $thissection);
+	    $doc_obj->delete_text($thissection);
+	    $doc_obj->add_text($thissection, $text);
+	    $thissection = $doc_obj->get_next_section ($thissection);
+	}
+    }
+
+}
+
+
+
+# extract acronyms from a section in a document. progress is 
+# reported to outhandle based on the verbosity. both the Acronym
+# and the AcronymKWIC metadata items are created. 
+
+sub extract_acronyms {
+    my $self = shift (@_);
+    my ($textref, $doc_obj, $thissection) = @_;
+    my $outhandle = $self->{'outhandle'};
+
+    # print $outhandle " extracting acronyms ...\n" 
+    gsprintf($outhandle, " {BasPlug.extracting_acronyms}...\n")
+	if ($self->{'verbosity'} > 2);
+
+    my $acro_array =  &acronym::acronyms($textref);
+    
+    foreach my $acro (@$acro_array) {
+
+	#check that this is the first time ...
+	my $seen_before = "false";
+	my $previous_data = $doc_obj->get_metadata($thissection, "Acronym");
+	foreach my $thisAcro (@$previous_data) {
+	    if ($thisAcro eq $acro->to_string()) {
+		$seen_before = "true";
+		if ($self->{'verbosity'} >= 4) {
+		    gsprintf($outhandle, " {BasPlug.already_seen} " .
+			     $acro->to_string() . "\n");
+		}
+	    }
+	}
+
+	if ($seen_before eq "false") {
+	    #write it to the file ...
+	    $acro->write_to_file();
+
+	    #do the normal acronym
+	    $doc_obj->add_utf8_metadata($thissection, "Acronym",  $acro->to_string());
+	    gsprintf($outhandle, " {BasPlug.adding} ".$acro->to_string()."\n")
+		if ($self->{'verbosity'} > 3);
+	}
+    }
+
+    gsprintf($outhandle, " {BasPlug.done_acronym_extract}\n")
+	if ($self->{'verbosity'} > 2);
+}
+
+sub markup_acronyms {
+    my $self = shift (@_);
+    my ($text, $doc_obj, $thissection) = @_;
+    my $outhandle = $self->{'outhandle'};
+
+    gsprintf($outhandle, " {BasPlug.marking_up_acronyms}...\n")
+	if ($self->{'verbosity'} > 2);
+
+    #self is passed in to check for verbosity ...
+    $text = &acronym::markup_acronyms($text, $self);
+
+    gsprintf($outhandle, " {BasPlug.done_acronym_markup}\n")
+	if ($self->{'verbosity'} > 2);
+
+    return $text;
+}
+
+1;
Index: /gsdl/trunk/perllib/plugins/DateExtractor.pm
===================================================================
--- /gsdl/trunk/perllib/plugins/DateExtractor.pm	(revision 15867)
+++ /gsdl/trunk/perllib/plugins/DateExtractor.pm	(revision 15867)
@@ -0,0 +1,77 @@
+package DateExtractor;
+
+use DateExtract;
+use PrintInfo;
+
+BEGIN {
+    @DateExtractor::ISA = ('PrintInfo');
+}
+
+my $arguments = [
+      { 'name' => "extract_historical_years",
+	'desc' => "{DateExtractor.extract_historical_years}",
+	'type' => "flag",
+	'reqd' => "no" },
+      { 'name' => "maximum_year",
+	'desc' => "{DateExtractor.maximum_year}",
+	'type' => "int",
+	'deft' => (localtime)[5]+1900,
+	'char_length' => "4",
+	#'range' => "2,100",
+	'reqd' => "no"},
+      { 'name' => "maximum_century",
+	'desc' => "{DateExtractor.maximum_century}",
+	'type' => "string",
+	'deft' => "-1",
+	'reqd' => "no" },
+      { 'name' => "no_bibliography",
+	'desc' => "{DateExtractor.no_bibliography}",
+	'type' => "flag",
+	'reqd' => "no"},
+		 ];
+
+my $options = { 'name'     => "DateExtractor",
+		'desc'     => "{DateExtractor.desc}",
+		'abstract' => "yes",
+		'inherits' => "yes",
+		'args'     => $arguments };
+
+
+sub new {
+    my ($class) = shift (@_);
+    my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
+    push(@$pluginlist, $class);
+
+    push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
+    push(@{$hashArgOptLists->{"OptList"}},$options);
+
+    my $self = new PrintInfo($pluginlist, $inputargs, $hashArgOptLists);
+
+    return bless $self, $class;
+
+}
+
+
+# extract metadata
+sub extract_date_metadata {
+
+    my $self = shift (@_);
+    my ($doc_obj) = @_;
+    
+    if($self->{'extract_historical_years'}) {
+	my $thissection = $doc_obj->get_top_section();
+	while (defined $thissection) {
+
+	    my $text = $doc_obj->get_text($thissection);
+	    &DateExtract::get_date_metadata($text, $doc_obj, 
+					    $thissection, 
+					    $self->{'no_bibliography'}, 
+					    $self->{'maximum_year'}, 
+					    $self->{'maximum_century'});
+	    $thissection = $doc_obj->get_next_section ($thissection);
+	}
+    }
+}
+
+
+1;
Index: /gsdl/trunk/perllib/plugins/EmailAddressExtractor.pm
===================================================================
--- /gsdl/trunk/perllib/plugins/EmailAddressExtractor.pm	(revision 15867)
+++ /gsdl/trunk/perllib/plugins/EmailAddressExtractor.pm	(revision 15867)
@@ -0,0 +1,102 @@
+package EmailAddressExtractor;
+
+use PrintInfo;
+
+BEGIN {
+    @EmailAddressExtractor::ISA = ('PrintInfo');
+}
+
+my $arguments = [
+      { 'name' => "extract_email",
+	'desc' => "{EmailAddressExtractor.extract_email}",
+	'type' => "flag",
+	'reqd' => "no" },
+      { 'name' => "new_extract_email",
+	'desc' => "",
+	'type' => "flag",
+	'reqd' => "no",
+	'hiddengli' => "yes" } 
+		 ];
+
+my $options = { 'name'     => "EmailAddressExtractor",
+		'desc'     => "{EmailAddressExtractor.desc}",
+		'abstract' => "yes",
+		'inherits' => "yes",
+		'args'     => $arguments };
+
+
+sub new {
+    my ($class) = shift (@_);
+    my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
+    push(@$pluginlist, $class);
+
+    push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
+    push(@{$hashArgOptLists->{"OptList"}},$options);
+
+    my $self = new PrintInfo($pluginlist, $inputargs, $hashArgOptLists);
+
+    return bless $self, $class;
+
+}
+
+# extract metadata
+sub extract_email_metadata {
+
+    my $self = shift (@_);
+    my ($doc_obj) = @_;
+    
+    if ($self->{'extract_email'}) {
+	my $thissection = $doc_obj->get_top_section();
+	while (defined $thissection) {
+	    my $text = $doc_obj->get_text($thissection);
+	    $self->extract_email (\$text, $doc_obj, $thissection) if $text =~ /./;
+	    $thissection = $doc_obj->get_next_section ($thissection);
+	}
+    } 
+
+}
+
+sub extract_email {
+    my $self = shift (@_);
+    my ($textref, $doc_obj, $thissection) = @_;
+    my $outhandle = $self->{'outhandle'};
+
+    gsprintf($outhandle, " {BasPlug.extracting_emails}...\n")
+	if ($self->{'verbosity'} > 2);
+    
+    my @email = ($$textref =~ m/([-a-z0-9\.@+_=]+@(?:[-a-z0-9]+\.)+(?:com|org|edu|mil|int|net|[a-z][a-z]))/g);
+    @email = sort @email;
+    
+#    if($self->{"new_extract_email"} == 0)
+#    {
+#    my @email2 = ();
+#    foreach my $address (@email) 
+#   {
+#	if (!(join(" ",@email2) =~ m/(^| )$address( |$)/ )) 
+#	    {
+#		push @email2, $address;
+#		$doc_obj->add_utf8_metadata ($thissection, "emailAddress", $address);
+#		# print $outhandle "  extracting $address\n" 
+#		&gsprintf($outhandle, "  {BasPlug.extracting} $address\n")
+#		    if ($self->{'verbosity'} > 3);
+#	    }
+#	}
+#    }
+#    else
+#    {
+    my $hashExistMail = {};
+    foreach my $address (@email) {
+	if (!(defined $hashExistMail->{$address}))
+	{
+	    $hashExistMail->{$address} = 1;
+	    $doc_obj->add_utf8_metadata ($thissection, "emailAddress", $address);
+	    gsprintf($outhandle, "  {BasPlug.extracting} $address\n")
+		if ($self->{'verbosity'} > 3);
+	}
+    }
+    gsprintf($outhandle, " {BasPlug.done_email_extract}\n")
+	if ($self->{'verbosity'} > 2);
+}
+
+
+1;
Index: /gsdl/trunk/perllib/plugins/KeyphraseExtractor.pm
===================================================================
--- /gsdl/trunk/perllib/plugins/KeyphraseExtractor.pm	(revision 15867)
+++ /gsdl/trunk/perllib/plugins/KeyphraseExtractor.pm	(revision 15867)
@@ -0,0 +1,115 @@
+package KeyphraseExtractor;
+
+use Kea;
+use PrintInfo;
+
+BEGIN {
+    @KeyphraseExtractor::ISA = ('PrintInfo');
+}
+
+my $arguments = [
+      { 'name' => "extract_keyphrases",
+	'desc' => "{KeyphraseExtractor.extract_keyphrases}",
+	'type' => "flag",
+	'reqd' => "no" },
+      { 'name' => "extract_keyphrases_kea4",
+	'desc' => "{KeyphraseExtractor.extract_keyphrases_kea4}",
+	'type' => "flag",
+	'reqd' => "no" },
+      { 'name' => "extract_keyphrase_options",
+	'desc' => "{KeyphraseExtractor.extract_keyphrase_options}",
+	'type' => "string",
+	'deft' => "",
+	'reqd' => "no" }
+		 ];
+
+my $options = { 'name'     => "KeyphraseExtractor",
+		'desc'     => "{KeyphraseExtractor.desc}",
+		'abstract' => "yes",
+		'inherits' => "yes",
+		'args'     => $arguments };
+
+
+sub new {
+    my ($class) = shift (@_);
+    my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
+    push(@$pluginlist, $class);
+
+    if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});}
+    if(defined $options) { push(@{$hashArgOptLists->{"OptList"}},$options)};
+
+    my $self = new PrintInfo($pluginlist, $inputargs, $hashArgOptLists);
+
+    return bless $self, $class;
+
+}
+# extract metadata
+sub extract_keyphrase_metadata {
+
+    my $self = shift (@_);
+    my ($doc_obj) = @_;
+
+    if ($self->{'extract_keyphrases'} || $self->{'extract_keyphrases_kea4'}) {
+	$self->extract_keyphrases($doc_obj);
+    }
+
+}
+
+
+#adding kea keyphrases
+sub extract_keyphrases
+{
+    my $self = shift(@_);
+    my $doc_obj = shift(@_);
+
+    # Use Kea 3.0 unless 4.0 has been specified
+    my $kea_version = "3.0";
+    if ($self->{'extract_keyphrases_kea4'}) {
+	$kea_version = "4.0";
+    }
+
+    # Check that Kea exists, and tell the user where to get it if not
+    my $keahome = &Kea::get_Kea_directory($kea_version);
+    if (!-e $keahome) {
+	gsprintf(STDERR, "{KeyphraseExtractor.missing_kea}\n", $keahome, $kea_version);
+	return;
+    }
+
+    my $thissection = $doc_obj->get_top_section();
+    my $text = "";
+    my $list;
+
+    #loop through sections to gather whole doc
+    while (defined $thissection) { 
+	my $sectiontext = $doc_obj->get_text($thissection);   
+	$text = $text.$sectiontext;
+	$thissection = $doc_obj->get_next_section ($thissection);
+    } 
+   
+    if($self->{'extract_keyphrase_options'}) { #if kea options flag is set, call Kea with specified options 
+	$list = &Kea::extract_KeyPhrases ($kea_version, $text, $self->{'extract_keyphrase_options'});
+    } else { #otherwise call Kea with no options
+	$list = &Kea::extract_KeyPhrases ($kea_version, $text);
+    }
+ 
+    if ($list){
+	# if a list of kea keyphrases was returned (ie not empty)
+	if ($self->{'verbosity'}) {
+	    gsprintf(STDERR, "{KeyphraseExtractor.keyphrases}: $list\n");
+	}
+
+	#add metadata to top section
+	$thissection = $doc_obj->get_top_section(); 
+
+	# add all key phrases as one metadata
+	$doc_obj->add_metadata($thissection, "Keyphrases", $list);
+
+	# add individual key phrases as multiple metadata
+	foreach my $keyphrase (split(',', $list)) {
+	    $keyphrase =~ s/^\s+|\s+$//g;
+	    $doc_obj->add_metadata($thissection, "Keyphrase", $keyphrase);
+	}
+    }
+}
+
+1;
