AI-ExpertSystem-Advanced
view release on metacpan or search on metacpan
lib/AI/ExpertSystem/Advanced/KnowledgeDB/Base.pm view on Meta::CPAN
}
my $causes_dict = AI::ExpertSystem::Advanced::Dictionary->new(
stack => \@facts);
return $causes_dict;
}
=head2 B<find_rule_by_goal($goal)>
Looks for the first rule that has the given C<goal> in its goals.
If a rule is found then its number is returned, otherwise C<undef> is
returned.
B<NOTE>: Rewrite this method if you are not going to use the C<rules> hash (eg,
you will use a database engine).
=cut
sub find_rule_by_goal {
my ($self, $goal) = @_;
my $rule_counter = 0;
foreach my $rule (@{$self->{'rules'}}) {
foreach my $rule_goal (@{$rule->{'goals'}}) {
# Look in id and name for the match
foreach my $look_in (qw(id name)) {
if (defined $rule_goal->{$look_in}) {
if ($rule_goal->{$look_in} eq $goal) {
return $rule_counter;
}
}
}
}
$rule_counter++;
}
return undef;
}
=head2 B<get_question($fact)>
Looks for a question about the given C<$fact>. If a question exists then this is
returned, otherwise C<undef> is returned.
B<NOTE>: Rewrite this method if you are not going to use the C<rules> hash (eg,
you will use a database engine).
=cut
sub get_question {
my ($self, $fact) = @_;
if (defined $self->{'questions'}->{$fact}) {
return $self->{'questions'}->{$fact};
}
return undef;
}
=head2 B<get_next_rule($current_rule)>
Returns the ID of the next rule. When there are no more rules to work then
C<undef> should be returned.
When it starts looking for the first rule, C<$current_rule> value will
be C<undef>.
B<NOTE>: Rewrite this method if you are not going to use the C<rules> hash (eg,
you will use a database engine).
=cut
sub get_next_rule {
my ($self, $current_rule) = @_;
my $next_rule;
if (defined $current_rule) {
$next_rule = $current_rule+1;
} else {
$next_rule = 0;
}
if (defined $self->{'rules'}->[$next_rule]) {
return $next_rule;
} else {
return undef;
}
}
=head1 AUTHOR
Pablo Fischer (pablo@pablo.com.mx).
=head1 COPYRIGHT
Copyright (C) 2010 by Pablo Fischer.
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
1;
( run in 1.294 second using v1.01-cache-2.11-cpan-39bf76dae61 )