AI-Logic-AnswerSet
view release on metacpan or search on metacpan
lib/AI/Logic/AnswerSet.pm view on Meta::CPAN
}
else {
my $command = "./dlv --";
(@returned_value) = `$command`;
}
return @returned_value;
}
sub selectOutput { # Select one of the outputs returned by the iterative execution of more input programs
my @stdoutput = @{$_[0]};
my $n = $_[1];
return @{$stdoutput[$n]};
}
sub getFacts { # Return the facts of the input program
lib/AI/Logic/AnswerSet.pm view on Meta::CPAN
my @second;
if($_[1]) {
@second = @{$_[1]};
}
my @third;
if($_[2]) {
@third = @{$_[2]};
}
my @selectedAS;
my @predList;
my @pred;
if(@second) {
if($second[0] =~ /\d+/) {
@selectedAS = @second;
if(@third) {
@predList = @third;
}
}
else {
@predList = @second;
if(@third) {
@selectedAS = @third;
}
}
}
foreach my $elem (@answerSets) {
if($elem =~ /(\w+).*\n/){
if(@predList) {
lib/AI/Logic/AnswerSet.pm view on Meta::CPAN
push @{$pred[$countAS]{$1}}, $elem;
}
}
else {
push @{$pred[$countAS]{$1}}, $elem;
}
}
}
if(@selectedAS) {
my $size = @selectedAS;
my @selectedPred;
for(my $i = 0; $i < $size; $i++) {
my $as = $selectedAS[$i];
push @selectedPred, $pred[$as];
}
return @selectedPred;
}
return @pred;
}
sub _existsPred { #Verifies the existence of a predicate (private use only)
my $pred = $_[0];
my @predList = @{$_[1]};
lib/AI/Logic/AnswerSet.pm view on Meta::CPAN
return 0;
}
sub getPred { #Returns the predicates from the array of hashes
my @pr = @{$_[0]};
return @{$pr[$_[1]]{$_[2]}};
}
sub getProjection { #Returns the values selected by the user
my @pr = @{$_[0]};
my @projection;
my @res = @{$pr[$_[1]]{$_[2]}};
my $size = @res;
my $fieldsStr;
for(my $i = 0; $i < $size; $i++) {
lib/AI/Logic/AnswerSet.pm view on Meta::CPAN
my @outputs = AI::Logic::AnswerSet::iterativeExec("3col.txt","nodes.txt","./instances");
In this case the nodes of each graph are the same, but not the edges.
Notice that in order to correctly use this method, the user must specify the path
to the instances (the edges, in this case).
The output of this function is a two-dimensional array; each element corresponds to the result
of a single DLV execution, exactly as in the case of the function C<singleExec()>.
=head3 selectOutput
This method allows to get one of the results of C<iterativeExec>.
my @outputs = AI::Logic::AnswerSet::iterativeExec("3col.txt","nodes.txt","./instances");
my @out = AI::Logic::AnswerSet::selectOutput(\@outputs,0);
In this case the first output is selected.
=head3 getASFromFile
Parses the output of a DLV execution saved in a file and gather the answer sets.
AI::Logic::AnswerSet::executeFromFileAndSave("outprog.txt","dlvprog.txt","");
my @result = AI::Logic::AnswerSet::getASFromFile("outprog.txt");
=head3 getAS
( run in 0.511 second using v1.01-cache-2.11-cpan-49f99fa48dc )