Hi PerlDiscuss - Perl Newsgroups and mailing lists,
It's not really inheritance that's lost, it's the actual module code. You should be able to solve this by just adding a 'use Algorithm::NaiveBayes::Model::Frequency;' to the second script.
Or if you don't want to hard-code that, you can do:
$nb = AI::Categorizer::Learner::NaiveBayes->restore_state('filename'); eval( 'use ' . ref($nb) );
To solve this correctly, I think I'd have to add this to the restore_state() method in the NaiveBayes learner class.
-Ken
On Aug 31, 2004, at 6:12 AM, PerlDiscuss - Perl Newsgroups and mailing lists wrote:
Hi folks,
I'm trying to implement AI:Categorizer. Everything works fine until I try to save and restore the state of the learner.
From the synopsis...
my $nb = new AI::Categorizer::Learner::NaiveBayes(...parameters...); $nb->train(knowledge_set => $k); $nb->save_state ('filename');
--- later ----
$nb = AI::Categorizer::Learner::NaiveBayes->restore_state('filename'); my $c = new AI::Categorizer::Collection::Files( path => ... ); while (my $document = $c->next) { my $hypothesis = $nb->categorize($document); print "Best assigned category: ", $hypothesis->best_category, "\n"; print "All assigned categories: ", join(', ', $hypothesis->categories), "\n";
However when the line my $hypothesis = $nb->categorize($document); is executed I get the following error.
Can't locate object method "predict" via package "Algorithm::NaiveBayes::Model::Frequency" at /usr/lib/perl5/site_perl/5.8.3/AI/Categorizer/Learner/NaiveBayes.pm line 28.
It seems like inheritance is lost between save and restore states. Any ideas?
Thanks in advance.
PS: CC to email highly appreciated.