Introduction
Answer Set Programming (ASP) has emerged as a powerful declarative paradigm for solving complex combinatorial search and optimization problems. From industrial scheduling to configuration management, ASP's ability to handle NP-hard problems is well-documented. However, its adoption is often hindered by a steep learning curve. The syntax, rooted deeply in mathematical logic, can be intimidating for domain experts who lack a computer science background. Furthermore, even for seasoned developers, large-scale ASP programs can become difficult to maintain and document.
To address these challenges, this paper introduces cnl2asp, an open-source tool designed to bridge the gap between human-readable specifications and formal logic. By translating sentences written in a "Controlled Natural Language" (CNL) directly into ASP rules, the tool makes logic programming more accessible and self-documenting.
The cnl2asp Framework
The core of cnl2asp is a specialized grammar inspired by the Semantics of Business Vocabulary and Business Rules (SBVR) standard. This grammar allows users to describe complex logic using plain English structures that the tool can unambiguously parse into ASP.
The translation process relies on five primary types of propositions:
- Definition Propositions: These establish the basic concepts and their ranges (e.g., "A node goes from 1 to 3").
- Quantified Choice Propositions: These define the search space by specifying possibilities (e.g., "Every patron can drink in exactly 1 pub").
- Strong Constraints: These define hard rules that must be satisfied, typically starting with "It is prohibited that" or "It is required that."
- Weak Constraints: These express preferences for optimization, allowing users to specify "low," "medium," or "high" priority levels.
- Conditional Definitions: These allow for logic that only applies under specific circumstances using "when" clauses.
The tool's sophistication lies in its ability to handle advanced ASP features such as aggregates (counting or summing), arithmetic operations, and complex sequence relationships. For instance, expressing that an event must happen "before" or "after" another in a sequence is handled automatically by the tool's underlying index management.
Key Insights and Technical Contributions
One of the most significant advantages of cnl2asp is the creation of self-documenting code. Because the CNL sentences map directly to generated ASP rules, the English specification serves as both the source code and its own documentation. This transparency is invaluable for auditing and maintaining complex logic.
Furthermore, the tool manages implicit variables to maintain the natural feel of the English input. When a user does not explicitly name a variable, the tool generates internal identifiers (e.g., _X1, _X2), preventing the "variable clutter" often found in traditional logic programming.
For experts, cnl2asp serves as a rapid prototyping tool. It allows developers to "sketch" an encoding in English to verify the logic before manually optimizing the resulting ASP code for performance.
Evaluation and Results
The expressiveness of cnl2asp was evaluated using classic combinatorial benchmark problems, including Graph Coloring, Hamiltonian Path, and Maximal Clique. The results demonstrated that even NP-hard problems can be fully expressed in a handful of clear English sentences. For example, the entire logic for a Graph Coloring problem—defining nodes, colors, and the constraint that adjacent nodes must differ in color—was successfully encoded in just seven CNL sentences.
The generated code is standard ASP, compatible with modern solvers like clingo. By releasing the tool as open-source, the authors provide a much-needed public resource in a field where previous tools were often proprietary or restricted to academic prototypes.
Future Directions
While cnl2asp is a significant step forward, several areas for improvement remain:
- Anaphora Resolution: Currently, the tool requires explicit variable references (e.g., "waiter X") rather than ambiguous pronouns like "it" or "they."
- Temporal Logic: Future versions aim to support operators like "always" or "eventually" for planning tasks.
- Bidirectionality: The authors plan to implement "reverse translation" to turn existing ASP rules back into English, aiding in the understanding of legacy code.
- Constraint ASP (CASP): Expanding support to CASP would allow the tool to handle large numeric domains more efficiently.
The implementation is available for the community at https://github.com/dodaro/cnl2asp.
Summary updated