|
| 1 | +package at.ac.tuwien.kr.alpha.api; |
| 2 | + |
| 3 | +import java.io.IOException; |
| 4 | +import java.nio.file.Path; |
| 5 | +import java.util.List; |
| 6 | +import java.util.Map; |
| 7 | +import java.util.stream.Stream; |
| 8 | + |
| 9 | +import at.ac.tuwien.kr.alpha.api.common.fixedinterpretations.PredicateInterpretation; |
| 10 | +import at.ac.tuwien.kr.alpha.api.config.InputConfig; |
| 11 | +import at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program; |
| 12 | +import at.ac.tuwien.kr.alpha.api.programs.NormalProgram; |
| 13 | +import at.ac.tuwien.kr.alpha.api.programs.Predicate; |
| 14 | + |
| 15 | +/** |
| 16 | + * Main API entry point for the Alpha ASP system. Provides facilities for parsing, normalizing and solving ASP programs. |
| 17 | + * |
| 18 | + * Copyright (c) 2021, the Alpha Team. |
| 19 | + */ |
| 20 | +public interface Alpha { |
| 21 | + |
| 22 | + /** |
| 23 | + * Reads an ASP program using the configuration and sources specified in a given {@link InputConfig}. |
| 24 | + * |
| 25 | + * @param cfg and {@link InputConfig} specifying program sources (strings, files) as well as config metadata (e.g. literate program, |
| 26 | + * external atoms, etc) |
| 27 | + * @return an {@link ASPCore2Program} representing the parsed ASP code from all sources referenced in the given {@link InputConfig} |
| 28 | + * @throws IOException in case one or more program sources (e.g. files) cannot be read, or parsing fails |
| 29 | + */ |
| 30 | + ASPCore2Program readProgram(InputConfig cfg) throws IOException; |
| 31 | + |
| 32 | + /** |
| 33 | + * Reads and parses an {@link ASPCore2Program} from a list of {@link String}s representing paths. |
| 34 | + * |
| 35 | + * @param literate flag indicating whether ASP code should be treated as "literate". |
| 36 | + * @param externals Custom {@link PredicateInterpretation}s for user-defined external atoms |
| 37 | + * @param paths a list of {@link String}s representing paths containing all sources from which ASP code should be read |
| 38 | + * @return an {@link ASPCore2Program} representing the parsed ASP code from all given path strings |
| 39 | + * @throws IOException in case one or more program sources cannot be read, or parsing fails |
| 40 | + */ |
| 41 | + ASPCore2Program readProgramFiles(boolean literate, Map<String, PredicateInterpretation> externals, List<String> paths) throws IOException; |
| 42 | + |
| 43 | + /** |
| 44 | + * see {@link Alpha#readProgramFiles(boolean, Map, List)} |
| 45 | + */ |
| 46 | + ASPCore2Program readProgramFiles(boolean literate, Map<String, PredicateInterpretation> externals, Path... paths) throws IOException; |
| 47 | + |
| 48 | + /** |
| 49 | + * Parses a given String into an {@link ASPCore2Program}, using a map of custom {@link PredicateInterpretation}s to resolve external atoms |
| 50 | + * in ASP code. |
| 51 | + * |
| 52 | + * @param aspString a string representing a valid ASP-Core2 program |
| 53 | + * @param externals a map of custom {@link PredicateInterpretation}s against which external atoms in the given code are resolved |
| 54 | + * @return an {@link ASPCore2Program} representing the parsed ASP code |
| 55 | + */ |
| 56 | + ASPCore2Program readProgramString(String aspString, Map<String, PredicateInterpretation> externals); |
| 57 | + |
| 58 | + /** |
| 59 | + * Convenience method to parse ASP strings not containing any user-defined external atoms, see {@link Alpha#readProgramString(String, Map)}. |
| 60 | + */ |
| 61 | + ASPCore2Program readProgramString(String aspString); |
| 62 | + |
| 63 | + /** |
| 64 | + * Prepares a {@link DebugSolvingContext} for the given {@link ASPCore2Program} to debug program preprocessing. |
| 65 | + * |
| 66 | + * @return a {@link DebugSolvingContext} holding debug information for the given program |
| 67 | + */ |
| 68 | + DebugSolvingContext prepareDebugSolve(final ASPCore2Program program); |
| 69 | + |
| 70 | + /** |
| 71 | + * Prepares a {@link DebugSolvingContext} for the given {@link NormalProgram} to debug program preprocessing. |
| 72 | + * |
| 73 | + * @return a {@link DebugSolvingContext} holding debug information for the given program |
| 74 | + */ |
| 75 | + DebugSolvingContext prepareDebugSolve(final NormalProgram program); |
| 76 | + |
| 77 | + /** |
| 78 | + * Prepares a {@link DebugSolvingContext} for the given {@link ASPCore2Program} to debug program preprocessing. |
| 79 | + * |
| 80 | + * @param filter a {@link java.util.function.Predicate} against which {@link Predicate}s of answer sets are tested. |
| 81 | + * @return a {@link DebugSolvingContext} holding debug information for the given program |
| 82 | + */ |
| 83 | + DebugSolvingContext prepareDebugSolve(final ASPCore2Program program, java.util.function.Predicate<Predicate> filter); |
| 84 | + |
| 85 | + /** |
| 86 | + * Prepares a {@link DebugSolvingContext} for the given {@link NormalProgram} to debug program preprocessing. |
| 87 | + * |
| 88 | + * @param filter a {@link java.util.function.Predicate} against which {@link Predicate}s of answer sets are tested. |
| 89 | + * @return a {@link DebugSolvingContext} holding debug information for the given program |
| 90 | + */ |
| 91 | + DebugSolvingContext prepareDebugSolve(final NormalProgram program, java.util.function.Predicate<Predicate> filter); |
| 92 | + |
| 93 | + /** |
| 94 | + * Solves the given {@link ASPCore2Program}. |
| 95 | + * @param program an input program |
| 96 | + * @return a {@link Stream} of {@link AnswerSet}s of the given program |
| 97 | + */ |
| 98 | + Stream<AnswerSet> solve(ASPCore2Program program); |
| 99 | + |
| 100 | + /** |
| 101 | + * Solves the given {@link ASPCore2Program}. |
| 102 | + * @param program an input program |
| 103 | + * @param filter a {@link java.util.function.Predicate} against which {@link Predicate}s of answer sets are tested. |
| 104 | + * @return a {@link Stream} of {@link AnswerSet}s of the given program |
| 105 | + */ |
| 106 | + Stream<AnswerSet> solve(ASPCore2Program program, java.util.function.Predicate<Predicate> filter); |
| 107 | + |
| 108 | + /** |
| 109 | + * Solves the given {@link NormalProgram}. |
| 110 | + * @param program an input program |
| 111 | + * @return a {@link Stream} of {@link AnswerSet}s of the given program |
| 112 | + */ |
| 113 | + Stream<AnswerSet> solve(NormalProgram program); |
| 114 | + |
| 115 | + /** |
| 116 | + * Solves the given {@link NormalProgram}. |
| 117 | + * @param program an input program |
| 118 | + * @param filter a {@link java.util.function.Predicate} against which {@link Predicate}s of answer sets are tested. |
| 119 | + * @return a {@link Stream} of {@link AnswerSet}s of the given program |
| 120 | + */ |
| 121 | + Stream<AnswerSet> solve(NormalProgram program, java.util.function.Predicate<Predicate> filter); |
| 122 | + |
| 123 | + /** |
| 124 | + * Normalizes a program, i.e. rewrites all syntax constructs not natively supported by Alphas back-end into semantically equivalent ASP code. |
| 125 | + * See {@link NormalProgram}, |
| 126 | + * @param program An {@link ASPCore2Program} to normalize |
| 127 | + * @return a {@link NormalProgram} that is a semantic equivalent to the given input program |
| 128 | + */ |
| 129 | + NormalProgram normalizeProgram(ASPCore2Program program); |
| 130 | + |
| 131 | + /** |
| 132 | + * Constructs a @{link Solver} pre-loaded with the given {@link ASPCore2Program} from which {@link AnswerSet}s can be obtained via {@link Solver#stream()}. |
| 133 | + * |
| 134 | + * @param program the program to solve |
| 135 | + * @param filter a {@link java.util.function.Predicate} against which {@link Predicate}s of answer sets are tested. |
| 136 | + * @return a {@link Solver} pre-loaded withthe given program |
| 137 | + */ |
| 138 | + Solver prepareSolverFor(ASPCore2Program program, java.util.function.Predicate<Predicate> filter); |
| 139 | + |
| 140 | + /** |
| 141 | + * Constructs a @{link Solver} pre-loaded with the given {@link NormalProgram} from which {@link AnswerSet}s can be obtained via {@link Solver#stream()}. |
| 142 | + * |
| 143 | + * @param program the program to solve |
| 144 | + * @param filter a {@link java.util.function.Predicate} against which {@link Predicate}s of answer sets are tested. |
| 145 | + * @return a {@link Solver} pre-loaded withthe given program |
| 146 | + */ |
| 147 | + Solver prepareSolverFor(NormalProgram program, java.util.function.Predicate<Predicate> filter); |
| 148 | + |
| 149 | +} |
0 commit comments