Index: /trunk/gsdl/perllib/classify/phind.pm
===================================================================
--- /trunk/gsdl/perllib/classify/phind.pm	(revision 1807)
+++ /trunk/gsdl/perllib/classify/phind.pm	(revision 1808)
@@ -31,15 +31,16 @@
 # options are:
 #   button=Name           The label for the classifiers button in the
-#                         navigation bar (defaults to "Topic").
+#                         navigation bar (defaults to "Phrase").
 #   title=Title           The metadata field used to describe each document
 #                         (defaults to "Title").
 #   text=fields           The text used to build the phrase hierarchy
 #                         (defaults to "section:Title,section:text").
-#   phinddir=directory  Location of phind index files
+#   phinddir=directory    Location of phind index files
 #   verbosity=num         Control amount of output
 #   untidy=true           Do not clean up intermediate files
 #   suffixmode=num        Mode of suffix program (0 = all phrases, 1 = stopword)
 #   suffixsize=num        Number of symbols available to suffix program
-
+#   savephrases=filename  If set, phrase infomation will be stored in filename
+#                         as text. (By defualt, it is not set.)
 
 # How a classifier works.  
@@ -155,4 +156,5 @@
     my $suffixmode = 1;
     my $suffixsize = 40000000;
+    my $savephrases = "";
 
     my $verbosity = 2;
@@ -174,12 +176,14 @@
 	} elsif ($option =~ /^phinddir=(.*)$/i) {
 	    $phinddir = $1;
+	} elsif ($option =~ /^savephrases=(.*)$/i) {
+	    $savephrases = $1;
 	} elsif ($option =~ /^suffixsize=(.*)$/i) {
 	    $suffixsize = $1;
 	} elsif ($option =~ /^suffixmode=(.*)$/i) {
 	    $suffixmode = $1;
+	} elsif ($option =~ /^untidy/i) {
+	    $untidy = 1;
 	} elsif ($option =~ /^verbosity=(.*)$/i) {
 	    $verbosity = $1;
-	} elsif ($option =~ /^untidy/i) {
-	    $untidy = 1;
 	}
     }
@@ -194,4 +198,5 @@
     $self->{'suffixmode'} = $suffixmode;
     $self->{'suffixsize'} = $suffixsize;
+    $self->{'savephrases'} = $savephrases if ($savephrases);
 
     # limit languages
@@ -380,5 +385,5 @@
     # Create the phrase file and put phrase numbers in phind/phrases
     print "\nSorting and Renumbering phrases for input to mgpp\n" if $verbosity;
-    &renumber_phrases("$phinddir", $verbosity);
+    &renumber_phrases($self);
     
     # Create the mg phrase database
@@ -427,5 +432,5 @@
 
     # Tidy up stray files
-    if (!$untidy) {
+    if (!$self->{'untidy'}) {
 	print "\nCleaning up\n" if ($verbosity > 2);
 	&util::rm("$phinddir/clauses", "$phinddir/clauses.numbers", 
@@ -795,5 +800,13 @@
 
 sub renumber_phrases {
-    my ($phind_dir, $verbosity) = @_;
+    my $self = shift (@_);
+
+    my $verbosity = $self->{'verbosity'};
+    my $phind_dir = $self->{'phinddir'};
+
+    my $savephrases = 0;
+    $savephrases = $self->{'savephrases'} if (defined($self->{'savephrases'}));
+
+					      
 
     # Sort the phrases into order of increasing frequency
@@ -802,7 +815,6 @@
     system("sort -rnt ':' +2 -o $phind_dir/phrases $phind_dir/phrases");
 
+    # Read the vocabulary
     my @symbol;
-
-    # Read the vocabulary
     print "Reading the vocabulary\n" if ($verbosity);
     open(V, "<$phind_dir/clauses.vocab")
@@ -846,12 +858,19 @@
     }
     
-
+    
     # Now we create a new phrase file using phrase numbers, not the old IDs.
     print "Format phrase data for MGPP\n" if ($verbosity);
     
+    # Open the basic files
     open(IN, "<$phind_dir/phrases");
     open(DATA, ">$phind_dir/pdata.txt");
     open(IDX, ">$phind_dir/pword.txt");
     
+    # We may want to save the phrases in a separate text file
+    if ($savephrases) {
+	print "Saving phrases in $savephrases\n" if ($verbosity);
+	open(SAVE, ">$savephrases");
+    }
+
     my ($key, $tf, $num, $countexp, $expansions, $countdocs, $documents, $text, $word);
     my @fields;
@@ -921,6 +940,12 @@
 	print IDX "<Document>$word\n";
 
-	
-    }
+	# output the phrases to a text file
+	if ($savephrases) {
+	    print SAVE "$tf\t$countdocs\t$text\n";
+	}
+
+    }
+
+    close SAVE if ($savephrases);
 }
 
