Hi, I am writing a word stemming program, the program reads from a *.trec file to get query words in <title></title> tag, then stems the query words and output the result to another *.trec file. But perl builder promts "out of memory":
Thanks a lot!
Code:
use stem;
use WordNet::QueryData;
$wn = WordNet::QueryData->new;
$stemmer = stem->new($wn);
my $topic= "D:\\Program Files\\Perl Builder2\\MYPERL\\TrainingTopics.trec";
my $mytopic="D:\\Program Files\\Perl Builder2\\MYPERL\\myTopics.trec";
open FILE,"$topic" or die $!;
open MYTOPIC,">$mytopic" or die $!;
while(my $file=<FILE>)
{
if($file=~/<title>(.+?)<\/title>/)
{
print MYTOPIC &stemming($file);
}
else
{
print MYTOPIC $file;
}
}
sub stemming
{
my $in = shift;
my $out = '';
foreach my $token (split /[ ,.:;?!]/, $in)
{
my @stems = $stemmer->stemWord($token);
$out .= $stems[0] . ' ';
}
return $out;
}
close FILE;
close MYTOPIC;
Comment