Search in sources :

Example 1 with ProgramParserImpl

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);
}
Also used : AnalyzedProgram(at.ac.tuwien.kr.alpha.core.programs.AnalyzedProgram) HashMap(java.util.HashMap) ProgramParser(at.ac.tuwien.kr.alpha.api.programs.ProgramParser) AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) PredicateInterpretation(at.ac.tuwien.kr.alpha.api.common.fixedinterpretations.PredicateInterpretation) ProgramParserImpl(at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl) CompiledProgram(at.ac.tuwien.kr.alpha.core.programs.CompiledProgram) Test(org.junit.jupiter.api.Test)

Example 2 with ProgramParserImpl

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);
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) Solver(at.ac.tuwien.kr.alpha.api.Solver) SystemConfig(at.ac.tuwien.kr.alpha.api.config.SystemConfig) AnalyzedProgram(at.ac.tuwien.kr.alpha.core.programs.AnalyzedProgram) ProgramParser(at.ac.tuwien.kr.alpha.api.programs.ProgramParser) AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) AtomStoreImpl(at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl) ProgramParserImpl(at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl) CompiledProgram(at.ac.tuwien.kr.alpha.core.programs.CompiledProgram) AtomStore(at.ac.tuwien.kr.alpha.core.common.AtomStore) Grounder(at.ac.tuwien.kr.alpha.core.grounder.Grounder) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with ProgramParserImpl

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);
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) NaiveGrounder(at.ac.tuwien.kr.alpha.core.grounder.NaiveGrounder) AtomStoreImpl(at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl) ProgramParserImpl(at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl) CompiledProgram(at.ac.tuwien.kr.alpha.core.programs.CompiledProgram) NormalizeProgramTransformation(at.ac.tuwien.kr.alpha.core.programs.transformation.NormalizeProgramTransformation) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with ProgramParserImpl

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;
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) ProgramParserImpl(at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl)

Example 5 with ProgramParserImpl

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);
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) ProgramParser(at.ac.tuwien.kr.alpha.api.programs.ProgramParser) ProgramParserImpl(at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl) BasicAtom(at.ac.tuwien.kr.alpha.api.programs.atoms.BasicAtom)

Aggregations

ProgramParserImpl (at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl)14 ASPCore2Program (at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program)11 AnswerSet (at.ac.tuwien.kr.alpha.api.AnswerSet)8 Solver (at.ac.tuwien.kr.alpha.api.Solver)5 ProgramParser (at.ac.tuwien.kr.alpha.api.programs.ProgramParser)5 InputProgram (at.ac.tuwien.kr.alpha.core.programs.InputProgram)4 CompiledProgram (at.ac.tuwien.kr.alpha.core.programs.CompiledProgram)3 Test (org.junit.jupiter.api.Test)3 SystemConfig (at.ac.tuwien.kr.alpha.api.config.SystemConfig)2 AtomStoreImpl (at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl)2 AnalyzedProgram (at.ac.tuwien.kr.alpha.core.programs.AnalyzedProgram)2 Alpha (at.ac.tuwien.kr.alpha.api.Alpha)1 PredicateInterpretation (at.ac.tuwien.kr.alpha.api.common.fixedinterpretations.PredicateInterpretation)1 BasicAtom (at.ac.tuwien.kr.alpha.api.programs.atoms.BasicAtom)1 Head (at.ac.tuwien.kr.alpha.api.rules.heads.Head)1 AtomStore (at.ac.tuwien.kr.alpha.core.common.AtomStore)1 Grounder (at.ac.tuwien.kr.alpha.core.grounder.Grounder)1 NaiveGrounder (at.ac.tuwien.kr.alpha.core.grounder.NaiveGrounder)1 NormalizeProgramTransformation (at.ac.tuwien.kr.alpha.core.programs.transformation.NormalizeProgramTransformation)1 HashMap (java.util.HashMap)1