Search in sources :

Example 16 with ASPCore2Program

use of at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program 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 17 with ASPCore2Program

use of at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program 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)

Example 18 with ASPCore2Program

use of at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program in project Alpha by alpha-asp.

the class AtomsTest method testIsExternalAtomGround.

@Test
public void testIsExternalAtomGround() {
    ASPCore2Program p1 = parser.parse("a :- &isFoo[1].", externals);
    Atom ext1 = p1.getRules().get(0).getBody().stream().findFirst().get().getAtom();
    assertExternalAtomGround(ext1, true);
    ASPCore2Program p2 = parser.parse("a :- &isFoo[bar(1)].", externals);
    Atom ext2 = p2.getRules().get(0).getBody().stream().findFirst().get().getAtom();
    assertExternalAtomGround(ext2, true);
    ASPCore2Program p3 = parser.parse("a :- &isFoo[BLA].", externals);
    Atom ext3 = p3.getRules().get(0).getBody().stream().findFirst().get().getAtom();
    assertExternalAtomGround(ext3, false);
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) BasicAtom(at.ac.tuwien.kr.alpha.api.programs.atoms.BasicAtom) Atom(at.ac.tuwien.kr.alpha.api.programs.atoms.Atom) ExternalAtom(at.ac.tuwien.kr.alpha.api.programs.atoms.ExternalAtom) Test(org.junit.jupiter.api.Test)

Example 19 with ASPCore2Program

use of at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program in project Alpha by alpha-asp.

the class AtomsTest method testIsBasicAtomGround.

@Test
public void testIsBasicAtomGround() {
    ASPCore2Program p = parser.parse("bla(blubb, foo(bar)).");
    Atom a = p.getFacts().get(0);
    assertBasicAtomGround(a, true);
    ASPCore2Program p1 = parser.parse("foo(1, 2, 3, \"bar\").");
    Atom a1 = p1.getFacts().get(0);
    assertBasicAtomGround(a1, true);
    ASPCore2Program p2 = parser.parse("foo(BAR).");
    Atom a2 = p2.getFacts().get(0);
    assertBasicAtomGround(a2, false);
    ASPCore2Program p3 = parser.parse("foo(b, a, r(\"bla\", BLUBB)).");
    Atom a3 = p3.getFacts().get(0);
    assertBasicAtomGround(a3, false);
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) BasicAtom(at.ac.tuwien.kr.alpha.api.programs.atoms.BasicAtom) Atom(at.ac.tuwien.kr.alpha.api.programs.atoms.Atom) ExternalAtom(at.ac.tuwien.kr.alpha.api.programs.atoms.ExternalAtom) Test(org.junit.jupiter.api.Test)

Example 20 with ASPCore2Program

use of at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program in project Alpha by alpha-asp.

the class AlphaImplTest method smallGraph.

@Test
public void smallGraph() throws Exception {
    Alpha system = new AlphaImpl();
    InputConfig inputCfg = InputConfig.forString("node(1). node(2). node(3). a :- &connected[1,2].");
    inputCfg.addPredicateMethod("connected", Externals.processPredicate((Integer a, Integer b) -> (a == 1 && b == 2) || (b == 2 || b == 3)));
    ASPCore2Program program = system.readProgram(inputCfg);
    Set<AnswerSet> actual = system.solve(program).collect(Collectors.toSet());
    Set<AnswerSet> expected = AnswerSetsParser.parse("{ a, node(1), node(2), node(3) }");
    assertEquals(expected, actual);
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) Alpha(at.ac.tuwien.kr.alpha.api.Alpha) InputConfig(at.ac.tuwien.kr.alpha.api.config.InputConfig) Test(org.junit.jupiter.api.Test)

Aggregations

ASPCore2Program (at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program)89 Test (org.junit.jupiter.api.Test)70 AnswerSet (at.ac.tuwien.kr.alpha.api.AnswerSet)23 NormalProgram (at.ac.tuwien.kr.alpha.api.programs.NormalProgram)22 Alpha (at.ac.tuwien.kr.alpha.api.Alpha)21 InputConfig (at.ac.tuwien.kr.alpha.api.config.InputConfig)19 AnalyzedProgram (at.ac.tuwien.kr.alpha.core.programs.AnalyzedProgram)15 ProgramParserImpl (at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl)14 DependencyGraph (at.ac.tuwien.kr.alpha.api.programs.analysis.DependencyGraph)12 CompiledProgram (at.ac.tuwien.kr.alpha.core.programs.CompiledProgram)11 Atom (at.ac.tuwien.kr.alpha.api.programs.atoms.Atom)10 Disabled (org.junit.jupiter.api.Disabled)9 SystemConfig (at.ac.tuwien.kr.alpha.api.config.SystemConfig)8 AtomStoreImpl (at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl)8 InputProgram (at.ac.tuwien.kr.alpha.core.programs.InputProgram)8 HashSet (java.util.HashSet)8 Predicate (at.ac.tuwien.kr.alpha.api.programs.Predicate)7 ComponentGraph (at.ac.tuwien.kr.alpha.api.programs.analysis.ComponentGraph)7 SCComponent (at.ac.tuwien.kr.alpha.api.programs.analysis.ComponentGraph.SCComponent)7 AtomStore (at.ac.tuwien.kr.alpha.core.common.AtomStore)7