The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

AI::ExpertSystem::Advanced::KnowledgeDB::Base - Base class for knowledge DBs.

DESCRIPTION

All knowledge databases that AI::ExpertSystem::Advanced uses should extend from this class.

This base class implements the basic methods required for extracting the rules, causes, goals and questions from the a plain text knowledge database, eg, all the records remain in the application memory instead of a database engine such as MySQL or SQLite.

Attributes

rules

This hash has the rules contained in the knowledge database. It's populated when an instance of AI::ExpertSystem::Advanced::KnowledgeDB::Base is created.

TIP: There's no sense in filling this hash if you are going to be using a database engine such as MySQL, SQLite or others. The hash is useful if your knowledge database will remain in application memory.

questions

Similar and same concept of rules, but this will have a list (if available) of what questions should be done to certain facts.

Methods

read()

This method reads the knowledge database. This is the only method you need to define even if you are going to load the database in memory or if you are going to query it.

rule_goals($rule)

Returns all the goals (usually only one) of the given $rule.

The goals should be returned as a AI::ExpertSystem::Advanced::Dictionary.

NOTE: Rewrite this method if you are not going to use the rules hash (eg, you will use a database engine).

rule_causes($rule)

Returns all the causes of the given $rule.

Same as rule_goals(), the causes should be returned as a AI::ExpertSystem::Advanced::Dictionary.

NOTE: Rewrite this method if you are not going to use the rules hash (eg, you will use a database engine).

find_rule_by_goal($goal)

Looks for the first rule that has the given goal in its goals.

If a rule is found then its number is returned, otherwise undef is returned.

NOTE: Rewrite this method if you are not going to use the rules hash (eg, you will use a database engine).

get_question($fact)

Looks for a question about the given $fact. If a question exists then this is returned, otherwise undef is returned.

NOTE: Rewrite this method if you are not going to use the rules hash (eg, you will use a database engine).

get_next_rule($current_rule)

Returns the ID of the next rule. When there are no more rules to work then undef should be returned.

When it starts looking for the first rule, $current_rule value will be undef.

NOTE: Rewrite this method if you are not going to use the rules hash (eg, you will use a database engine).

AUTHOR

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

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.