ASP Plugin - aantakli/AJAN-service GitHub Wiki

The AJAN Extension described in this section (https://github.com/aantakli/AJAN-service/tree/master/pluginsystem/plugins/ASPPlugin) was developed as part of the REACT project funded by the German Federal Ministry of Education and Research (BMBF) and the AIToC project funded by the EU. This plugin extends the AJAN agent and behavior model with Answer Set Programming (ASP). Accordingly, RDF-based agent knowledge and rules can be translated into an ASP-based problem and then solved for AJAN reasoning via an integrated ASP solver. In the following, we will briefly discuss the functionality of this plugin and then present the configuration of the plugin and its RDF representation.

ASP Plugin Integration Overview

The figure above shows how ASP Solving is integrated into AJAN. The solving itself involves three steps: 1) Defining and selecting and translating RDF data into ASP rules. These are passed in 2) to the integrated ASP solver, which finds 0 to n possible stable models. In 3) these stable models are translated back into RDF named graphs, one named graph per stable model, and then stored in a selected repository.

RDF -> ASP Translation Overview

When translating from RDF to ASP and vice versa, we refer to the previous figure. Basically, RDF triples are translated into ASP facts with three literals. Such a translated ASP triple has the predicate _t, whereas RDF literals are marked with ASP predicate _l and RDF blank nodes with _b. URIs, floats and other RDF literals that have special characters are converted to ASP strings in this translation, whereas integers remain as integers.

Result Handling Overview

The previous graphic demonstrates how two Stable models are each translated into RDF Named Graphs and how these models are accessed with a SPARQL CONSTRUCT query. The blue frame on the left shows a single stable model. The green and red frames, on the other hand, indicate different facts. On the right side again a SPARQL query is shown, which queries the resulting RDF based Stable Models. The colored boxes refer to the ASP results on the left side.


Leaf Nodes

SPARQL-BT ASP Problem node

Implementation: https://github.com/aantakli/AJAN-service/blob/master/pluginsystem/plugins/ASPPlugin/src/main/java/de/dfki/asr/ajan/pluginsystem/aspplugin/extensions/Problem.java

States: SUCCEEDED || FAILED

Description: A SBT Problem node is a BT leaf node, that can be used to define an ASP problem and solve it using an ASP solver. For this purpose, in addition to the definition for solving itself, via asp:config, the domain knowledge or the agent knowledge to be used must be defined via asp:domain. These RDF statements are translated into ASP and are available to the solver for problem solving. For additional ASP rules to be included, asp:ruleSets can be used, which references various predefined ASP rules (native or in RDF). On the other hand, asp:write is used to specify how the result of the solver should be stored. If stable models are found by the ASP solver or its result is Satisfiable, this node returns SUCCEEDED, otherwise FAILED (solver outputs: Error or Unsatisfiable; or problems while reading and saving RDF data).

Properties

Property (RDF) Value (RDF)
Namespace (@prefix asp:) URL (http://www.ajan.de/behavior/asp-ns#)
Namespace (@prefix clingo:) URL (http://www.ajan.de/behavior/clingo-ns#)
Type (rdf:type) Problem Node (asp:Problem)
Class (rdfs:subClassOf) Leaf Node (bt:Leaf)
Label (rdfs:label) <string> ("some label"^^xsd:string)
Solver Configuration (asp:config) Clingo Configuration Definition (e.g. clingo:Config)
Domain Information (asp:domain) CONSTRUCT Query (bt:ConstructQuery)
Rule Sets (asp:ruleSets) Rule Set Location Definition (asp:RuleSetLocation)
Result Configuration (asp:write) ASP Write Definition (asp:Write)

Example in [Turtle/RDF] (comments start with: #)

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix asp: <http://www.ajan.de/behavior/asp-ns#> .

[ 
   a asp:Problem ;
   rdfs:label "Some ASP Problem" ;
   asp:config :SomeConfig ;
   asp:domain [ a bt:ConstructQuery ; # ... ] ;
   asp:ruleSets ( :SomeRuleSetLocation ) ;
   asp:write :SomeWriteInfo .
]

ASP Plugin Object Definitions

ASP Configuration

Implementation: https://github.com/aantakli/AJAN-service/blob/master/pluginsystem/plugins/ASPPlugin/src/main/java/de/dfki/asr/ajan/pluginsystem/aspplugin/extensions/ClingoConfig.java

Description: The configuration object asp:Config is used to configure the used ASP solver. In the following example this configuration applies to to the used Potassco Clingo solver. With clingo:time-limit the maximum solving time in seconds can be specified. clingo:execution-limit specifies how many times the solver should be executed to get a result. clingo:models specifies the maximum number of models to be output. clingo:parallel-mode specifies on how many threads the solution should be found. This can massively influence the execution time. Finally, clingo:const refers to a clingo:Const definition with which ASP constants can be specified.

Properties

Property (RDF) Value (RDF)
Namespace (@prefix clingo:) URL (http://www.ajan.de/behavior/clingo-ns#)
Type (rdf:type) Clingo Config (clingo:Config)
Time Limit (clingo:time-limit) <INT> ("10"^^xsd:int)
Execution Limit (clingo:execution-limit) <INT> ("1"^^xsd:int)
Models (clingo:models) <INT> ("3"^^xsd:int)
Parallel Mode (clingo:parallel-mode) <INT> ("2"^^xsd:int)
Constant (clingo:const) Constant (clingo:Constant)

Example in [Turtle/RDF] (comments strat with: #)

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix clingo: <http://www.ajan.de/behavior/clingo-ns#> .

:SomeConfig
   a clingo:Config ;
   clingo:time-limit "10"^^xsd:int ;
   clingo:execution-limit "1"^^xsd:int ;
   clingo:models "3"^^xsd:int ;
   clingo:parallel-mode "2"^^xsd:int ;
   clingo:const (
      [ a clingo:Constant ;
        clingo:name "steps" ;
        clingo:value "4"^^xsd:string ;
      ]
   ) .

ASP Domain Information

Implementation: https://github.com/aantakli/AJAN-service/blob/master/behaviour/src/main/java/de/dfki/asr/ajan/behaviour/nodes/query/BehaviorConstructQuery.java

Description: The property asp:domain is used to reference an SBT CONSTRUCT query (bt:ConstructQuery), which is used to read the desired RDF statements from a defined repository and translate them into ASP facts. This domain information is passed to the solver together with the rule sets described below to determine possible stable models.

Properties

Property (RDF) Value (RDF)
Namespace (@prefix asp:) URL (http://www.ajan.de/behavior/asp-ns#)
Object Pointer (asp:domain) SBT CONSTRUCT query (bt:ConstructQuery)

Example in [Turtle/RDF] (comments start with: #)

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix bt: <http://www.ajan.de/behavior/bt-ns#> .
@prefix asp: <http://www.ajan.de/behavior/asp-ns#> .

asp:domain [ a bt:ConstructQuery ; # ... ] ;

ASP Rule Set Location

Implementation: https://github.com/aantakli/AJAN-service/blob/master/pluginsystem/plugins/ASPPlugin/src/main/java/de/dfki/asr/ajan/pluginsystem/aspplugin/extensions/RuleSetLocation.java

https://github.com/aantakli/AJAN-service/blob/master/pluginsystem/plugins/ASPPlugin/src/main/java/de/dfki/asr/ajan/pluginsystem/aspplugin/extensions/ASPRules.java

Description: This configuration object is used to specify the location of a rule set. The URI of the desired rule set must be specified with asp:ruleSet and its location with bt:OriginBase. A single Rule Set is of type asp:RuleSet and holds native ASP rules via asp:asRules.

Properties

Property (RDF) Value (RDF)
Namespace (@prefix asp:) URL (http://www.ajan.de/behavior/asp-ns#)
Type (rdf:type) Rule Set Location (asp:RuleSetLocation)
Rule Set (asp:ruleSet) Rule Set (asp:RuleSet)
Origin Base (bt:originBase) <URI> ("some URI"^^xsd:anyURI)

Example in [Turtle/RDF] (comments start with: #)

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix bt: <http://www.ajan.de/behavior/bt-ns#> .
@prefix asp: <http://www.ajan.de/behavior/asp-ns#> .

:SomeRuleSetLocation 
   a asp:RuleSetLocation ;
   asp:ruleSet <http://localhost:8090/rdf4j/repositories/domain#Plugin_Planning_LP> ;
   bt:originBase ajan:DomainKnowledge .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix asp: <http://www.ajan.de/behavior/asp-ns#> .

:Plugin_Planning_LP
   a asp:RuleSet ;
   asp:asRules """
      % -----------------------------------
      % Plug-in Rules
      % -----------------------------------

      plugin_connection_start(CONN,END + 1) :- plugin_connection(CONN), END = 0 .
      plugin_connection_end(CONN,END) :- plugin_position_end(CONN,END) .
   """^^xsd:string .

ASP Write

Implementation: https://github.com/aantakli/AJAN-service/blob/master/pluginsystem/plugins/ASPPlugin/src/main/java/de/dfki/asr/ajan/pluginsystem/aspplugin/extensions/ASPWrite.java

Description: This configuration object defines where and how the result of the used solver should be stored in the agent knowledge base. For example, asp:saveString can be used to specify whether the result should be saved as a string in addition to an RDF-based representation. With asp:contextBase you have to specify under which URIs the respective stable models (in form of a named graph) are stored. With asp:random you can specify whether only one stable model should be selected and stored randomly. Finally, the storage location must be specified with bt:targetBase.

Properties

Property (RDF) Value (RDF)
Namespace (@prefix asp:) URL (http://www.ajan.de/behavior/asp-ns#)
Type (rdf:type) Problem Node (asp:Write)
Save as String (asp:saveString) <boolean> ("true/false"^^xsd:boolean)
Result Graph Name (asp:contextBase) <URI> ("some URI"^^xsd:anyURI)
Save Random Result (asp:random) <boolean> ("true/false"^^xsd:boolean)
Target Base (bt:targetBase) <URI> ("some URI"^^xsd:anyURI)

Example in [Turtle/RDF] (comments start with: #)

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix bt: <http://www.ajan.de/behavior/bt-ns#> .
@prefix asp: <http://www.ajan.de/behavior/asp-ns#> .

:SomeWriteInfo
   a asp:Write ;
   asp:saveString "true"^^xsd:boolean ;
   asp:random "false"^^xsd:boolean ;
   asp:contextBase "http://www.ajan.de/asp/MoveToASP/stableModel/"^^xsd:anyURI ;
   bt:targetBase ajan:AgentKnowledge .
⚠️ **GitHub.com Fallback** ⚠️