Skip to content

Commit

Permalink
WIP: fix tests after merging action implementation into latest master…
Browse files Browse the repository at this point in the history
… state
  • Loading branch information
madmike200590 committed Jul 7, 2024
1 parent 8191e89 commit 133553f
Show file tree
Hide file tree
Showing 83 changed files with 680 additions and 769 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

/**
* Configuration structure controlling how {@link AggregateLiteral}s are compiled during program normalization in
* {@link Alpha#normalizeProgram(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program)}.
* {@link Alpha#normalizeProgram(at.ac.tuwien.kr.alpha.api.programs.InputProgram)}.
*
* Copyright (c) 2021, the Alpha Team.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

public interface InputProgram extends Program<Rule<Head>> {

/**
* The test cases associated with this program.
*/
List<TestCase> getTestCases();
/**
* The test cases associated with this program.
*/
List<TestCase> getTestCases();

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package at.ac.tuwien.kr.alpha.api.programs.actions;

import java.util.List;
import at.ac.tuwien.kr.alpha.api.programs.terms.ActionResultTerm;
import at.ac.tuwien.kr.alpha.api.programs.terms.Term;

import at.ac.tuwien.kr.alpha.api.terms.ActionResultTerm;
import at.ac.tuwien.kr.alpha.api.terms.Term;
import java.util.List;

/**
* An action that gets executed as part of an action rule in an evolog program firing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ default BasicAtom getHeadAtom() {
return this.isConstraint() ? null : this.getHead().getAtom();
}

boolean isGround();

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

public interface RuleInstantiator {

BasicAtom instantiate(InstantiableHead ruleHead, Substitution substitution);
BasicAtom instantiate(InstantiableHead ruleHead, Substitution substitution);

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

public interface ActionHead extends NormalHead {

String getActionName();
String getActionName();

List<Term> getActionInputTerms();
List<Term> getActionInputTerms();

VariableTerm getActionOutputTerm();
VariableTerm getActionOutputTerm();

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

public interface InstantiableHead extends Head {

BasicAtom instantiate(RuleInstantiator instantiator, Substitution substitution);
BasicAtom instantiate(RuleInstantiator instantiator, Substitution substitution);

}
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
package at.ac.tuwien.kr.alpha.api.programs.terms;

/**
* A term representing the result of an evolog action (i.e. result of action function application).
* Action result terms are function terms with symbol "success" or "error" depending on whether the corresponding action was sucessful.
* There is always one argument which is either some term representing the actual function result or an error message, respectively.
*/
/**
* A term representing the result of an evolog action (i.e. result of action function application).
* Action result terms are function terms with symbol "success" or "error" depending on whether the corresponding action was sucessful.
* There is always one argument which is either some term representing the actual function result or an error message, respectively.
*/
public interface ActionResultTerm<T extends Term> extends FunctionTerm {

public static final String SUCCESS_SYMBOL = "success";
public static final String ERROR_SYMBOL = "error";
public static final String SUCCESS_SYMBOL = "success";
public static final String ERROR_SYMBOL = "error";

/**
* True if the action that generated this result was successful (i.e. executed normally).
*/
boolean isSuccess();
/**
* True if the action that generated this result was successful (i.e. executed normally).
*/
boolean isSuccess();

/**
* True if the action that generated this result failed (i.e. threw an error in execution).
*/
boolean isError();
/**
* True if the action that generated this result failed (i.e. threw an error in execution).
*/
boolean isError();

/**
* Gets the actual value wrapped in this result.
* Either a term representing the action return value or a string term representing an error
* message.s
*/
T getValue();
/**
* Gets the actual value wrapped in this result.
* Either a term representing the action return value or a string term representing an error
* message.s
*/
T getValue();

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,7 @@
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package at.ac.tuwien.kr.alpha.core.externals;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.reflections.Reflections;
import org.reflections.scanners.MethodAnnotationsScanner;
package at.ac.tuwien.kr.alpha.commons.externals;

import at.ac.tuwien.kr.alpha.api.common.fixedinterpretations.PredicateInterpretation;
import at.ac.tuwien.kr.alpha.api.externals.Predicate;
Expand All @@ -44,13 +32,11 @@
import at.ac.tuwien.kr.alpha.commons.Predicates;
import at.ac.tuwien.kr.alpha.commons.programs.atoms.Atoms;
import at.ac.tuwien.kr.alpha.commons.programs.terms.Terms;
import at.ac.tuwien.kr.alpha.core.common.fixedinterpretations.BinaryPredicateInterpretation;
import at.ac.tuwien.kr.alpha.core.common.fixedinterpretations.BindingMethodPredicateInterpretation;
import at.ac.tuwien.kr.alpha.core.common.fixedinterpretations.IntPredicateInterpretation;
import at.ac.tuwien.kr.alpha.core.common.fixedinterpretations.LongPredicateInterpretation;
import at.ac.tuwien.kr.alpha.core.common.fixedinterpretations.MethodPredicateInterpretation;
import at.ac.tuwien.kr.alpha.core.common.fixedinterpretations.SuppliedPredicateInterpretation;
import at.ac.tuwien.kr.alpha.core.common.fixedinterpretations.UnaryPredicateInterpretation;
import org.reflections.Reflections;
import org.reflections.scanners.MethodAnnotationsScanner;

import java.lang.reflect.Method;
import java.util.*;

public final class Externals {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package at.ac.tuwien.kr.alpha.commons.externals;

import at.ac.tuwien.kr.alpha.api.programs.terms.ConstantTerm;
import at.ac.tuwien.kr.alpha.api.common.fixedinterpretations.PredicateInterpretation;
import at.ac.tuwien.kr.alpha.api.programs.terms.Term;

import java.util.List;
import java.util.Set;

import at.ac.tuwien.kr.alpha.api.common.fixedinterpretations.PredicateInterpretation;
import at.ac.tuwien.kr.alpha.api.terms.ConstantTerm;
import at.ac.tuwien.kr.alpha.api.terms.Term;

// TODO this looks like a duplicate
public interface PredicateInterpretationImpl extends PredicateInterpretation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@
* Copyright (c) 2017-2019, the Alpha Team.
*/
// TODO rename this to InputProgramImpl or some such
class ASPCore2ProgramImpl extends AbstractProgram<Rule<Head>> implements InputProgram {
class InputProgramImpl extends AbstractProgram<Rule<Head>> implements InputProgram {

static final ASPCore2ProgramImpl EMPTY = new ASPCore2ProgramImpl(Collections.emptyList(), Collections.emptyList(), new InlineDirectivesImpl(), Collections.emptyList());
static final InputProgramImpl EMPTY = new InputProgramImpl(Collections.emptyList(), Collections.emptyList(), new InlineDirectivesImpl(), Collections.emptyList());

private final List<TestCase> testCases;

ASPCore2ProgramImpl(List<Rule<Head>> rules, List<Atom> facts, InlineDirectives inlineDirectives, List<TestCase> testCases) {
InputProgramImpl(List<Rule<Head>> rules, List<Atom> facts, InlineDirectives inlineDirectives, List<TestCase> testCases) {
super(rules, facts, inlineDirectives);
this.testCases = testCases;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import java.util.Collections;
import java.util.List;

import at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program;
import at.ac.tuwien.kr.alpha.api.programs.InlineDirectives;
import at.ac.tuwien.kr.alpha.api.programs.InputProgram;
import at.ac.tuwien.kr.alpha.api.programs.InlineDirectives;
import at.ac.tuwien.kr.alpha.api.programs.NormalProgram;
import at.ac.tuwien.kr.alpha.api.programs.atoms.Atom;
import at.ac.tuwien.kr.alpha.api.programs.rules.NormalRule;
Expand All @@ -22,25 +21,25 @@ private Programs() {
}

public static InputProgram emptyProgram() {
return ASPCore2ProgramImpl.EMPTY;
return InputProgramImpl.EMPTY;
}

// TODO rename method
public static InputProgram newASPCore2Program(List<Rule<Head>> rules, List<Atom> facts, InlineDirectives inlineDirectives, List<TestCase> testCases) {
return new ASPCore2ProgramImpl(rules, facts, inlineDirectives, testCases);
public static InputProgram newInputProgram(List<Rule<Head>> rules, List<Atom> facts, InlineDirectives inlineDirectives, List<TestCase> testCases) {
return new InputProgramImpl(rules, facts, inlineDirectives, testCases);
}

// TODO rename method
public static InputProgram newASPCore2Program(List<Rule<Head>> rules, List<Atom> facts, InlineDirectives inlineDirectives) {
return new ASPCore2ProgramImpl(rules, facts, inlineDirectives, Collections.emptyList());
public static InputProgram newInputProgram(List<Rule<Head>> rules, List<Atom> facts, InlineDirectives inlineDirectives) {
return new InputProgramImpl(rules, facts, inlineDirectives, Collections.emptyList());
}

public static ASPCore2ProgramBuilder builder() {
return new ASPCore2ProgramBuilder();
public static InputProgramBuilder builder() {
return new InputProgramBuilder();
}

public static ASPCore2ProgramBuilder builder(InputProgram program) {
return new ASPCore2ProgramBuilder(program);
public static InputProgramBuilder builder(InputProgram program) {
return new InputProgramBuilder(program);
}

public static NormalProgram newNormalProgram(List<NormalRule> rules, List<Atom> facts, InlineDirectives inlineDirectives) {
Expand All @@ -60,69 +59,69 @@ public static InlineDirectives newInlineDirectives() {
}

/**
* Builder for more complex program construction scenarios, ensuring that an {@link ASPCore2ProgramImpl} is immutable
* Builder for more complex program construction scenarios, ensuring that an {@link InputProgramImpl} is immutable
*/
// TODO maybe rename
public static class ASPCore2ProgramBuilder {
public static class InputProgramBuilder {

private List<Rule<Head>> rules = new ArrayList<>();
private List<Atom> facts = new ArrayList<>();
private InlineDirectives inlineDirectives = new InlineDirectivesImpl();

private List<TestCase> testCases = new ArrayList<>();

public ASPCore2ProgramBuilder(InputProgram prog) {
public InputProgramBuilder(InputProgram prog) {
this.addRules(prog.getRules());
this.addFacts(prog.getFacts());
this.addInlineDirectives(prog.getInlineDirectives());
this.addTestCases(prog.getTestCases());
}

public ASPCore2ProgramBuilder() {
public InputProgramBuilder() {

}

public ASPCore2ProgramBuilder addRules(List<Rule<Head>> rules) {
public InputProgramBuilder addRules(List<Rule<Head>> rules) {
this.rules.addAll(rules);
return this;
}

public ASPCore2ProgramBuilder addRule(Rule<Head> r) {
public InputProgramBuilder addRule(Rule<Head> r) {
this.rules.add(r);
return this;
}

public ASPCore2ProgramBuilder addFacts(List<Atom> facts) {
public InputProgramBuilder addFacts(List<Atom> facts) {
this.facts.addAll(facts);
return this;
}

public ASPCore2ProgramBuilder addFact(Atom fact) {
public InputProgramBuilder addFact(Atom fact) {
this.facts.add(fact);
return this;
}

public ASPCore2ProgramBuilder addInlineDirectives(InlineDirectives inlineDirectives) {
public InputProgramBuilder addInlineDirectives(InlineDirectives inlineDirectives) {
this.inlineDirectives.accumulate(inlineDirectives);
return this;
}

public ASPCore2ProgramBuilder addTestCase(TestCase testCase) {
public InputProgramBuilder addTestCase(TestCase testCase) {
this.testCases.add(testCase);
return this;
}

public ASPCore2ProgramBuilder addTestCases(List<TestCase> testCases) {
public InputProgramBuilder addTestCases(List<TestCase> testCases) {
this.testCases.addAll(testCases);
return this;
}

public ASPCore2ProgramBuilder accumulate(InputProgram prog) {
public InputProgramBuilder accumulate(InputProgram prog) {
return this.addRules(prog.getRules()).addFacts(prog.getFacts()).addInlineDirectives(prog.getInlineDirectives()).addTestCases(prog.getTestCases());
}

public InputProgram build() {
return Programs.newASPCore2Program(this.rules, this.facts, this.inlineDirectives, this.testCases);
return Programs.newInputProgram(this.rules, this.facts, this.inlineDirectives, this.testCases);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import java.util.function.Supplier;

import at.ac.tuwien.kr.alpha.api.ComparisonOperator;
import at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program;
import at.ac.tuwien.kr.alpha.api.programs.InlineDirectives;
import at.ac.tuwien.kr.alpha.api.programs.InputProgram;
import at.ac.tuwien.kr.alpha.api.programs.Predicate;
import at.ac.tuwien.kr.alpha.api.programs.atoms.AggregateAtom;
import at.ac.tuwien.kr.alpha.api.programs.atoms.AggregateAtom.AggregateElement;
Expand Down Expand Up @@ -35,6 +35,7 @@
import at.ac.tuwien.kr.alpha.commons.util.IdGenerator;
import at.ac.tuwien.kr.alpha.commons.util.Util;

// TODO add support for action rules
public class Reifier {

// Predicates describing rules.
Expand Down Expand Up @@ -193,7 +194,7 @@ public Reifier(Supplier<IdGenerator<ConstantTerm<?>>> idGeneratorProvider) {
this.idGeneratorProvider = idGeneratorProvider;
}

public Set<BasicAtom> reifyProgram(ASPCore2Program program) {
public Set<BasicAtom> reifyProgram(InputProgram program) {
ReificationContext ctx = new ReificationContext(idGeneratorProvider.get());
reifyDirectives(ctx, program.getInlineDirectives());
for (Atom fact : program.getFacts()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public abstract class AbstractRule<H extends Head> implements Rule<H> {
private final Set<Literal> bodyLiteralsPositive;
private final Set<Literal> bodyLiteralsNegative;

public AbstractRule(H head, List<Literal> body) {
public AbstractRule(H head, Set<Literal> body) {
this.head = head;
Set<Literal> positiveBody = new LinkedHashSet<>();
Set<Literal> negativeBody = new LinkedHashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
package at.ac.tuwien.kr.alpha.commons.programs.rules;

import java.util.List;
import java.util.Set;

import at.ac.tuwien.kr.alpha.api.programs.literals.Literal;
import at.ac.tuwien.kr.alpha.api.programs.rules.heads.Head;
Expand All @@ -38,7 +39,7 @@
*/
class BasicRule extends AbstractRule<Head> {

BasicRule(Head head, List<Literal> body) {
BasicRule(Head head, Set<Literal> body) {
super(head, body);
}

Expand Down
Loading

0 comments on commit 133553f

Please sign in to comment.