How can I use sign in array of initial facts with Perl module AI::ExpertSystem::Advanced

StackOverflow https://stackoverflow.com/questions/15596906

  •  29-03-2022
  •  | 
  •  

Pergunta

I am trying to use the Perl AI::ExpertSystem::Advanced module, and I try to use sign in the array of initial facts. The documentation of this module shows an example:

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

but there is something wrong (syntax error). I thing that one ] missing at the end of code.

First question: What is the correct form? When I run the example my terminal shows me a lot of errors.

Second question: Can I use a file to stored initial facts?

Thanks for your answers.

Error log:

when I use example from documentation:

syntax error at mix.pl line 24, near "])"
Global symbol "$ai" requires explicit package name at mix.pl line 26.
Missing right curly or square bracket at mix.pl line 27, at end of line
Execution of mix.pl aborted due to compilation errors.

When I put ] in its correct place at the end of expression: initial_facts => ['I', ['F', '-'], ['G', '+']]);

Attribute (initial_facts) does not pass the type constraint because: Validation failed for 'ArrayRef[Str]' with value ARRAY(0x3268038) at C:/Perl64/lib/Moose/Meta/Attribute.pm line 1274.
  Moose::Meta::Attribute::verify_against_type_constraint('Moose::Meta::Attribute=HASH(0x3111108)', 'ARRAY(0x3268038)', 'instance', 'AI::ExpertSystem::Advanced=HASH(0x30ef068)') called at C:/Perl64/lib/Moose/Meta/Attribute.pm line 1261
  Moose::Meta::Attribute::_coerce_and_verify('Moose::Meta::Attribute=HASH(0x3111108)', 'ARRAY(0x3268038)', 'AI::ExpertSystem::Advanced=HASH(0x30ef068)') called at C:/Perl64/lib/Moose/Meta/Attribute.pm line 531
  Moose::Meta::Attribute::initialize_instance_slot('Moose::Meta::Attribute=HASH(0x3111108)', 'Moose::Meta::Instance=HASH(0x32673d8)', 'AI::ExpertSystem::Advanced=HASH(0x30ef068)', 'HASH(0x3118298)') called at C:/Perl64/lib/Class/MOP/Class.pm line 525
  Class::MOP::Class::_construct_instance('Moose::Meta::Class=HASH(0x2eb2418)', 'HASH(0x3118298)') called at C:/Perl64/lib/Class/MOP/Class.pm line 498
  Class::MOP::Class::new_object('Moose::Meta::Class=HASH(0x2eb2418)', 'HASH(0x3118298)') called at C:/Perl64/lib/Moose/Meta/Class.pm line 274
  Moose::Meta::Class::new_object('Moose::Meta::Class=HASH(0x2eb2418)', 'HASH(0x3118298)') called at C:/Perl64/lib/Moose/Object.pm line 28
  Moose::Object::new('AI::ExpertSystem::Advanced', 'viewer_class', 'terminal', 'knowledge_db', 'AI::ExpertSystem::Advanced::KnowledgeDB::YAML=HASH(0x3118478)', 'verbose', 1, 'initial_facts', 'ARRAY(0x3268038)') called at mix.pl line 20
Foi útil?

Solução

This is a bug in the documentation (and possibly in the module itself).

To set the object up with negative initial facts you need to create the dictionary object first.

my $initial_facts_dict = AI::ExpertSystem::Advanced::Dictionary->new(
    stack => [ 'I', ['F', '-'], ['G', '+'] ]);

my $ai = AI::ExpertSystem::Advanced->new(
    viewer_class => 'terminal',
    knowledge_db => $yaml_kdb,
    initial_facts_dict => $initial_facts_dict,
);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top