|
From: <jgr...@us...> - 2003-07-27 15:42:45
|
Update of /cvsroot/popfile/engine/Classifier
In directory sc8-pr-cvs1:/tmp/cvs-serv17399/Classifier
Modified Files:
Bayes.pm
Log Message:
More tests for Classifier::Bayes to cover adding and removing messages in a bucket
Index: Bayes.pm
===================================================================
RCS file: /cvsroot/popfile/engine/Classifier/Bayes.pm,v
retrieving revision 1.172
retrieving revision 1.173
diff -C2 -d -r1.172 -r1.173
*** Bayes.pm 27 Jul 2003 01:37:58 -0000 1.172
--- Bayes.pm 27 Jul 2003 15:42:42 -0000 1.173
***************
*** 1283,1291 ****
my ( $self, $bucket ) = @_;
if ( $self->get_bucket_word_count( $bucket ) > 0 ) {
! return $self->{matrix__}{$bucket};
! } else {
! return ();
}
}
--- 1283,1299 ----
my ( $self, $bucket ) = @_;
+ my @result;
+
if ( $self->get_bucket_word_count( $bucket ) > 0 ) {
! my @entries = @{$self->{matrix__}{$bucket}};
!
! for my $i (0..$#entries) {
! if ( defined( $entries[$i] ) && ( $entries[$i] ne '' ) ) {
! push @result, ($entries[$i]);
! }
! }
}
+
+ return @result;
}
***************
*** 1537,1541 ****
if ( !defined( $self->{total__}{$bucket} ) ) {
! return;
}
--- 1545,1549 ----
if ( !defined( $self->{total__}{$bucket} ) ) {
! return 0;
}
***************
*** 1546,1551 ****
if ( /__CORPUS__ __VERSION__ (\d+)/ ) {
if ( $1 != $self->{corpus_version__} ) {
! print "Incompatible corpus version in $bucket\n";
! return;
}
--- 1554,1560 ----
if ( /__CORPUS__ __VERSION__ (\d+)/ ) {
if ( $1 != $self->{corpus_version__} ) {
! print STDERR "Incompatible corpus version in $bucket\n";
! close WORDS;
! return 0;
}
***************
*** 1578,1582 ****
print WORDS "__CORPUS__ __VERSION__ 1\n";
foreach my $word (sort keys %words) {
! print WORDS "$word $words{$word}\n";
}
close WORDS;
--- 1587,1593 ----
print WORDS "__CORPUS__ __VERSION__ 1\n";
foreach my $word (sort keys %words) {
! if ( $words{$word} != 0 ) {
! print WORDS "$word $words{$word}\n";
! }
}
close WORDS;
***************
*** 1584,1587 ****
--- 1595,1600 ----
$self->load_word_matrix_();
+
+ return 1;
}
***************
*** 1592,1604 ****
# Parses a mail message and updates the statistics in the specified bucket
#
- # $file Name of file containing mail message to parse
# $bucket Name of the bucket to be updated
#
# ---------------------------------------------------------------------------------------------
sub add_message_to_bucket
{
! my ( $self, $file, $bucket ) = @_;
! $self->add_messages_to_bucket( $bucket, $file );
}
--- 1605,1617 ----
# Parses a mail message and updates the statistics in the specified bucket
#
# $bucket Name of the bucket to be updated
+ # $file Name of file containing mail message to parse
#
# ---------------------------------------------------------------------------------------------
sub add_message_to_bucket
{
! my ( $self, $bucket, $file ) = @_;
! return $self->add_messages_to_bucket( $bucket, $file );
}
***************
*** 1609,1619 ****
# Parses a mail message and updates the statistics in the specified bucket
#
- # $file Name of file containing mail message to parse
# $bucket Name of the bucket to be updated
#
# ---------------------------------------------------------------------------------------------
sub remove_message_from_bucket
{
! my ( $self, $file, $bucket ) = @_;
# Verify that the bucket exists. You must call create_bucket before this
--- 1622,1632 ----
# Parses a mail message and updates the statistics in the specified bucket
#
# $bucket Name of the bucket to be updated
+ # $file Name of file containing mail message to parse
#
# ---------------------------------------------------------------------------------------------
sub remove_message_from_bucket
{
! my ( $self, $bucket, $file ) = @_;
# Verify that the bucket exists. You must call create_bucket before this
***************
*** 1621,1625 ****
if ( !defined( $self->{total__}{$bucket} ) ) {
! return;
}
--- 1634,1638 ----
if ( !defined( $self->{total__}{$bucket} ) ) {
! return 0;
}
***************
*** 1630,1635 ****
if ( /__CORPUS__ __VERSION__ (\d+)/ ) {
if ( $1 != $self->{corpus_version__} ) {
! print "Incompatible corpus version in $bucket\n";
! return;
}
--- 1643,1649 ----
if ( /__CORPUS__ __VERSION__ (\d+)/ ) {
if ( $1 != $self->{corpus_version__} ) {
! print STDERR "Incompatible corpus version in $bucket\n";
! close WORDS;
! return 0;
}
***************
*** 1660,1664 ****
print WORDS "__CORPUS__ __VERSION__ 1\n";
foreach my $word (sort keys %words) {
! print WORDS "$word $words{$word}\n";
}
close WORDS;
--- 1674,1680 ----
print WORDS "__CORPUS__ __VERSION__ 1\n";
foreach my $word (sort keys %words) {
! if ( $words{$word} != 0 ) {
! print WORDS "$word $words{$word}\n";
! }
}
close WORDS;
***************
*** 1666,1669 ****
--- 1682,1687 ----
$self->load_word_matrix_();
+
+ return 1;
}
|