1

我正在尝试使用 PerlAI::ExpertSystem::Advanced模块,并尝试在初始事实数组中使用符号。该模块的文档显示了一个示例:

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

但是有问题(语法错误)。我认为]代码末尾缺少一个。

第一个问题:正确的形式是什么?当我运行该示例时,我的终端显示了很多错误。

第二个问题:我可以使用文件来存储初始事实吗?

感谢您的回答。

错误日志

当我使用文档中的示例时:

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.

当我]在表达式末尾放置正确的位置时: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
4

1 回答 1

1

这是文档中的一个错误(可能在模块本身中)。

要使用否定的初始事实设置对象,您需要首先创建字典对象。

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,
);
于 2013-03-24T17:16:06.847 回答