How to interpret (hash reference) results of perl AI::Classifier::Text::FileLearner;

48 Views Asked by At

I am trying my own perl "AI hello world" and having a hard time understanding the results of AI::Classifier::Text::FileLearner;

I believe I have gone astray in iterating through the hash references.

#!/usr/bin/perl

use utf8;
use strict;
use warnings;

use AI::Classifier::Text::FileLearner;
my $iterator = AI::Classifier::Text::FileLearner->new( training_dir => '/home/pi/20_newsgroups/talk.politics.guns' );

print "getting ready to classify\n";
my $classifier = $iterator->classifier;

my $key;
my $value;
my %hash = %$classifier;
# traversing the hash using "each" function 
while(($key, $value) = each (%hash)) 
{ 

    # do stuff 
    $value = $hash{$key};
    #print ref{$value};
    if (ref{$value} eq 'HASH') {

    print "$value is ANOTHER hash reference\n";
    my %hash2 = %$value; #derefrence it
    while(($key, $value) = each (%hash2)) 
    {

        # do stuff 
        $value = $hash2{$key};
        print "Value of $key is $value\n";  

    }


    } else {

    print "Value of $key is $value\n";  

    }


} # end of 1st while 

Is there a better more effective way to try to iterate through these hash references so that I can see the results of the training?

0

There are 0 best solutions below