use of at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl in project Alpha by alpha-asp.
the class StratifiedEvaluationTest method testNegatedExternalLiteral.
@Test
public void testNegatedExternalLiteral() throws Exception {
String asp = "claimedTruth(bla). truth(X) :- claimedTruth(X), &sayTrue[X]. lie(X) :- claimedTruth(X), not &sayTrue[X].";
Map<String, PredicateInterpretation> externals = new HashMap<>();
externals.put("sayTrue", Externals.processPredicateMethod(this.getClass().getMethod("sayTrue", Object.class)));
ProgramParser parserWithExternals = new ProgramParserImpl();
AnalyzedProgram analyzed = AnalyzedProgram.analyzeNormalProgram(normalizer.apply(parserWithExternals.parse(asp, externals)));
CompiledProgram evaluated = new StratifiedEvaluation().apply(analyzed);
Set<AnswerSet> answerSets = solveCompiledProg.apply(evaluated);
TestUtils.assertAnswerSetsEqual("claimedTruth(bla), truth(bla)", answerSets);
}
use of at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl in project Alpha by alpha-asp.
the class StratifiedEvaluationRegressionTest method runTest.
@ParameterizedTest
@MethodSource("at.ac.tuwien.kr.alpha.core.programs.transformation.StratifiedEvaluationRegressionTest#params")
public void runTest(String aspString, Consumer<CompiledProgram> programVerifier, Consumer<Set<AnswerSet>> resultVerifier) {
// Parse and pre-evaulate program
ProgramParser parser = new ProgramParserImpl();
ASPCore2Program prog = parser.parse(aspString);
AnalyzedProgram analyzed = AnalyzedProgram.analyzeNormalProgram(new NormalizeProgramTransformation(SystemConfig.DEFAULT_AGGREGATE_REWRITING_CONFIG).apply(prog));
CompiledProgram evaluated = new StratifiedEvaluation().apply(analyzed);
// Verify stratified evaluation result
programVerifier.accept(evaluated);
// Solve remaining program
AtomStore atomStore = new AtomStoreImpl();
Grounder grounder = GrounderFactory.getInstance("naive", evaluated, atomStore, false);
Solver solver = SolverFactory.getInstance(new SystemConfig(), atomStore, grounder);
Set<AnswerSet> answerSets = solver.collectSet();
resultVerifier.accept(answerSets);
}
use of at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl in project Alpha by alpha-asp.
the class ChoiceManagerTests method setUp.
@BeforeEach
public void setUp() {
String testProgram = "h :- b1, b2, not b3, not b4.";
ASPCore2Program parsedProgram = new ProgramParserImpl().parse(testProgram);
CompiledProgram internalProgram = InternalProgram.fromNormalProgram(new NormalizeProgramTransformation(SystemConfig.DEFAULT_AGGREGATE_REWRITING_CONFIG).apply(parsedProgram));
atomStore = new AtomStoreImpl();
grounder = new NaiveGrounder(internalProgram, atomStore, true);
WritableAssignment assignment = new TrailAssignment(atomStore);
NoGoodStore store = new NoGoodStoreAlphaRoaming(assignment);
choiceManager = new ChoiceManager(assignment, store);
}
use of at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl in project Alpha by alpha-asp.
the class HeadBodyTransformationTests method checkNumberOfRulesAndParse.
private ASPCore2Program checkNumberOfRulesAndParse(List<String> strRules, int numberOfRules) {
assertEquals(numberOfRules, strRules.size());
String strProgram = strRules.stream().collect(Collectors.joining(System.lineSeparator()));
ASPCore2Program parsedProgram = new ProgramParserImpl().parse(strProgram);
assertEquals(numberOfRules, parsedProgram.getRules().size());
return parsedProgram;
}
use of at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl in project Alpha by alpha-asp.
the class UnifierTest method parseAtom.
private BasicAtom parseAtom(String atom) {
ProgramParser programParser = new ProgramParserImpl();
ASPCore2Program program = programParser.parse(atom + ".");
return (BasicAtom) program.getFacts().get(0);
}
Aggregations