JASP: a Framework for Integrating Answer Set Programming with Java Onofrio Febbraro Giovanni Grasso Dlvsystem S.R.L
Total Page:16
File Type:pdf, Size:1020Kb
Proceedings of the Thirteenth International Conference on Principles of Knowledge Representation and Reasoning JASP: A Framework for Integrating Answer Set Programming with Java Onofrio Febbraro Giovanni Grasso DLVSystem s.r.l. Oxford University, Department of Computer Science P.zza Vermicelli, Polo Tecnologico, Parks Road, Oxford, UK Rende, Italy Nicola Leone and Francesco Ricca University of Calabria, Department of Mathematics Rende, Italy Abstract Among the others, ASP has been applied in the areas of Arti- Answer Set Programming (ASP) is a fully-declarative logic ficial Intelligence (Gebser et al. 2007b; Denecker et al. 2009; programming paradigm, which has been proposed in the area Calimeri et al. 2011b; Balduccini et al. 2001; Baral and Gel- of knowledge representation and non-monotonic reasoning. fond 2000; Baral and Uyan 2001; Friedrich and Ivanchenko Nowadays, the formal properties of ASP are well-understood, 2008; Franconi et al. 2001; Nogueira et al. 2001; Brewka efficient ASP systems are available, and, recently, ASP has et al. 2006), Information Integration (Leone et al. 2005; been employed in a few industrial applications. However, Bertossi, Hunter, and Schaub 2005), and Knowledge Man- ASP technology is not mature for a successful exploitation agement (Baral 2003; Bardadym 1996; Grasso et al. 2009; in industry yet; mainly because ASP technologies are not in- 2011). Recently, we have employed ASP for developing tegrated in the well-assessed development processes and plat- some industrial application; in particular, we have used ASP forms which are tailored for imperative/object-oriented pro- for building systems for workforce management (Ricca et gramming languages. In this paper we present a new pro- gramming framework blending ASP with Java. The frame- al. 2011b) and e-tourism (Ricca et al. 2010a). work is based on JASP, an hybrid language that trans- The experience we have gained in developing real-world parently supports a bilateral interaction between ASP and ASP-based applications, on the one hand has confirmed the Java. JASP specifications are compliant with the JPA stan- viability of the industrial exploitation of ASP; but, on the dard to perfectly fit extensively-adopted enterprise applica- other hand, it has brought into light some practical obsta- tion technologies. The framework also encompasses an im- cles to the development of ASP-based software. The dif- plementation of JASP as a plug-in for the Eclipse platform, ficulties we faced within practice, have inspired the solu- called JDLV, which includes a compiler from JASP to Java. tions provided by the development-framework we present in Moreover, we show a real-world application developed with JASP and JDLV, which highlights the effectiveness of our this paper, which is based on our on-the-field experience. ASP–Java integration framework. We have observed that there is a strong need of integrat- ing ASP technologies (i.e., ASP programs and solvers) in the well-assessed software-development processes and plat- 1 Introduction forms, which are tailored for imperative/object-oriented pro- Answer Set Programming (ASP) (Lifschitz 1999) is a fully- gramming languages. Indeed, the lesson we have learned declarative logic programming paradigm, which has been while building real-world ASP-based applications, confirms proposed in the area of non-monotonic reasoning and logic that complex business-logic features can be developed in programming. The idea of ASP is to represent a given com- ASP at a lower (implementation) price than in traditional putational problem by a logic program whose answer sets imperative languages, and the employment of ASP brings correspond to solutions, and use a solver to find them (Lifs- many advantages from a Software Engineering viewpoint, chitz 1999). in flexibility, readability, extensibility, ease of maintenance, After many years of research, the formal properties of etc. However, since ASP is not a full general-purpose lan- ASP are well-understood; notably, ASP is expressive: it guage, ASP programs must be embedded, at some point, can solve problems of complexity beyond NP (Eiter, Gott- in systems components that are usually built by employing lob, and Mannila 1997). Moreover, the availability of robust imperative/object-oriented programming languages, e.g., for and efficient solvers (Leone et al. 2006; Simons, Niemelä, developing visual user-interfaces. and Soininen 2002; Lin and Zhao 2002; Babovich and A first step toward the solution of this problem was Maratea 2003; Gebser et al. 2007a; Janhunen et al. 2006; the development of an Application Programming Interface Lierler 2005; Drescher et al. 2008; Gebser et al. 2007b; (API) (Ricca 2003; Gallucci and Ricca 2007), which offers Denecker et al. 2009; Calimeri et al. 2011b) made ASP an some methods for interacting with an ASP solver from an effective powerful tool for advanced applications, and stim- embedding Java program. In that work, however, the bur- ulated the development of many interesting applications. den of the integration between ASP and Java is still in the Copyright c 2012, Association for the Advancement of Artificial hands of the programmer, who must take care of the (of- Intelligence (www.aaai.org). All rights reserved. ten repetitive and) time-consuming development of ad-hoc 541 procedures that both control the execution of an external integration platform. solver and convert the application-data back and forth from In short, the contribution of the paper is the following. logic-based to object-oriented (Java) representations. Note • We propose JASP, a language blending ASP with Java. that, programming tools and workbenches basically offer no - We formally define the syntax (in EBNF) and the specific support for this development task and, developers rewriting-based semantics of the JASP-core, along with are hindered from adopting a poorly-supported non stan- the Object-Relational Mapping, which is transparently dard technology. Another issue, which is particularly rele- applied in JASP-core for the bilateral data-exchange Java- vant in the case of enterprise applications (Fowler 2002), is ASP and vice versa. the need of manipulating large databases, which store enter- - We specify the advanced features of the JASP lan- prise information or are often used to make persistent com- guage, including the dynamic composition of JASP plex object-oriented domain models. modules, the access to databases, the JPA-compliant (Or- This paper provides some contribution in this setting, acle 2009) mechanism for defining advanced mappings to deal with the above mentioned issues. In particular, we between Java objects and ASP facts. present a new programming framework integrating ASP • We design and develop JDLV – an implementation of with Java. The framework is based on an hybrid language, JASP integrating Java with the ASP system DLV (Leone et called JASP, that transparently supports a bilateral inter- al. 2006), that we have incorporated as a plugin in the popu- action between ASP and Java. The programmer can simply lar Eclipse platform. (Notaby, any other ASP system can be embed ASP code in a Java program without caring about easily supported.) the interaction with the underlying ASP system. The log- - We specify the advanced features of JDLV. ical ASP program can access Java variables, and the an- - We discuss the main issues underlying the JDLV swer sets, resulting from the execution of the ASP code, implementation, particularly focusing on Jdlvc, a com- are automatically stored in Java objects, possibly popu- piler from JASP to Java code embedding calls to DLV, lating Java collections, transparently. A key ingredient of which constitutes a key component of JDLV. JASP is the mapping between (collections of) Java objects • We present a real-world application developed with and ASP facts. JASP shares with Object-Relational Map- JASP and JDLV, confirming the usefulness of our frame- ping (ORM) frameworks, such as Hibernate and TopLink, work. the structural issues of the impedance mismatch (Maier The remainder of this paper is organized as follows: After 1990; Keller, Jensen, and Agrawal 1993) problem. Indeed, a brief ASP introduction, we present, in turn, the JASP lan- the data model underlying ASP systems is the relational guage and the JDLVsystem. We then discuss related works, model (Codd 1970) as for RDBMSs. Thus, Java Objects and we finally draw the conclusion after showing an appli- are mapped to logic facts (and vice versa) by adopting a cation of our framework. structural mapping strategy similar to the one employed by ORM tools for retrieving/saving persistent objects from/to relational databases. JASP supports both a default map- 2 Answer Set Programming ping strategy, which fits the most common programmers’ Answer Set Programming (ASP) (Lifschitz 1999) is a truly- requirements, and custom ORM strategies that can be spec- declarative programming paradigm proposed in the area of ified by the programmer for advanced needs. Importantly, non-monotonic reasoning and logic programming. We re- custom ORM specifications in JASP comply with the Java frain from reporting in this paper a formal description of Persistence API (JPA) (Oracle 2009), to perfectly suit enter- both syntax and semantics of ASP, rather we provide an in- prise application development standards. Moreover, JASP tuitive account of ASP as a tool for knowledge represen- supports direct access to data stored in a DBMS, since ORM tation and reasoning by exploiting some examples. We as- strategies can be shared with the persistent object manage- sume the reader familiar with logic programming conven- ment layer, the new language also supports efficient ASP- tions, and refer to (Gelfond and Lifschitz 1991; Gelfond and based reasoning on large repositories of persistent objects. Leone 2002; Leone et al. 2006) for a formal description, and The framework also encompasses an implementation of to (Baral 2003) and (Gelfond and Leone 2002) for comple- JASP as a plug-in for the Eclipse platform (Eclipse 2001), mentary introductory material on ASP. called JDLV. JDLV provides an advanced platform for inte- In ASP, a rule is of the form Head :- Body., where grating Java with DLV (Leone et al.