Search in sources :

Example 11 with AnswerSetBuilder

use of at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder in project Alpha by alpha-asp.

the class AnswerSetQueryTest method matchPredicate.

@Test
public void matchPredicate() {
    AnswerSetBuilder bld = new AnswerSetBuilder();
    // @formatter:off
    bld.predicate("p").symbolicInstance("a").symbolicInstance("b").predicate("q").symbolicInstance("x");
    // @formatter:on
    AnswerSet as = bld.build();
    List<Atom> queryResult = as.query(AnswerSetQueryImpl.forPredicate(Predicates.getPredicate("p", 1)));
    assertEquals(2, queryResult.size());
    for (Atom a : queryResult) {
        assertTrue(a.getPredicate().equals(Predicates.getPredicate("p", 1)));
    }
}
Also used : AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) AnswerSetBuilder(at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder) Atom(at.ac.tuwien.kr.alpha.api.programs.atoms.Atom) Test(org.junit.jupiter.api.Test)

Example 12 with AnswerSetBuilder

use of at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder in project Alpha by alpha-asp.

the class AnswerSetQueryTest method matchString.

@Test
public void matchString() {
    AnswerSetBuilder bld = new AnswerSetBuilder();
    bld.predicate("p").symbolicInstance("a").instance("a");
    AnswerSet as = bld.build();
    AnswerSetQueryImpl stringQuery = AnswerSetQueryImpl.forPredicate(Predicates.getPredicate("p", 1)).withStringEquals(0, "a");
    List<Atom> queryResult = as.query(stringQuery);
    assertEquals(1, queryResult.size());
}
Also used : AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) AnswerSetBuilder(at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder) Atom(at.ac.tuwien.kr.alpha.api.programs.atoms.Atom) Test(org.junit.jupiter.api.Test)

Example 13 with AnswerSetBuilder

use of at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder in project Alpha by alpha-asp.

the class AnswerSetQueryTest method matchSymbolicConstant.

@Test
public void matchSymbolicConstant() {
    AnswerSetBuilder bld = new AnswerSetBuilder();
    bld.predicate("p").symbolicInstance("a").instance("a");
    AnswerSet as = bld.build();
    AnswerSetQueryImpl constantQuery = AnswerSetQueryImpl.forPredicate(Predicates.getPredicate("p", 1)).withConstantEquals(0, "a");
    List<Atom> queryResult = as.query(constantQuery);
    assertEquals(1, queryResult.size());
}
Also used : AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) AnswerSetBuilder(at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder) Atom(at.ac.tuwien.kr.alpha.api.programs.atoms.Atom) Test(org.junit.jupiter.api.Test)

Example 14 with AnswerSetBuilder

use of at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder in project Alpha by alpha-asp.

the class AnswerSetQueryTest method matchTerm.

@Test
public void matchTerm() {
    AnswerSetBuilder bld = new AnswerSetBuilder();
    bld.predicate("p").instance(1).instance(2).instance(3).instance(4).instance(5).instance("bla").symbolicInstance("blubb");
    AnswerSet as = bld.build();
    AnswerSetQueryImpl equalTerm = AnswerSetQueryImpl.forPredicate(Predicates.getPredicate("p", 1)).withTermEquals(0, Terms.newConstant(1));
    List<Atom> queryResult = as.query(equalTerm);
    assertEquals(1, queryResult.size());
    Atom retrievedAtom = queryResult.get(0);
    assertTrue(retrievedAtom.getTerms().get(0).equals(Terms.newConstant(1)));
}
Also used : AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) AnswerSetBuilder(at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder) Atom(at.ac.tuwien.kr.alpha.api.programs.atoms.Atom) Test(org.junit.jupiter.api.Test)

Example 15 with AnswerSetBuilder

use of at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder in project Alpha by alpha-asp.

the class AnswerSetToXlsxWriterTest method writeAnswerSetFilesTest.

@Test
public void writeAnswerSetFilesTest() throws IOException {
    AnswerSet as = new AnswerSetBuilder().predicate("bla").instance("blubb", "blubb").instance("foo", "bar").predicate("foo").instance("bar").instance("baz").predicate("complex").instance(Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3)).build();
    Path tmpDir = Files.createTempDirectory("alpha-test-xlsx-output");
    AnswerSetToXlsxWriter writer = new AnswerSetToXlsxWriter(tmpDir.toString() + "/alphaAnswerSet");
    writer.accept(0, as);
    File tmpDirFile = tmpDir.toFile();
    File[] generatedFiles = tmpDirFile.listFiles();
    assertEquals(1, generatedFiles.length);
    File answerSetFile = generatedFiles[0];
    assertEquals("alphaAnswerSet.0.xlsx", answerSetFile.getName());
    try (Workbook wb = WorkbookFactory.create(answerSetFile)) {
        AnswerSetToWorkbookMapperTest.assertWorkbookMatchesAnswerSet(wb, as);
    }
    // clean up
    answerSetFile.delete();
    tmpDirFile.delete();
}
Also used : Path(java.nio.file.Path) AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) AnswerSetBuilder(at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder) File(java.io.File) Workbook(org.apache.poi.ss.usermodel.Workbook) AnswerSetToWorkbookMapperTest(at.ac.tuwien.kr.alpha.app.mappers.AnswerSetToWorkbookMapperTest) Test(org.junit.jupiter.api.Test)

Aggregations

AnswerSetBuilder (at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder)21 AnswerSet (at.ac.tuwien.kr.alpha.api.AnswerSet)20 Test (org.junit.jupiter.api.Test)20 Alpha (at.ac.tuwien.kr.alpha.api.Alpha)12 HashSet (java.util.HashSet)12 InputConfig (at.ac.tuwien.kr.alpha.api.config.InputConfig)8 ASPCore2Program (at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program)7 Atom (at.ac.tuwien.kr.alpha.api.programs.atoms.Atom)7 InputProgram (at.ac.tuwien.kr.alpha.core.programs.InputProgram)4 Disabled (org.junit.jupiter.api.Disabled)4 InlineDirectivesImpl (at.ac.tuwien.kr.alpha.core.parser.InlineDirectivesImpl)3 ConstantTerm (at.ac.tuwien.kr.alpha.api.terms.ConstantTerm)2 Predicates (at.ac.tuwien.kr.alpha.commons.Predicates)2 Atoms (at.ac.tuwien.kr.alpha.commons.atoms.Atoms)2 Terms (at.ac.tuwien.kr.alpha.commons.terms.Terms)2 MethodPredicateInterpretation (at.ac.tuwien.kr.alpha.core.common.fixedinterpretations.MethodPredicateInterpretation)2 BasicRule (at.ac.tuwien.kr.alpha.core.rules.BasicRule)2 Path (java.nio.file.Path)2 List (java.util.List)2 Workbook (org.apache.poi.ss.usermodel.Workbook)2