AI-ExpertSystem-Advanced

 view release on metacpan or  search on metacpan

inc/Module/Install.pm  view on Meta::CPAN

40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
 
 
 
 
# Whether or not inc::Module::Install is actually loaded, the
# $INC{inc/Module/Install.pm} is what will still get set as long as
# the caller loaded module this in the documented manner.
# If not set, the caller may NOT have loaded the bundled version, and thus
# they may not have a MI version that works with the Makefile.PL. This would
# result in false errors or unexpected behaviour. And we don't want that.
my $file = join( '/', 'inc', split /::/, __PACKAGE__ ) . '.pm';
unless ( $INC{$file} ) { die <<"END_DIE" }
 
Please invoke ${\__PACKAGE__} with:
 
        use inc::${\__PACKAGE__};
 
not:
 
        use ${\__PACKAGE__};

inc/Module/Install.pm  view on Meta::CPAN

71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# is unreliable on some platforms and requires write permissions)
# for now we should catch this and refuse to run.
if ( -f $0 ) {
        my $s = (stat($0))[9];
 
        # If the modification time is only slightly in the future,
        # sleep briefly to remove the problem.
        my $a = $s - time;
        if ( $a > 0 and $a < 5 ) { sleep 5 }
 
        # Too far in the future, throw an error.
        my $t = time;
        if ( $s > $t ) { die <<"END_DIE" }
 
Your installer $0 has a modification time in the future ($s > $t).
 
This is known to create infinite loops in make.
 
Please correct this, then run $0 again.
 
END_DIE

lib/AI/ExpertSystem/Advanced.pm  view on Meta::CPAN

871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
        $rule_no, 'causes_pending');
if (defined $causes_total and defined $causes_pending) {
    # No more pending causes for this rule, lets shoot it
    if ($causes_pending-1 le 0) {
        my $last_rule = $self->remove_last_visited_rule();
        if ($last_rule eq $rule_no) {
            $self->{'viewer'}->debug("Going to shoot $last_rule")
                if $self->{'debug'};
            $self->shoot($last_rule, 'backward');
        } else {
            $self->{'viewer'}->print_error(
                    "Seems the rule ($rule_no) of goal " .
                    "$goal is not the same as the last " .
                    "visited rule ($last_rule)");
            $more_goals = 0;
            next WAIT_FOR_MORE_GOALS;
        }
    } else {
        $self->{'visited_rules'}->update($rule_no,
                {
                    causes_pending => $causes_pending-1

lib/AI/ExpertSystem/Advanced.pm  view on Meta::CPAN

989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
will be asked to the user. For example, we know that that the patient has a
headache but that doesn't give us any positive answer, what if the patient has
flu or another disease? Then a set of these I<related> symptons will be asked
to the user.
 
=cut
sub mixed {
    my ($self) = @_;
 
    if (!$self->forward()) {
        $self->{'viewer'}->print_error("The first execution of forward failed");
        return 0;
    }
 
    use Data::Dumper;
 
    while(1) {
        # We are satisfied if only one inference fact is positive (eg, means we
        # got to our result)
        while(my $fact = $self->{'inference_facts'}->iterate) {
            my $sign = $self->{'inference_facts'}->get_value($fact, 'sign');

lib/AI/ExpertSystem/Advanced.pm  view on Meta::CPAN

1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
If C<$return> is defined (eg, it got any parameter) then the result wont be
passed to the L<viewer>, instead it will be returned as a string.
 
=cut
sub summary {
    my ($self, $return) = @_;
 
    # any facts we found via inference?
    if (scalar @{$self->{'inference_facts'}->{'stack'}} eq 0) {
        $self->{'viewer'}->print_error("No inference was possible");
    } else {
        my $summary = {};
        # How the rules started being shot?
        my $order = 1;
        # So, what rules we shot?
        foreach my $shot_rule (sort(keys %{$self->{'shot_rules'}})) {
            $summary->{'rules'}->{$shot_rule} = {
                order => $order,
            };
            $order++;

lib/AI/ExpertSystem/Advanced/Viewer/Base.pm  view on Meta::CPAN

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
=head2 B<print($msg)>
 
Will be used to print anything that is not a debug messages. It only receives
one parameter that is the message to print.
 
=cut
sub print {
    confess NO_ABSTRACT_CLASS_MSG;
}
 
=head2 B<print_error($msg)>
 
Will be used to print any error of L<AI::ExpertSystem::Advanced>. It only
receives one parameter that is the message to print.
 
=cut
sub print_error {
    confess NO_ABSTRACT_CLASS_MSG;
}
 
=head2 B<ask($message, @options)>
 
Will be used to ask the user for some information. It will receive a string,
the question to ask and an array of all the possible options.
 
Please return only one option and this should be any of the ones listed in
C<@options> cause otherwise L<AI::ExpertSystem::Advanced> will die.

lib/AI/ExpertSystem/Advanced/Viewer/Terminal.pm  view on Meta::CPAN

53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
=head2 B<print($msg)>
 
Simply prints the given C<$msg>.
 
=cut
sub print {
    my ($self, $msg) = @_;
    print "$msg\n";
}
 
=head2 B<print_error($msg)>
 
Will prepend the "ERROR:" word to the given message and then will call
C<print()>.
 
=cut
sub print_error {
    my ($self, $msg) = @_;
    $self->print("ERROR: $msg");
}
 
=head2 B<ask($message, @options)>
 
Will be used to ask the user for some information. It will receive a string,
the question to ask and an array of all the possible options.
 
=cut



( run in 0.396 second using v1.01-cache-2.11-cpan-26ccb49234f )