Description |
This software package implements a full RuleML compiler
for an extension of the hornlog frament of
RuleML. The W4 RuleML compiler
supports default and explicit negation both in the heads and in the
bodies of rules, as well as assert statements of EVOLP programs. The
semantics implemented is Paraconsistent Well-founded Semantics with
Explicit Negation. Furthermore, the W4 RuleML
compiler supports several rulebases, imported from RuleML files our
Prolog files. A converter from Prolog syntax to RuleML syntax and from
RuleML syntax to Prolog syntax are available.
By exploring the NMR features of the new
XSB Prolog 2.6, it will be soon
provided support for Stable Models and Answer Set Semantics. The
package was originally developed for XSB Prolog
2.5, but porting
to other Prolog systems
is foreseen.
DISCLAIMER: This
is still a beta version of the RuleML compiler and should be used solely
for research/illustration purposes. Use it at your own risk...
|
Download and
Installation
The
W4 RuleML compiler
distribution contains the following XSB Prolog source
files:
- The file containing the main predicates (ruleml.P)
- The support predicates for
asserting, retracting and updating Rule Bases (rulebase.P)
- The predicates for reading (rulemlread.P) and
writing (rulemlwrite.P) RuleML files for the urhornlog fragment.
- The predicates for reading (prologread.P) and
writing (prologwrite.P) Prolog files.
- The GWFSXp meta-interpreter (gwfsxpengine.P)
- Several utility predicates (utilities.P)
Plus the the
W4 XML Parser, which can be used
for parsing arbitrary XML documents.
- The file containing the main
XML parser
predicates (xml.P)
- The XML parser (xmlparser.H
and xmlparser.P),
automaticaly produced by our Parser Generator,
with lookahead information.
- The Document Object Model (xmldom.H
and xmldom.P)
with the predicates for constructing the Prolog representation
of XML documents.
- A translator to the compact representation of XML
in Prolog (xml2termns.P), with Namespace support.
- The I/O stream support predicates (iostream.P
and utf.P).
- Several utility predicates (utilities.P)
- Support of URIs (uri.P) - preliminary file.
You can also find some files with extension .G,
whcih are the original source files to generate the XML Parser.
To start using the W4
RuleML compiler, unpack
the .zip file and compile the file ruleml.P within XSB Prolog.
Ignore the singleton variable warnings produced
while compiling the file xmlparser.P.
|
Utilization
We assume that the user is familiar with the syntax of
RuleML and Prolog. We start by describing the main predicates for
loading, discarding, and writing rule bases.
In what follows, the In parameter means either a term of the form:
- ruleML( FilePath ), identifying a RuleML
file.
- prolog( FilePath ), identifying a Prolog
file.
Rule Bases are identified by a _rbaselab element in
a RuleML file or by a module/1 declaration in a Prolog files. If
the label is absent, the rule base name by default is [].
Reading Rule Bases
The user has available several predicates for reading
in rule bases.
- loadRules( In ), loads a rule base
inserting the rules in the Prolog knowledge
base.
- reloadRules( In ), discards all the rules
of the rule base and then loads the rules.
- updateRules( In ),
updates a rule base, advancing a step (for supporting EVOLP update
programs).
- consultRules( In ),
consults a rule base by loading it, and executing the queries
provided in the rulebase. The output is a XML
document with the answer substitutions, written to the current output.
- consultRules( In, Out
), consults a rule base by loading it, and
executing the queries provided in the rulebase. If
Out is a variable then it is returned a list of answer
substitutions. Otherwise, a XML document with the answer
is written to the stream
identified by Out.
- reconsultRules( In ),
reconsults a rule base by loading it, and executing the queries
provided in the rulebase. The output is a XML
document with the answer substitutions, written to the current output.
- reconsultRules( In, Out
), reconsults a rule base by loading it,
and executing the queries provided in the rulebase. If
Out is a variable then it is returned a list of answer
substitutions. Otherwise, a XML document with the answer
is written to the stream
identified by Out.
Abolishing
Rule Bases
Only two predicates are available for abolishing rule
bases:
- abolishRules, cleans all the loaded
rule bases in the Prolog knowledge base.
- abolishRules( Label ), cleans all the rules
of the rule base identified by Label (recall that [] is the default
label, if none is provided).
Listing
Rule Bases
Two forms are provided, one for listing a given
predicate of a rule base, and another for listing all rules of a rule
base:
- listRules(RuleBaseLabel, PredInd,
Stream ), lists the rules
of PredInd (of the form Name/Arity) in RuleBaseLabel.
Argument Stream is the name of a stream. Rules are listed in
RuleML format.
- listAllRules(RuleBaseLabel, Stream ), lists
all the rules in RuleBaseLabel. Argument
Stream is the name of a stream. Rules are listed in RuleML
format.
Querying
Rule Bases
The user can query a rule base ŕ la Prolog or ŕ la
RuleML. For the RuleML support two query predicates are defined:
- queryRules(Queries,
Answers ), queries all the
loaded rule bases.
- queryRules(RuleBaseLabel,
Queries, Answers ),
queries a given RuleBase.
The Queries argument describes a list of queries to
execute. Each query is a term of the form:
- query( Goal, Label, ListOfSubsts ), where
Goal is the goal to execute (ŕ la Prolog), Label
identifies the answers of the query and can be a constant or a complex
term, and ListOfSubsts is a list of equalities of the form Atom = Var
in order to collect and name the substitutions variables.
If the Answers argument is a variable then it
is returned a list of answers of the form:
- answer( Label, ListOfSubsts), where Label
is a label to identify the query and ListOfSubsts is a list containing
terms of the form Atom = Subst. The template for the ListOfSubsts
should be provided in the Queries argument.
If the Answers argument is not a variable,
then it is assumed that it describes an output stream and the Answers
are written in XML format.
Alternatively, the user can query the rule base
resorting to the demo/1 or demo/2 predicates:
- demo( Goal ), to query Goal in the
union of all rule bases.
- demo( RuleBaseLabel, Goal ), to query
Goal in the rule base identified by RuleBaseLabel.
Translation of Rule Bases
The W4 RuleML compiler provides two translation
predicates from RuleML syntax to Prolog and vice-versa. The use is the
following:
- ruleML2prolog( InFilePath, OutFilePath ),
converts a RuleML base to Prolog syntax.
- prolog2ruleML( InFilePath, OutFilePath ),
converts a Prolog file to RuleML.
Both predicates loose variable names, since the
current version of XSB Prolog does not provide the standard mechanisms
for getting the original variables names.
The conversion of RuleML to Prolog is particular useful
to see how an RuleML is encoded by the RuleML compiler.
|
Example
Session Consider the
taxonomy rule base.Start by compiling the
RuleML compiler:
XSB Version 2.5 (Okocim) of March 11, 2002
[x86-pc-windows; mode: optimal; engine: slg-wam; gc: indirection;
scheduling: lo
cal]
| ?- [ruleml].
[ruleml loaded]
[prologread loaded]
[prologwrite loaded]
[rulemlread loaded]
[xml2termns loaded]
[xmldom loaded]
[xml loaded]
[iostream loaded]
[utf loaded]
[uri loaded]
[xmlparser loaded]
[rulemlwrite loaded]
[rulebase loaded]
[gwfsxpengine loaded]
yes
Next, load the rule base:
| ?- loadRules( ruleML( 'taxonomy.ruleml' ) ).
yes
Let us try some basic queries:
| ?- demo( animals, animal(X) ).
X = Pluto;
X = Dracula;
X = Tweety;
X = Joe;
no
| ?- demo( animals, flies(X) ).
X = Dracula;
X = Tweety;
no
| ?- demo( animals, neg flies(X) ).
X = Joe;
X = Pluto;
no
| ?- demo( animals, not flies(X) ).
++Error[XSB]: [Runtime/P] FLOUNDERING: tnot/1 used with a non-ground
subgoal: demo_wfsxp_tu_goal(animals,flies(_h152517))
Aborting...
Removing incomplete tables...
| ?- demo( animals, ( animal(X), not flies(X) ) ).
X = Pluto;
X = Joe;
no
We can also try the same queries but now using the
queryRules/3 predicate in its two flavors:
| ?- queryRules( animals, [query( flies(X), q1, [animal=X] )], Ans ).
X = _h152778
Ans = [[answer(q1,[animal = Dracula]),answer(q1,[animal = Tweety])]];
no
| ?- queryRules( animals, [query( flies(X), q1, [animal=X] ),query( neg
flies(X)
, q2, [non=X])], Ans ).
X = _h152980
Ans = [[answer(q1,[animal = Dracula]),answer(q1,[animal = Tweety])],[answer(q2,[
non = Joe]),answer(q2,[non = Pluto])]];
no
| ?- queryRules( animals, [query( flies(X), q1, [animal=X] )], userout
).
<answers><_answer><_rlab><ind>q1</ind></_rlab><_subst><var>animal</var><ind>Dracula</ind></_subst></_answer>
<_answer><_rlab><ind>q1</ind></_rlab><_subst><var>animal</var><ind>Tweety</ind></_subst></_answer>
</answers>
X = _h153294;
no
| ?- queryRules( animals, [query( flies(X), q1, [animal=X] ),query( neg
flies(X)
, q2, [non=X])], userout ).
<answers><_answer><_rlab><ind>q1</ind></_rlab><_subst><var>animal</var><ind>Dracula</ind></_subst></_answer>
<_answer><_rlab><ind>q1</ind></_rlab><_subst><var>animal</var><ind>Tweety</ind></_subst></_answer>
<_answer><_rlab><ind>q2</ind></_rlab><_subst><var>non</var><ind>Joe</ind></_subst></_answer>
<_answer><_rlab><ind>q2</ind></_rlab><_subst><var>non</var><ind>Pluto</ind></_subst></_answer></answers>
X = _h153480;
To convert the original RuleML file to Prolog just
issue the goal:
| ?- ruleML2prolog( 'taxonomy.ruleml', 'taxonomy.pl'
).
yes
The resulting program is:
:- module(animals).
animal(A) :- mammal(A).
animal(A) :- bird(A).
animal(A) :- 'dead animal'(A).
mammal(A) :- bat(A).
bird(A) :- penguin(A).
bird('Tweety').
mammal('Pluto').
penguin('Joe').
bat('Dracula').
'dead animal'('Dracula').
neg flies(A) :- animal(A),neg 'flying animal'(A),not(flies(A)).
neg 'flying animal'(A) :- not('flying animal'(A)).
flies(A) :- bat(A),'flying bat'(A),not(neg flies(A)).
'flying bat'(A) :- not(neg 'flying bat'(A)).
flies(A) :- bird(A),'flying bird'(A),not(neg flies(A)).
'flying bird'(A) :- not(neg 'flying bird'(A)).
neg flies(A) :- penguin(A),neg 'flying penguin'(A),not(flies(A)).
neg 'flying penguin'(A) :- not('flying penguin'(A)).
neg flies(A) :- 'dead animal'(A),neg 'flying dead'(A),not(flies(A)).
neg 'flying dead'(A) :- not('flying dead'(A)).
neg 'flying bat'(A) :- 'dead animal'(A),bat(A),neg 'flying dead bat'(A).
neg 'flying dead bat'(A) :- not('flying dead bat'(A)).
neg 'flying bird'(A) :- 'dead animal'(A),bird(A),neg 'flying dead
bird'(A).
neg 'flying dead bird'(A) :- not('flying dead bird'(A)).
'flying dead bat'('Dracula').
'flying animal'(A) :- bat(A),'flying bat'(A).
'flying animal'(A) :- bird(A),'flying bird'(A).
'flying dead'(A) :- bat(A),'flying dead bat'(A).
neg 'flying bird'(A) :- penguin(A),neg 'flying penguin'(A).
|
Current Limitations
- Tups, Rolis e Hrefs in the RuleML document are
translated but ignored by the engine.
- Constructive Negation is not implemented.
- The code is meta-interpreted, and not compiled. It
amkes extensive use of tabling.
- Original Prolog variable names are not kept.
- Missing SOAP 1.2 interface. Under construction.
- Further testing...
|
Future developments
- Integration with Stable Models/Answer Sets engine
via NMR support from XSB Prolog 2.6.
- Update semantics.
- Triple Engine for handling RDF and OWL documents.
- URI processor, for resolving relative references.
- Porting to other Prolog systems.
- More accurate documentation.
|
Comments
and Suggestions
- Please send your enquiries, suggestions, or bug
lists to cd@di.fct.unl.pt with
subject title starting with "RULEML:".
|
|
|
Last update: July 31st, 2003 |