Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evolog: Permit actions in stratifiable part of input programs #338

Draft
wants to merge 115 commits into
base: evolog-new
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
14d13e6
repo: Migrate to Java 17
lorenzleutgeb Dec 2, 2021
c6f79be
implementation skeleton for reification helper
madmike200590 Dec 15, 2021
6a888da
commons: draft implementation of reification logic for asp programs
madmike200590 Dec 17, 2021
f288581
Merge branch 'master' into reification
madmike200590 Dec 17, 2021
a34319c
API method and CLI option for reification
madmike200590 Jan 11, 2022
0aa1d30
refine reification
madmike200590 Jan 11, 2022
d7b9761
fix checkstyle violations
madmike200590 Jan 11, 2022
3240f1e
commons: unit tests for term reification
madmike200590 Jan 11, 2022
227fbb4
unit tests for basic and comparison atom reification
madmike200590 Jan 14, 2022
b4cf45b
unit tests for aggregate and external atom reification
madmike200590 Jan 26, 2022
40a336a
additional test for atom reification
madmike200590 Jan 26, 2022
f1779cb
constant term types: string, integer, symbol, object
madmike200590 Jan 26, 2022
7c8b746
correctly handle strings containing quotes
madmike200590 Jan 26, 2022
1de895d
add number of items for reified elements with list properties
madmike200590 Jan 31, 2022
39793fa
extend unit tests
madmike200590 Jan 31, 2022
e3c3892
integration test for reification feature
madmike200590 Jan 31, 2022
a990c8b
fix NPE in constraint reification
madmike200590 Jan 31, 2022
e955c13
Merge branch 'master' into reification
madmike200590 Feb 2, 2022
fdc4902
add action heads and draft evaluation
madmike200590 Feb 10, 2022
5097587
account for action heads in rewritings and rule translations
madmike200590 Feb 10, 2022
b975a9c
refactoring: factory methods for rules
madmike200590 Feb 11, 2022
b2f9c96
actions: file output draft
madmike200590 Feb 17, 2022
09e1b7c
actions: file input draft
madmike200590 Feb 17, 2022
21664ed
additional actions for input stream handling
madmike200590 Feb 24, 2022
4f9de69
actions: draft implementation
madmike200590 Mar 8, 2022
0f2fe31
remove useage of non-java-8-api
madmike200590 Mar 8, 2022
7f8ba4f
unit tests for new standard library externals
madmike200590 Mar 10, 2022
25008a4
adapt AlphaFactory to work with externally supplied action bindings
madmike200590 Mar 10, 2022
da7160d
WIP: refine action implementation
madmike200590 Jul 7, 2022
625a3d0
add ActionResultTerm interface and implementations
madmike200590 Aug 25, 2022
990da89
use ActionResultTerm interface in Action implementations
madmike200590 Aug 26, 2022
b8821da
add debug option to add action witnesses to answer set
madmike200590 Aug 29, 2022
dc0198d
specification for action implementation provider
madmike200590 Aug 29, 2022
e80c424
mock action provider for testing
madmike200590 Aug 29, 2022
399ec00
mock implementation provider and smoke test for actions
madmike200590 Sep 1, 2022
20c2b73
remove option to switch off stratified evaluation
madmike200590 Sep 3, 2022
6b2bba2
ensure statelessness of program transformations, reflect this in naming
madmike200590 Sep 3, 2022
7802ffb
incorporate action support into AlphaFactory, remove option to disabl…
madmike200590 Sep 5, 2022
491390f
fix mock implementation for actions
madmike200590 Sep 5, 2022
efd96e8
fix evolog hello world test
madmike200590 Sep 6, 2022
8312dcf
fix name generation for stream handles
madmike200590 Oct 3, 2022
db5544f
unit tests for actions
madmike200590 Oct 12, 2022
20a571e
merge evolog-new into evolog-actions-new
madmike200590 Oct 12, 2022
fcfb1b5
Merge branch 'master' into reification
madmike200590 Oct 12, 2022
ac6d27f
reify inline directives, move rule implementations to commons
madmike200590 Oct 12, 2022
f7f5e0c
adapt package structures: program components into program subpackages
madmike200590 Oct 12, 2022
50bdc42
code cleanup - move ASPCore2Program to commons module
madmike200590 Oct 12, 2022
dfcda1b
code cleanup - move NormalProgramImpl and InlineDirectivesImpl to com…
madmike200590 Oct 12, 2022
1e4e1c1
test for directive reification
madmike200590 Oct 12, 2022
5c1cfbe
explicit contract for ID generation in Reifier
madmike200590 Oct 12, 2022
5ec6adb
reify interval terms
madmike200590 Oct 12, 2022
09fe84e
code cleanup - improve exceptions
madmike200590 Oct 12, 2022
a910fb9
WIP: reduce useless object creation in Reifier
madmike200590 Oct 22, 2022
2d22309
improve naming and refactor: AnswerSetQuery -> AtomQuery, reification…
madmike200590 Oct 22, 2022
fee81a8
Improve logging output for debugging.
AntoniusW Dec 2, 2022
008a287
Merge pull request #348 from alpha-asp/improve_logging_for_debug
madmike200590 Dec 2, 2022
0a319f4
ci: Update Java Versions
lorenzleutgeb Dec 6, 2022
7fd591f
Merge pull request #349 from alpha-asp/java-update
madmike200590 Dec 11, 2022
1afecb8
fix checkstyle violations
madmike200590 Dec 11, 2022
c4ce84a
parsing method for atom sets for use in testing
madmike200590 Dec 12, 2022
38e27b8
remove unused import
madmike200590 Dec 12, 2022
23b6948
WIP: tests for reification
madmike200590 Dec 14, 2022
d28c2d6
No longer use Strings to encode substitutions in body-representing li…
AntoniusW Dec 20, 2022
b16072e
Add equals() and hashCode() to InternalRule and RuleAtomConstant.
AntoniusW Jan 2, 2023
c1e8afc
Issue 350: Upgrade Gradle to 7.6
madmike200590 Jan 2, 2023
28599b1
Issue 350: Upgrade Gradle version to 3.6
madmike200590 Jan 2, 2023
2f8927c
Merge pull request #351 from alpha-asp/issue_350_update_gradle
madmike200590 Jan 2, 2023
c14f075
Merge branch 'master' into ruleatom_nostring
AntoniusW Jan 3, 2023
e7877ea
Add test for recovering substitution with function terms from body-re…
AntoniusW Jan 3, 2023
5c93f91
Rename RuleAtomConstant to RuleAtomData.
AntoniusW Jan 3, 2023
55ee779
Check for inconsistent substitutions when comparing RuleAtomData.
AntoniusW Jan 4, 2023
e41c0d8
Small polish in BasicSubstitution as suggested by Michael Langowski.
AntoniusW Jan 4, 2023
b6f39e3
Merge pull request #353 from alpha-asp/ruleatom_nostring
madmike200590 Jan 4, 2023
f168b94
merge master; add reification test case for comparison atom
madmike200590 Jan 4, 2023
104b724
reification test for aggregate and external atoms
madmike200590 Jan 5, 2023
9a43dff
Update alpha-commons/src/main/java/at/ac/tuwien/kr/alpha/commons/prog…
madmike200590 Jan 5, 2023
af55383
merge branch master into reification
madmike200590 Jan 5, 2023
ce69537
java version to 11 instead of 17, set jvm target to 11 kotlin
madmike200590 Jan 5, 2023
4bd7fc7
merge origin/master
madmike200590 Jan 5, 2023
8879279
Merge pull request #315 from alpha-asp/java-17
AntoniusW Jan 5, 2023
acf0e94
ci: Upgrade actions/setup-java
lorenzleutgeb Jan 10, 2023
b8af1d7
Merge pull request #355 from alpha-asp/upgrade-setup-java
madmike200590 Jan 12, 2023
1e97745
Merge remote-tracking branch 'origin/master' into reification
madmike200590 Jan 12, 2023
28ab2bb
also reify constraints
madmike200590 Jan 12, 2023
3028684
Merge pull request #332 from alpha-asp/reification
AntoniusW Jan 13, 2023
b16b9d6
Add JaCoCo report aggregation (#356)
AntoniusW Jan 24, 2023
e049fbf
unit tests: grammar + parser skeleton
madmike200590 Feb 19, 2023
7237490
parsing for unit tests
madmike200590 Mar 2, 2023
2e4ffaf
Lexer rules for test-specific reserved words, slight syntax tweaks
madmike200590 Mar 3, 2023
4d1c69a
tests for unit test parsing
madmike200590 Mar 3, 2023
d79d556
skeleton implementation for unit test execution
madmike200590 Mar 3, 2023
10a1d13
implement unit test execution
madmike200590 Mar 3, 2023
0d0e4bc
commandline option to run unit tests
madmike200590 Mar 3, 2023
ecc9bbd
add 3-coloring example with unit tests
madmike200590 Mar 3, 2023
6248871
add assertion error messages to test result
madmike200590 Mar 5, 2023
be85567
negative tests for unit test support
madmike200590 Mar 5, 2023
a9d442b
delete accidentally commited generated source files
madmike200590 Mar 5, 2023
c7b1f9a
allow keywords as identifiers in programs
madmike200590 Mar 5, 2023
5dd8f80
remove obsolete TODO
madmike200590 Mar 5, 2023
5d04cc1
Merge pull request #358 from madmike200590/asp-unit-tests
madmike200590 Apr 28, 2023
e9dccb7
Make releasing Alpha more convenient by adding gradle release plugin …
madmike200590 Apr 28, 2023
ef74c9c
[Gradle Release Plugin] - pre tag commit: '0.7.0'.
madmike200590 Apr 28, 2023
2cce436
[Gradle Release Plugin] - new version commit: '0.8.0-SNAPSHOT'.
madmike200590 Apr 28, 2023
6512eea
Update dependencies to avoid several CVEs.
AntoniusWeinzierl Jul 24, 2023
2b1dddb
Merge pull request #363 from alpha-asp/issue_362
madmike200590 Dec 1, 2023
782c338
fix ParserTest - use updated type name InputProgram instead of ASPCor…
madmike200590 Dec 1, 2023
c7ec493
fix FunctionTermImpl#equals s.t. also subtypes can be equal
madmike200590 Dec 10, 2023
8d86445
Fix ActionsTest: check answer set content for answer set of write fil…
madmike200590 Jan 9, 2024
0bb76b1
Fix checkstyle violations
madmike200590 Jan 9, 2024
01c7038
add simple evolog examples
madmike200590 Jan 11, 2024
fac7e67
merge branch origin/master into evolog-actions-new
madmike200590 May 26, 2024
8191e89
WIP: merge action implementation back into state from master
madmike200590 May 26, 2024
133553f
WIP: fix tests after merging action implementation into latest master…
madmike200590 Jul 7, 2024
173f664
Fix tests after merging master
madmike200590 Jul 22, 2024
aad5520
Fix tests after merging changes from master
madmike200590 Jul 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
strategy:
matrix:
# We test against Java releases:
# - greater than 7
# - greater than or equal to 11
# AND
# - with LTS and in "Premier Support" phase
# OR
Expand All @@ -15,12 +15,12 @@ jobs:
# https://blogs.oracle.com/java-platform-group/oracle-jdk-releases-for-java-11-and-later
# https://www.oracle.com/technetwork/java/java-se-support-roadmap.html
java:
# LTS and in "Premier Support" as of 2019-03 (until 2022-03)
- 8
# LTS and in "Premier Support" as of 2019-03 (until 2023-09)
- 11
# LTS as of 2021-11 (until 2029)
- 17
# Not succeeded as of 2022-12
- 19
os: [ubuntu, windows]
env:
# We only post coverage data for exactly one build to coveralls.
Expand All @@ -40,7 +40,7 @@ jobs:
# See https://github.com/marketplace/actions/gradle-wrapper-validation
- uses: gradle/wrapper-validation-action@v1
# See https://github.com/marketplace/actions/setup-java-jdk
- uses: actions/setup-java@v2
- uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java }}
distribution: 'temurin'
Expand All @@ -52,7 +52,7 @@ jobs:
if: matrix.os == env.MAIN_OS && matrix.java == env.MAIN_JAVA
continue-on-error: true
with:
arguments: jacocoTestReport coveralls
arguments: jacocoAggregatedTestReport coveralls
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
- uses: codecov/codecov-action@v1
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ possibilities to interface with the ecosystem built around the Java Virtual Mach

## Getting Started

Download a current version of `alpha.jar` from [Releases](https://github.com/alpha-asp/Alpha/releases).
Download a current version of the distribution jar (`alpha-cli-app-${version}-bundled.jar`) from [Releases](https://github.com/alpha-asp/Alpha/releases) and save it as `alpha.jar` for convenience.

Running Alpha is as simple as running any other JAR:

Expand Down Expand Up @@ -52,19 +52,19 @@ Alpha uses the [Gradle build automation system](https://gradle.org). Executing
$ ./gradlew build
```

will automatically fetch all dependencies (declared in [`build.gradle`](build.gradle)) and compile the project.
will automatically fetch all dependencies (declared in [`build.gradle.kts`](build.gradle.kts)) and compile the project.

Artifacts generated will be placed in `build/`. Most notably you'll find files ready for distribution at
`build/distributions/`. They contain archives which in turn contain a `bin/` directory with scripts to run Alpha on Linux
Artifacts generated will be placed in the `build/` subfolder of the respective module. Most notably you'll find files ready for distribution at
`alpha-cli-app/build/distributions/`. They contain archives which in turn contain a `bin/` directory with scripts to run Alpha on Linux
and Windows.

If you want to generate a JAR file to be run standalone, execute

```bash
$ ./gradlew bundledJar
$ ./gradlew alpha-cli-app:bundledJar
```

and pick up `build/libs/alpha-bundled.jar`.
and pick up `alpha-cli-app/build/libs/alpha-cli-app-${version}-bundled.jar`.

### A Note on IDEs

Expand Down
70 changes: 38 additions & 32 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,70 @@

This document explains how to build and release Alpha.

First, decide which revision (= Git commit) of Alpha you want to release. This revision should be on `master`
and ideally ahead of any previously released revisions. We denote the Git commit hash of the revision to be
released as `$rev` (it is a reference to a commit, so it could be the name of a branch, say, `master` or just
a hash like `cafebabe`).

You probably have already checked out this version, but if you haven't, do so now:
The regular release workflow for Alpha assumes that a release will always be based on the latest commit in the `master` branch. In order to release Alpha, first checkout the `master` branch and make sure you're up to date:

```bash
$ git checkout $rev
$ git checkout master
$ git pull
```

Now is the time to make sure the revision you are about to release actually works fine. Run tests, try it out
manually, maybe go paranoid and `./gradlew clean` everything and try again. Only continue if you are happy with
the revision you are about to release, and avoid list minute fixes.
Now is the time to make sure the revision you are about to release actually works. Build it using `./gradlew clean build`, potentially do some manual tests, play around a bit, maybe go paranoid and `./gradlew clean build` everything once more. Only continue if you are happy with the state you are about to release, and avoid last minute fixes.

Next, give `$rev` a name, by tagging it. The naming convention for tags is
[Semantic Versioning 2](http://semver.org/spec/v2.0.0.html). **Read through the specification of Semantic
Versioning carefully, before releasing anything. If in doubt, read it again and seek advice.**
The actual release process consists of following steps:
- Create a release tag using gradle release plugin.
- From the tag created by gradle release plugin, create a release on github.

Make sure the version you want to release does not collide and fits with any
[tags already present on GitHub](https://github.com/alpha-asp/Alpha/tags). We denote the version to be released
as `$version` (it looks like "v0.1.0", "v1.0.0-beta", note it starts with the letter "v").
#### Creating a release tag using Gradle Release Plugin

```bash
$ git tag $version
```
Before running the release plugin, decide on a release version identifier and the next development version. Version identifiers must confirm to [Semantic Versioning 2](http://semver.org/spec/v2.0.0.html). **Read through the specification of Semantic Versioning carefully, before releasing anything. If in doubt, read it again and seek advice.** Also, make sure the version you want to release does not collide with any [tag already present on GitHub](https://github.com/alpha-asp/Alpha/tags). We denote the version to be released as `$version` (it looks like "0.1.0", "1.0.0-beta").

Now you push this tag to GitHub:
The next development version (denoted `$nextVersion`) is the version you expect to be the next release version. Note that it isn't set in stone since actual release versions are set during the release process. For example, if your release version is `0.9.0`, your next version could be `0.10.0` or `1.0.0`.

To create a release tag and set the correct versions in the `gradle.properties` file, call the gradle release plugin:

```bash
$ git push --tags
$ ./gradlew release -Prelease.useAutomaticVersion=true -Prelease.releaseVersion=$version -Prelease.newVersion=$nextVersion-SNAPSHOT
```
**Make sure you add the `-SNAPSHOT` qualifier to the next version!** This is the version that will be put into `gradle.properties` in the `master` branch after creating the release tag, i.e. subsequent builds of `master` (e.g. nightly builds from CI workflows) will have this version.

The release plugin automatically pushes all changes it makes in the repository. After running it, make sure:
- `gradle.properties` in `master` has the new `SNAPSHOT` version.
- On github, you can see a new tag with the same name as your release version.
- When you check out the tag, `gradle.properties` contains the correct version, i.e. the tag name.

Navigate to (Releases)[https://github.com/alpha-asp/Alpha/releases] and press "Draft a new release"). Fill in `$version`
as the name of your tag, and change the Release Title to `$version`. Feel free to write a release note (we currently
have no policy in place for release notes). If `$version` is below 1 or you are releasing a preview version, check the
box.

Now, let's generate two distribution packages of Alpha for convenience. You will attach two files to the release on
GitHub. `alpha.jar`, a self-contained and executbale JAR and `alpha.zip` which contains Alpha as JAR file, dependencies
as JAR files and two scripts to run Alpha on Unix-like and Windows respectively.
Now, let's generate some distribution packages of Alpha for convenience. You will attach the following files to the release on GitHub:
- `alpha-cli-app-$version-bundled.jar: A "fat-jar" containingthe Alpha CLI applications along with all dependencies in one jar file.
- Distribution zip- and tar-archives for the CLI application: Zip- and tar-versions of an archive with Alpha, all dependencies, and launcher scripts for windows and UNIX-like systems.
- A zip- and tar-archive of the source code for Alpha.

To generate `alpha.jar`:
To generate these artifacts, check out your release tag:

```bash
$ git checkout $version
```

To generate the "fat-jar":

```bash
$ ./gradlew alpha-cli-app:bundledJar
$ cp alpha-cli-app/build/libs/alpha-cli*-bundled.jar alpha.jar
```

To generate `alpha.zip`:
The jar file can be found in `./alpha-cli-app/build/libs/alpha-cli-app-$version-bundled.jar`

To generate distribution archives:

```bash
$ ./gradlew alpha-cli-app:distZip
$ cp alpha-cli-app/build/distributions/*.zip alpha.zip
$ ./gradlew alpha-cli-app:distZip && ./gradlew alpha-cli-app:distTar
```

Attach the two files to the release on GitHub, then publish the release. Lastly, check that everything is fine,
e.g. that the tag/version really points at the revision you wanted to rlease and that `alpha.zip` and `alpha.jar
downloaded from GitHub do what they are supposed to do.
The finished archives are located in `./alpha-cli-app/build/distributions/`.
Last `./gradlew clean` the project to get rid of all build artifacts, then create a `sources.zip` (using e.g. `zip -r sources.zip .`) and a `sources.tar.gz` (using e.g. `tar -czf /tmp/sources.tar.gz .`)

Attach the generated files to the release on GitHub, then publish the release. Last but not least, check that everything is fine, i.e. the files - when downloaded from the github release - do what they're supposed to.

Optionally, archive the release on Zenodo. If you do so, add the new identifier to `CITATION.cff`.
69 changes: 52 additions & 17 deletions alpha-api/src/main/java/at/ac/tuwien/kr/alpha/api/Alpha.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package at.ac.tuwien.kr.alpha.api;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;

import at.ac.tuwien.kr.alpha.api.common.fixedinterpretations.PredicateInterpretation;
import at.ac.tuwien.kr.alpha.api.config.InputConfig;
import at.ac.tuwien.kr.alpha.api.programs.InputProgram;
import at.ac.tuwien.kr.alpha.api.programs.NormalProgram;
import at.ac.tuwien.kr.alpha.api.programs.Predicate;
import at.ac.tuwien.kr.alpha.api.programs.atoms.BasicAtom;
import at.ac.tuwien.kr.alpha.api.programs.tests.TestResult;

/**
* Main API entry point for the Alpha ASP system. Provides facilities for parsing, normalizing and solving ASP programs.
Expand All @@ -24,18 +28,18 @@ public interface Alpha {
*
* @param cfg and {@link InputConfig} specifying program sources (strings, files) as well as config metadata (e.g. literate program,
* external atoms, etc)
* @return an {@link ASPCore2Program} representing the parsed ASP code from all sources referenced in the given {@link InputConfig}
* @return an {@link InputProgram} representing the parsed ASP code from all sources referenced in the given {@link InputConfig}
* @throws IOException in case one or more program sources (e.g. files) cannot be read, or parsing fails
*/
InputProgram readProgram(InputConfig cfg) throws IOException;

/**
* Reads and parses an {@link ASPCore2Program} from a list of {@link String}s representing paths.
* Reads and parses an {@link InputProgram} from a list of {@link String}s representing paths.
*
* @param literate flag indicating whether ASP code should be treated as "literate".
* @param externals Custom {@link PredicateInterpretation}s for user-defined external atoms
* @param paths a list of {@link String}s representing paths containing all sources from which ASP code should be read
* @return an {@link ASPCore2Program} representing the parsed ASP code from all given path strings
* @return an {@link InputProgram} representing the parsed ASP code from all given path strings
* @throws IOException in case one or more program sources cannot be read, or parsing fails
*/
InputProgram readProgramFiles(boolean literate, Map<String, PredicateInterpretation> externals, List<String> paths) throws IOException;
Expand All @@ -46,12 +50,12 @@ public interface Alpha {
InputProgram readProgramFiles(boolean literate, Map<String, PredicateInterpretation> externals, Path... paths) throws IOException;

/**
* Parses a given String into an {@link ASPCore2Program}, using a map of custom {@link PredicateInterpretation}s to resolve external atoms
* Parses a given String into an {@link InputProgram}, using a map of custom {@link PredicateInterpretation}s to resolve external atoms
* in ASP code.
*
* @param aspString a string representing a valid ASP-Core2 program
* @param externals a map of custom {@link PredicateInterpretation}s against which external atoms in the given code are resolved
* @return an {@link ASPCore2Program} representing the parsed ASP code
* @return an {@link InputProgram} representing the parsed ASP code
*/
InputProgram readProgramString(String aspString, Map<String, PredicateInterpretation> externals);

Expand All @@ -61,7 +65,17 @@ public interface Alpha {
InputProgram readProgramString(String aspString);

/**
* Prepares a {@link DebugSolvingContext} for the given {@link ASPCore2Program} to debug program preprocessing.
* Parses an ASP program from an input stream.
*/
InputProgram readProgramStream(InputStream is) throws IOException;

/**
* Parses an ASP program from an input stream.
*/
InputProgram readProgramStream(InputStream is, Map<String, PredicateInterpretation> externals) throws IOException;

/**
* Prepares a {@link DebugSolvingContext} for the given {@link InputProgram} to debug program preprocessing.
*
* @return a {@link DebugSolvingContext} holding debug information for the given program
*/
Expand All @@ -75,7 +89,7 @@ public interface Alpha {
DebugSolvingContext prepareDebugSolve(final NormalProgram program);

/**
* Prepares a {@link DebugSolvingContext} for the given {@link ASPCore2Program} to debug program preprocessing.
* Prepares a {@link DebugSolvingContext} for the given {@link InputProgram} to debug program preprocessing.
*
* @param filter a {@link java.util.function.Predicate} against which {@link Predicate}s of answer sets are tested.
* @return a {@link DebugSolvingContext} holding debug information for the given program
Expand All @@ -91,59 +105,80 @@ public interface Alpha {
DebugSolvingContext prepareDebugSolve(final NormalProgram program, java.util.function.Predicate<Predicate> filter);

/**
* Solves the given {@link ASPCore2Program}.
* Solves the given {@link InputProgram}.
*
* @param program an input program
* @return a {@link Stream} of {@link AnswerSet}s of the given program
*/
Stream<AnswerSet> solve(InputProgram program);

/**
* Solves the given {@link ASPCore2Program}.
* Solves the given {@link InputProgram}.
*
* @param program an input program
* @param filter a {@link java.util.function.Predicate} against which {@link Predicate}s of answer sets are tested.
* @param filter a {@link java.util.function.Predicate} against which {@link Predicate}s of answer sets are tested.
* @return a {@link Stream} of {@link AnswerSet}s of the given program
*/
Stream<AnswerSet> solve(InputProgram program, java.util.function.Predicate<Predicate> filter);

/**
* Solves the given {@link NormalProgram}.
*
* @param program an input program
* @return a {@link Stream} of {@link AnswerSet}s of the given program
*/
Stream<AnswerSet> solve(NormalProgram program);

/**
* Solves the given {@link NormalProgram}.
*
* @param program an input program
* @param filter a {@link java.util.function.Predicate} against which {@link Predicate}s of answer sets are tested.
* @param filter a {@link java.util.function.Predicate} against which {@link Predicate}s of answer sets are tested.
* @return a {@link Stream} of {@link AnswerSet}s of the given program
*/
Stream<AnswerSet> solve(NormalProgram program, java.util.function.Predicate<Predicate> filter);

/**
* Normalizes a program, i.e. rewrites all syntax constructs not natively supported by Alphas back-end into semantically equivalent ASP code.
* Normalizes a program, i.e. rewrites all syntax constructs not natively supported by Alphas back-end into semantically equivalent ASP
* code.
* See {@link NormalProgram},
* @param program An {@link ASPCore2Program} to normalize
*
* @param program An {@link InputProgram} to normalize
* @return a {@link NormalProgram} that is a semantic equivalent to the given input program
*/
NormalProgram normalizeProgram(InputProgram program);

/**
* Constructs a @{link Solver} pre-loaded with the given {@link ASPCore2Program} from which {@link AnswerSet}s can be obtained via {@link Solver#stream()}.
* Constructs a @{link Solver} pre-loaded with the given {@link InputProgram} from which {@link AnswerSet}s can be obtained via
* {@link Solver#stream()}.
*
* @param program the program to solve
* @param filter a {@link java.util.function.Predicate} against which {@link Predicate}s of answer sets are tested.
* @param filter a {@link java.util.function.Predicate} against which {@link Predicate}s of answer sets are tested.
* @return a {@link Solver} pre-loaded withthe given program
*/
Solver prepareSolverFor(InputProgram program, java.util.function.Predicate<Predicate> filter);

/**
* Constructs a @{link Solver} pre-loaded with the given {@link NormalProgram} from which {@link AnswerSet}s can be obtained via {@link Solver#stream()}.
* Constructs a @{link Solver} pre-loaded with the given {@link NormalProgram} from which {@link AnswerSet}s can be obtained via
* {@link Solver#stream()}.
*
* @param program the program to solve
* @param filter a {@link java.util.function.Predicate} against which {@link Predicate}s of answer sets are tested.
* @param filter a {@link java.util.function.Predicate} against which {@link Predicate}s of answer sets are tested.
* @return a {@link Solver} pre-loaded withthe given program
*/
Solver prepareSolverFor(NormalProgram program, java.util.function.Predicate<Predicate> filter);

/**
* Reifies, i.e. re-expresses as a set of ASP facts, the given input program.
*
* @param program an ASP program to reify
* @return a set of {@link BasicAtom}s encoding the given program
*/
Set<BasicAtom> reify(InputProgram program);

/**
* Runs all test cases of the given program.
*/
TestResult test(InputProgram program);

}
23 changes: 18 additions & 5 deletions alpha-api/src/main/java/at/ac/tuwien/kr/alpha/api/AnswerSet.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package at.ac.tuwien.kr.alpha.api;

import java.util.List;
import java.util.SortedSet;

import at.ac.tuwien.kr.alpha.api.programs.Predicate;
import at.ac.tuwien.kr.alpha.api.programs.atoms.Atom;
import at.ac.tuwien.kr.alpha.api.programs.atoms.AtomQuery;

import java.util.List;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;

/**
* API representation of an answer set, i.e. a set of atoms that is a model of an ASP program.
Expand All @@ -29,7 +32,17 @@ public interface AnswerSet extends Comparable<AnswerSet> {
boolean isEmpty();

/**
* List {@link Atom}s in this answer set satisfying the given {@link AnswerSetQuery}.
* List {@link Atom}s in this answer set satisfying the given {@link AtomQuery}.
*/
List<Atom> query(AnswerSetQuery query);
List<Atom> query(AtomQuery query);

default Set<Atom> asFacts() {
return getPredicates().stream()
.map(this::getPredicateInstances)
.reduce(new TreeSet<Atom>(), (left, right) -> {
left.addAll(right);
return left;
});
}

}
Loading
Loading