Pergunta

I am using AI::ExpertSystem::Advanced to run an expert system from web content.

I have a website where I run a Perl script with this code:

use strict;
use warnings;

use AI::ExpertSystem::Advanced;
use AI::ExpertSystem::Advanced::KnowledgeDB::Factory;
use Data::Dumper;
use File::Slurp;

open(LOG, ">C:\\xampp\\htdocs\\xampp\\bc\\log.txt");

print LOG "START EXPERT\n";
system("C:\\Perl\\bin\\perl C:\\xampp\\htdocs\\xampp\\bc\\create_yaml.pl");

print LOG "START CREATE DB\n";
my $yaml_kdb = AI::ExpertSystem::Advanced::KnowledgeDB::Factory->new('yaml', {
    filename => 'C:\\xampp\\htdocs\\xampp\\bc\\recepty.yaml'
});

print LOG "LOAD RECEPTY\n";
my $text = read_file(
    'C:\\xampp\\htdocs\\xampp\\bc\\knowledgebase.yaml',
    array_ref => 1,
    chomp     => 1
);

print LOG "LOAD DB\n";
my $ai = AI::ExpertSystem::Advanced->new(
    viewer_class  => 'terminal',
    knowledge_db  => $yaml_kdb,
    initial_facts => $text
);

print LOG "NEW ES\n";
$ai->mixed();

print LOG "RESULT DONE\n";
#$ai->summary();
close LOG;

I tried to create a log. When I run this source in terminal my log is full and all things are right. But when I run it from web it is something wrong. My log file is only:

START EXPERT
START CREATE DB
LOAD RECEPTY
LOAD DB

I think that something with creating new expert system is bad. Links or I dont know. What do you think?

ERROR OF MY LOCAL SERVER:

Compilation failed in require at C:/Perl/lib/Term/ReadLine/Perl.pm line 65. 
The system cannot find the path specified. Unable to get Terminal Size. 
The Win32 GetConsoleScreenBufferInfo call didn't work. 
The COLUMNS and LINES environment variables didn't work. 
The resize program didn't work. at C:/Perl/lib/Term/ReadKey.pm line 362. 
Compilation failed in require at C:/Perl/lib/Term/ReadLine/Perl.pm line 65.
Foi útil?

Solução

(Originally submitted as an answer to the duplicate question at How can I find place of error in perl )

The error messages in the question state that the error is thrown at C:/Perl/lib/Term/ReadKey.pm line 362 and that use Term::ReadKey appears at C:/Perl/lib/Term/ReadLine/Perl.pm line 65. If you are running this code in a CGI environment, using ReadLine/ReadKey makes no sense and it's unsurprising that they fail to initialize.

However, you're creating your ExpertSystem instance with viewer_class => 'terminal', which causes it to use AI::ExpertSystem::Advanced::Viewer::Terminal, which "Extends from AI::ExpertSystem::Advanced::Viewer::Base and its main purpose is to interact with a (console) terminal" (emphasis mine) and it uses ReadLine to do so. In order to make this work, you need to use a different viewer class which does not "interact with a (console) terminal".

Unfortunately, a search of metacpan finds no other available viewers, so you'll need to either find one somewhere else (the author of AI::ExpertSystem::Advanced may know where you can get one for CGI) or write your own viewer class.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top