Search code examples
perlviewerexpert-system

How can I use another viewer in AI::ExpertSystem::Advanced


I tried to use AI::ExpertSystem::Advanced. I read in documentation that I can use another viewers. You can see it there:

viewer
Is the object AI::ExpertSystem::Advanced will be using for printing what is happening and for interacting with the user (such as asking the asked_facts).

This is practical if you want to use a viewer object that is not provided by AI::ExpertSystem::Advanced::Viewer::Factory.

viewer_class
Is the the class name of the viewer. use the viewers AI::ExpertSystem::Advanced::Viewer::Factory offers, in this case you can pass the object or only the name of your favorite viewer.

or in this module I find this:

Offers different views, so user can interact with the expert system via a terminal or with a friendly user interface.

example of source is:

my $ai = AI::ExpertSystem::Advanced->new(
                    viewer_class => 'terminal',
                    knowledge_db => $yaml_kdb,
                    initial_facts => ['I'],
                    verbose => 1);

Can I use as viewer_class my browser or some CGI interface??? When yes how to use it??? I didnt find any example.


Solution

  • You will have to write your own "Viewer" class. Create a new module that extends from AI::ExpertSystem::Advanced::Viewer::Base and implement each method that has a stub in that base class. The source and documentation of `AI::ExpertSystem::Advanced::Viewer::Base' will prove to be helpful in this task.

    Update

    To write your own viewer class, create a file that looks something like this:

    package My::AI::Viewer;
    use Moose;
    extends 'AI::ExpertSystem::Advanced::Viewer::Base';
    
    sub debug {
        # your implementation goes here
    }
    

    ... When you are done with that class, I suppose you can pass its name to the constructor of the expert system module under the viewer_class key.