AI-Logic-AnswerSet
view release on metacpan or search on metacpan
lib/AI/Logic/AnswerSet.pm view on Meta::CPAN
open(SAVESTDOUT, ">&STDOUT") or die "Can't save STDOUT: $!\n";
open(STDOUT, ">$_[0]") or die "Can't open STDOUT to $_[0]", "$!\n";
my @args = ("./dlv", "$_[1]");
system(@args) == 0
or die "system @args failed: $?";
open(STDOUT,">&SAVESTDOUT"); #close file and restore STDOUT
close OUTPUT;
}
sub executeAndSave { #Executes DLV and saves the output of the program written by the user in a file
open(SAVESTDOUT, ">&STDOUT") or die "Can't save STDOUT: $!\n";
open(STDOUT, ">$_[0]") or die "Can't open STDOUT to $_[0]", "$!\n";
my @args = ("./dlv --");
system(@args) == 0 or die "system @args failed: $?";
open(STDOUT,">&SAVESTDOUT"); #close file and restore STDOUT
close OUTPUT;
}
sub iterativeExec { # Executes an input program with several instances and stores them in a bidimensional array
my @input = @_;
my @returned_value;
lib/AI/Logic/AnswerSet.pm view on Meta::CPAN
my $elem = $files[$i];
chomp $elem;
my @args = ("./dlv", "@input", "$dir$elem", "$option");
my (@out) = `@args`;
push @{$returned_value[$i]}, @out;
}
}
else {
print "INPUT ERROR\n";
}
return @returned_value;
}
sub singleExec { # Executes a single input program or opens the DLV terminal and stores it in an array
my @input = @_;
my @returned_value;
lib/AI/Logic/AnswerSet.pm view on Meta::CPAN
sub getFacts { # Return the facts of the input program
my $input = shift;
my @isAFile = stat($input);
my @facts;
if(@isAFile) {
open INPUT, "<", "$input";
my @rows = <INPUT>;
foreach my $row (@rows) {
if($row =~ /^(\w+)(\(((\w|\d|\.)+,?)*\))?\./) {
push @facts, $row;
}
}
close INPUT;
}
else {
my @str = split /\. /,$input;
foreach my $elem (@str) {
if($elem =~ /^(\w+)(\(((\w|\d|\.)+,?)*\))?\.?$/) {
push @facts, $elem;
}
}
( run in 0.322 second using v1.01-cache-2.11-cpan-4e96b696675 )