<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Extending ASPIDE with User-defined Plugins</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Onofrio Febbraro</string-name>
          <email>febbraro@dlvsystem.com</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Nicola Leone</string-name>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Kristian Reale</string-name>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Francesco Ricca</string-name>
          <email>riccag@mat.unical.it</email>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>DLVSystem s.r.l. - P.zza Vermicelli</institution>
          ,
          <addr-line>Polo Tecnologico, 87036 Rende</addr-line>
          ,
          <country country="IT">Italy</country>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Dipartimento di Matematica, Universita` della Calabria</institution>
          ,
          <addr-line>87030 Rende</addr-line>
          ,
          <country country="IT">Italy</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>ASPIDE is the most comprehensive IDE for Answer Set Programming. We describe how to extend ASPIDE with user-defined plugins by means of three examples for: (i) handling the ASP RuleML input format, (ii) performing disjunctive program shifting, and (iii) generating custom XML output.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1 Introduction</title>
      <p>
        Answer Set Programming (ASP) [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] is a declarative programming paradigm which has
been proposed in the area of non-monotonic reasoning and logic programming. A
computational problem is represented in ASP by a logic program (set of rules) whose
answer sets (also called stable models [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ]) correspond to problem’s solutions, which can
be, thus, effectively computed by an ASP solver [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ]. The availability of some efficient
ASP systems made ASP a powerful tool for developing advanced applications, and,
also, the exploitation of ASP in industry has started [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ].
      </p>
      <p>
        As for the most diffused programming languages, the availability of a complete
IDE can simplify significantly both programming and maintenance tasks. In order to
facilitate the design of ASP applications, some tools for ASP-program development
were proposed and the first Integrated Development Environments (IDEs) were
introduced [
        <xref ref-type="bibr" rid="ref4 ref5 ref6">4–6</xref>
        ]. Among them, one of the most comprehensive is ASPIDE [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ]. ASPIDE
includes a cutting-edge editing tool with a collection of user-friendly graphical tools
for program composition, debugging, testing, profiling, DBMS access, solver
execution configuration and output-handling. Nonetheless, we describe in this paper a further
significant extension of ASPIDE devised with the goal of improving the support to
application development: user-defined plugins.
      </p>
      <p>In real-world applications, input data is usually not encoded in ASP, and the
results of a reasoning task specified by an ASP program is expected to be saved in an
application-specific format. In addition, during the development of an ASP program,
the developer might have the need to apply “refactoring”, which often means “rewriting
some rule” (e.g., by applying magic sets, disjunctive rule shifting, etc.), for optimizing
performance, for compliance with solver formats or for modeling purposes. Having this
in mind, we have introduced in ASPIDE the possibility to extend it with user-defined
plugins. Developers can create libraries for extending ASPIDE with: (i) new input
formats, (ii) program rewritings, and even (iii) customizing the format of solver results.</p>
      <p>In the remainder of this paper we present the SDK, composed by Java interfaces and
classes, for extending ASPIDE by describing three examples plugins for: (i) handling
the ASP RuleML input format, (ii) performing disjunctive program shifting, and (iii)
generating custom XML output.
2</p>
    </sec>
    <sec id="sec-2">
      <title>An Input Plugin for ASP RuleML</title>
      <p>
        We design a new input plugin for handling and loading files containing program written
in the ASP RuleML syntax [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ]. The goal is to enrich ASPIDE with tools to open and edit
ASP RuleML programs in two modalities: (i) in the original format, so that an editor,
working as XML editor, shows the content of the file; (ii) in its ASP version, so that an
editor, working as ASP editor, shows the program using the usual ASP syntax. When
this plugin is installed in ASPIDE, a user can identify easily, on the workspace explorer
panel, ASP RuleML files by the corresponding icon specified in the plugin.
Typical input-plugin usage scenario. The user opens one of the available ASP RuleML
files with a simple editor of the plugin and ASPIDE shows the pure content of the file.
When the user switches to the ASP editor of the plugin, the current program is translated
in the ASP version and shown to the user. In this way the user has the possibility to edit
the program in the DLV syntax editor. Finally, the user saves the program and, in this
case, the ASP version of the program is translated again to the ASP RuleML syntax and
stored in the original format of the source file.
      </p>
      <p>Creating the plugin. To define this plugin we develop a new class RuleMLPlugin that
implements the interface InputPlugin (fig. 1). We specify also a new class RuleMLFile
that implements InputStorageHandler and represents our ASP RuleML input file. To
define the editors mentioned on the scenario, we create two classes named
SimpleEditorXML and SimpleEditorASP that extend DefaultEditorView and DLVEditorView (both
implementing the interface EditorView) respectively. In RuleMLPlugin, we implement
the functions getViews, returning the editors, and nextView, returning the next editor to
be loaded when the user switches to the next editor. When the user opens or saves the
content of an editor view, the load and save methods of EditorView are called.
Consequently, we allow the save (load) method of SimpleEditorXML to store (load) the pure
content of the editor and the ones of SimpleEditorASP to store (load) the content of the
editor translated from ASP to ASP RuleML format (and vice-versa); for this last
purpose we create a class RuleMLPlugin that implements RewritingPlugin (fig. 1) with a
rewriting procedure (see next section for rewriting plugin creation).</p>
      <p>Usage in ASPIDE. We now show the usage of the ASP RuleML plugin in ASPIDE.
The user creates a new project that includes an XML file containing the well known
MaximalClique encoding in the ASP RuleML format. The user chooses to open it by
selecting Simple RuleML Editor. ASPIDE shows the editor with the content of the file.
To switch to the ASP editor for showing the program in the DLV format the user clicks
the switch button. ASPIDE opens the Simple ASP Editor showing the translated version
of the program (in ASP). In this editor the user modifies the program by adding facts,
and switches again (after saving) to the ASP RuleML Editor. The editor will show the
modified version of the file that includes also the facts that the user has added.
3</p>
    </sec>
    <sec id="sec-3">
      <title>A Rewriting Plugin for Shifting ASP Rules</title>
      <p>In this section we describe the creation of a rewriting plugin for enriching ASPIDE
with a new functionality that allows one to rewrite disjunctive rules in order to obtain a
“shifted” version, where disjunction is replaced by cyclic non-monotonic negation (this
rewriting produces an equivalent encoding in case of Head-Cycle Free programs). For
example, rule a _ b is rewritten in a : not b and b : not a, the intuition here is that
“disjunction is shifted in the body”.</p>
      <p>Typical rewriting-plugin usage scenario. The user can apply a rewriting procedure to
ASP files or to a part of them by selecting a DLV file on the workspace explorer panel,
and using the shifting function of the rewriting plugin. In this case, the whole file is
analyzed and rewritten in a shifted version. This operation can also be directly used on
a part of the program by selecting interested rules in the DLV editor; in this way only
the selected rules are translated to the shifted version.</p>
      <p>Creating the plugin. We specify a new class ShifterPlugin that implements the interface
RewritingPlugin (fig. 1). The programmer must override three methods used for dealing
with an entire file, with multiple files and with ASP code usually corresponding to some
rules selected in the editor. The results of the rewriting procedure will be stored to a file
or written to the OutputStream parameter.</p>
      <p>Usage in ASPIDE. We now show the usage of the ASP Shifter plugin in ASPIDE.
After its installation, new menu items appear automatically in ASPIDE, allowing one
to use the rewriting functionality on DLV files. A first way of using the ASP Shifter
plugin consists in exploiting the popup menu on a DLV file (in this example
MaximalClique.dl); the user selects the menu item Rewrite As, ASP shifter (fig. 2a). The result of
this action is an automatic creation of a new DLV file (fig. 2b). The ASP Shifter plugin
can be directly used on a DLV editor, in this case selecting a set of rules and using the
command Rewrite, ASP Shifter (fig. 2c); selected code is rewritten and replaced with
the corresponding shifted code (fig. 2d).
4</p>
    </sec>
    <sec id="sec-4">
      <title>An Output Plugin for Formatting Solver Output in XML</title>
      <p>We now describe the creation process of an output plugin for handling the solver output,
generated on the execution process, and writing it in a new format. The output can be
used for many purposes like: (i) redirecting it to some other solver, (ii) translating it to
some other output format to be shown, for example, in the output console or in a new
user-defined window.</p>
      <p>
        Typical output-plugin usage scenario. The user opens the Run Configuration dialog by
adding program files that resolve the Maximal Clique problem. Exploiting the window,
the user chooses to visualize the results using the plugin, so that, after the execution,
the Console Window is open with answer sets formatted to the custom XML format.
Creating the plugin. We start by designing the class CustomXMLOutput that
implements the interface OutputPlugin (fig. 1). This class allows one to: (i) capture the answer
sets of the DLV solver, (ii) rewrite the answer sets in the XML format, (iii) print the
result to the Console Window, (iv) notify ASPIDE that the execution is finished. The DLV
Wrapper library [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ] offers Java classes that represents models and atoms, so we can
exploit it for handling the DLV output by means of Java objects without any need to
create specific parsers. For the writing procedure to the console we create a new class that
implements ConsoleView (fig. 1) and we override the method process(OutputStream)
making it to write the custom XML output to the OutputStream; ASPIDE redirects the
OutputStream to the Console Window on the execution phase. When the execution of
the solver and the rewriting procedure are finished, the method notifyExecutionFinished
to the singleton class AspideEnvironment must be called so that ASPIDE can show the
result window.
      </p>
      <p>Usage in ASPIDE. In ASPIDE the user opens the Run Configuration window by the
Execute menu. After the setting of the solver and the specification of the Maximal Clique
encoding, the user chooses to show the results in the Custom ASP-XML Output format
and click on the Run button. The solver is executed, the output of the solver is passed
to the plugin (activating the rewriting procedure) and the result is shown to the console.
5</p>
    </sec>
    <sec id="sec-5">
      <title>Conclusion and Future Work</title>
      <p>Since its first presentation at LPNMR’11 in Vancouver, ASPIDE has improved in
several respects. In this paper we have described one of the new remarkable additions of
ASPIDE: the support for user-defined plugins. This new feature allows one to write an
entire ASP-based application with minimal (or no) need for external conversion tools.</p>
      <p>The Java interfaces herein described belong to aspidePluginKit.jar, a JAR library
that provides an SDK distributed under the LGPL license and available at the ASPIDE
web site https://www.mat.unical.it/ricca/aspide/.</p>
      <p>Acknowledgments. This work has been partially supported by the Calabrian Region
under PIA (Pacchetti Integrati di Agevolazione industria, artigianato e servizi) project
DLVSYSTEM approved in BURC n. 20 parte III del 15/05/2009 - DR n. 7373 del
06/05/2009.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <surname>Gelfond</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Lifschitz</surname>
            ,
            <given-names>V.</given-names>
          </string-name>
          :
          <article-title>Classical Negation in Logic Programs</article-title>
          and
          <source>Disjunctive Databases. NGC 9</source>
          (
          <year>1991</year>
          )
          <fpage>365</fpage>
          -
          <lpage>385</lpage>
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <surname>Lifschitz</surname>
          </string-name>
          , V.:
          <article-title>Answer Set Planning</article-title>
          . In: ICLP'
          <volume>99</volume>
          )
          <fpage>23</fpage>
          -
          <lpage>37</lpage>
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <surname>Grasso</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Leone</surname>
            ,
            <given-names>N.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Manna</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Ricca</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          : ASP at Work:
          <article-title>Spin-off and Applications of the DLV System Logic Programming, Knowledge Representation, and Nonmonotonic Reasoning: Essays in Honor of M. Gelfond</article-title>
          . LNCS
          <volume>6565</volume>
          (
          <year>2011</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <surname>Sureshkumar</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Vos</surname>
            ,
            <given-names>M.D.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Brain</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Fitch</surname>
            ,
            <given-names>J.: APE</given-names>
          </string-name>
          :
          <article-title>An AnsProlog* Environment</article-title>
          . In: SEA 07
          <fpage>101</fpage>
          -
          <lpage>115</lpage>
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <surname>Oetsch</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          , Pu¨hrer, J.,
          <string-name>
            <surname>Tompits</surname>
          </string-name>
          , H.:
          <article-title>The sealion has landed: An ide for answer-set programming-preliminary report</article-title>
          .
          <source>In: INAP2011/WLP2011</source>
          . Volume abs/1109.3989. (
          <year>2011</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <surname>Febbraro</surname>
            ,
            <given-names>O.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Reale</surname>
            ,
            <given-names>K.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Ricca</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          :
          <article-title>ASPIDE: Integrated Development Environment for Answer Set Programming</article-title>
          .
          <source>In: LPNMR 2011. LNCS 6645</source>
          , (
          <year>2011</year>
          )
          <fpage>317</fpage>
          -
          <lpage>330</lpage>
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <surname>Eiter</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Ianni</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Schindlauer</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Tompits</surname>
          </string-name>
          , H.: H.:
          <article-title>A ruleml syntax for answer-set programming</article-title>
          .
          <source>In: Informal Proceedings of the Workshop on Applications of Logic Programming in the Semantic Web and Semantic Web Services (ALPSWS06)</source>
          . (
          <year>2006</year>
          )
          <fpage>107108</fpage>
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <surname>Ricca</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          :
          <article-title>The DLV Java Wrapper</article-title>
          . In: ASP'
          <fpage>03</fpage>
          ,
          <string-name>
            <surname>Messina</surname>
          </string-name>
          , Italy (
          <year>2003</year>
          )
          <fpage>305</fpage>
          -
          <lpage>316</lpage>
          Online at http://CEUR-WS.org/Vol-
          <volume>78</volume>
          /.
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>