AI::ExpertSystem::Advanced::KnowledgeDB::YAML - YAML Knowledge DB driver


AI-ExpertSystem-Advanced documentation Contained in the AI-ExpertSystem-Advanced distribution.

Index


Code Index:

NAME

Top

AI::ExpertSystem::Advanced::KnowledgeDB::YAML - YAML Knowledge DB driver

DESCRIPTION

Top

A YAML knowledge database driver.

It reads a given YAML file and looks for the rules hash key. All of the elements of rules (causes and goals) are copied to the rules hash key of AI::ExpertSystem::Advanced::KnowledgeDB::Base.

If no rules are found then it ends unsuccessfully.

It also looks for any available questions under the questions hash key, however if no questions are found then they are not copied :-)

Attributes

Top

filename

YAML file path to read

AUTHOR

Top

Pablo Fischer (pablo@pablo.com.mx).

COPYRIGHT

Top


AI-ExpertSystem-Advanced documentation Contained in the AI-ExpertSystem-Advanced distribution.
#
# AI::ExpertSystem::Advanced::KnowledgeDB::YAML
#
# Author(s): Pablo Fischer (pfischer@cpan.org)
# Created: 12/13/2009 16:12:43 PST 16:12:43
package AI::ExpertSystem::Advanced::KnowledgeDB::YAML;

use Moose;
use YAML::Syck;

extends 'AI::ExpertSystem::Advanced::KnowledgeDB::Base';

our $VERSION = '0.01';

has 'filename' => (
        is => 'rw',
        isa => 'Str',
        required => 1);

# Called when the object gets created
sub BUILD {
    my ($self) = @_;

    my $data = LoadFile($self->{'filename'});
    if (defined $data->{'rules'}) {
        $self->{'rules'} = $data->{'rules'}
    } else {
        confess "Couldn't find any rules in $self->{'filename'}";
    }

    if (defined $data->{'questions'}) {
        $self->{'questions'} = $data->{'questions'};
    }
}

1;