| 1 | # | ||
| 2 | # AI::ExpertSystem::Advanced::KnowledgeDB::YAML | ||
| 3 | # | ||
| 4 | # Author(s): Pablo Fischer (pfischer@cpan.org) | ||
| 5 | # Created: 12/13/2009 16:12:43 PST 16:12:43 | ||
| 6 | package AI::ExpertSystem::Advanced::KnowledgeDB::YAML; | ||
| 7 | |||
| 8 | =head1 NAME | ||
| 9 | |||
| 10 | AI::ExpertSystem::Advanced::KnowledgeDB::YAML - YAML Knowledge DB driver | ||
| 11 | |||
| 12 | =head1 DESCRIPTION | ||
| 13 | |||
| 14 | A YAML knowledge database driver. | ||
| 15 | |||
| 16 | It reads a given YAML file and looks for the I<rules> hash key. All of the | ||
| 17 | elements of C<rules> (causes and goals) are copied to the C<rules> hash | ||
| 18 | key of L<AI::ExpertSystem::Advanced::KnowledgeDB::Base>. | ||
| 19 | |||
| 20 | If no rules are found then it ends unsuccessfully. | ||
| 21 | |||
| 22 | It also looks for any available questions under the I<questions> hash key, | ||
| 23 | however if no questions are found then they are not copied :-) | ||
| 24 | |||
| 25 | =cut | ||
| 26 | use Moose; | ||
| 27 | use YAML::Syck; | ||
| 28 | |||
| 29 | extends 'AI::ExpertSystem::Advanced::KnowledgeDB::Base'; | ||
| 30 | |||
| 31 | our $VERSION = '0.01'; | ||
| 32 | |||
| 33 | =head1 Attributes | ||
| 34 | |||
| 35 | =over 4 | ||
| 36 | |||
| 37 | =item B<filename> | ||
| 38 | |||
| 39 | YAML file path to read | ||
| 40 | |||
| 41 | =back | ||
| 42 | |||
| 43 | =cut | ||
| 44 | has 'filename' => ( | ||
| 45 | is => 'rw', | ||
| 46 | isa => 'Str', | ||
| 47 | required => 1); | ||
| 48 | |||
| 49 | # Called when the object gets created | ||
| 50 | sub BUILD { | ||
| 51 | my ($self) = @_; | ||
| 52 | |||
| 53 | my $data = LoadFile($self->{'filename'}); | ||
| 54 | if (defined $data->{'rules'}) { | ||
| 55 | $self->{'rules'} = $data->{'rules'} | ||
| 56 | } else { | ||
| 57 | confess "Couldn't find any rules in $self->{'filename'}"; | ||
| 58 | } | ||
| 59 | |||
| 60 | if (defined $data->{'questions'}) { | ||
| 61 | $self->{'questions'} = $data->{'questions'}; | ||
| 62 | } | ||
| 63 | } | ||
| 64 | |||
| 65 | =head1 AUTHOR | ||
| 66 | |||
| 67 | Pablo Fischer (pablo@pablo.com.mx). | ||
| 68 | |||
| 69 | =head1 COPYRIGHT | ||
| 70 | |||
| 71 | Copyright (C) 2010 by Pablo Fischer. | ||
| 72 | |||
| 73 | This library is free software; you can redistribute it and/or modify | ||
| 74 | it under the same terms as Perl itself. | ||
| 75 | |||
| 76 | =cut | ||
| 77 | |||
| 78 | 1; | ||
| 79 |