SWSL is serialized in XML using RuleML. RuleML-style serialization of SWSL enables interoperation with other XML applications for rules and provides an encoding for transporting SWSL-Rules via the SOAP infrastructure of Web services.
RuleML integrates various rule paradigms via common set of concepts and defines a family of rule-based, Web-enabled sublanguages with various degrees of expressiveness. This section applies the RuleML approach to serialization of SWSL. This is done mostly by reusing and sometimes extending the existing RuleML sublanguages. In addition, a new sublanguage for the serialization of HiLog is developed.
Serialization of the presentation syntax of SWSL-Rules amounts to construction of explicit parse trees and then representing these trees linearly as XML markup that is compliant with XML Schema of the appropriate RuleML sublanguages. Starting with Version 0.89, the XML Schema specification of RuleML supports SWSL-Rules.
Serialization of SWSL-FOL does not require any new constructs, and it is done by repurposing existing RuleML features. Serialization of SWSL-FOL is discussed at the end of this section, in Section 4.5.
Conceptually, RuleML models XML trees as objects and thus divides all XML tags into class descriptors, called type tags, and property descriptors, called role tags. This conceptual object-oriented model implies that type tags and role tags must alternate, which is known as striped XML syntax. For instance, in F-logic and RDF, classes can have properties, which point to classes, which have properties that point to classes, etc. Similarly, in the striped XML syntax, a type tag has role tags as subelements, whose children are again type tags, etc. When the role of a subelement is clear from the context, its tag may be skipped for brevity, as in RDF's StripeSkipping.
HiLog terms. The HiLog serialization uses the
type tag Hterm
for HiLog terms, Con
for constants, and Var
for variables. Since HiLog allows
arbitrary terms to be used in the position of predicate and function
symbols, the RuleML serialization allows not only constants but also
variables and Hterms under the op
role tag . The
following illustrates the main aspects of the HiLog serialization.
Regular first-order terms. For instance, the HiLog
terms c
, f(a,?X)
, ?X
are
represented by the following three XML fragments, respectively:
<Con>c</Con>
<Hterm> <op><Con>f</Con></op> <Con>a</Con> <Var>X</Var> </Hterm>
<Var>X</Var>
Variables over function symbols. For
instance, the terms ?X(a,?Y)
,
?X(a,?Y(?X))
are serialized as follows:
<Hterm> <op><Var>X</Var></op> <Con>a</Con> <Var>Y</Var> </Hterm>
<Hterm> <op><Var>X</Var></op> <Con>a</Con> <Hterm> <op><Var>Y</Var></op> <Var>X</Var> </Hterm> </Hterm>
Parameterized function symbols. For
instance, the HiLog terms f(?X,a)(b,?X(c))
,
?Z(?X,a)(b,?X(?Y)(d))
, ?Z(f)(g,a)(p,?X)
will be serialized as shown below:
<Hterm> <op> <Hterm> <op><Con>f</Con></op> <Var>X</Var> <Con>a</Con> </Hterm> </op> <Con>b</Con> <Hterm> <op><Var>X</Var></op> <Con>c</Con> </Hterm> </Hterm>
<Hterm> <op> <Hterm> <op><Var>Z</Var></op> <Var>X</Var> <Con>a</Con> </Hterm> </op> <Con>b</Con> <Hterm> <op> <Hterm> <op><Var>X</Var></op> <Var>Y</Var> </Hterm> </op> <Con>d</Con> </Hterm> </Hterm>
<Hterm> <op> <Hterm> <op> <Hterm> <op><Var>Z</Var></op> <Con>f</Con> </Hterm> </op> <Con>g</Con> <Con>a</Con> </Hterm> </op> <Con>p</Con> <Var>X</Var> </Hterm>
HiLog atomic formulas. Since any HiLog term is also a HiLog atomic
formula, the RuleML serialization for these formulas is the same as for HiLog terms.
The following example shows an encoding of a query, which uses
the Query
element of RuleML:
?- q(?X) and ?X.
<Query> <And> <Hterm> <op><Con>q</Con></op> <Var>X</Var> </Hterm> <Var>X</Var> </And> <Query>
Another interesting example is a HiLog rule
call(?X) :- ?X.
which is a logical definition of the meta-predicate call/1
in
Prolog. This is translated using the RuleML
tags Implies, head, and body, as follows:
<Implies> <head> <Hterm> <op><Con>call</Con></op> <Var>X</Var> </Hterm> </head> <body> <Var>X</Var> </body> </Implies>
The explicit equality predicate :=:
is serialized using the
RuleML's element Equal
. For example,
f(a,?X):=:g(?Y,b) :- p(?X,?Y).
is serialized as
<Implies> <head> <Equal> <Hterm> <op><Con>f</Con></op> <Con>a</Con> <Var>X</Var> </Hterm> <Hterm> <op><Con>g</Con></op> <Var>Y</Var> <Con>b</Con> </Hterm> </Equal> </head> <body> <Hterm> <op><Con>p</Con></op> <Var>X</Var> <Var>Y</Var> </Hterm> </body> </Implies>
To serialize the Frames layer of SWSL-Rules we need to show the serialization of the various molecules and path expressions introduced by F-logic.
Molecules. The serialization of molecules uses slotted
atoms, which have an oid
but often do not have
an op
. The overall structure of F-logic molecules (except for
class membership and subclassing) is as follows:
Atom ::= oid op? slot*
Value molecules.
If t
, m
, v
are terms then the
value molecule t[m -> v]
is serialized as follows:
<Atom><oid>t'</oid><slot>m' v'</slot></Atom>
Here and elsewhere we use primes to represent recursive RuleML
serialization. For instance, t'
, m'
,
and v'
denote RuleML serializations
of t
, m
, and v
,
respectively. For instance, o[f(a,b) -> 3]
would be
represented by the following fragment:
<Atom> <oid><Con>o</Con></oid> <slot> <Hterm><Con>f</Con><Con>a</Con><Con>b</Con></Hterm> <Con>3</Con> </slot> </Atom>
The syntax t[m -> {v1,...,vk}]
is also supported: the set-valued result is serialized using
the Set
tag:
<Atom> <oid>t'</oid> <slot> m' <Set>v1',...,vk'</Set> </slot> </Atom>
Boolean molecules. These molecules have the form
t[m]
where t
and m
are
terms. They are serialized using singleton slot
elements. For instance,
mary[female]
is represented as follows:
<Atom> <oid><Con>mary</Con></oid> <slot> <Con>female</Con> </slot> </Atom>
Class membership molecule. Class membership
molecules of the form
t:s
are serialized using the InstanceOf element:
<InstanceOf>t' s'</InstanceOf>
where t'
and s'
represent RuleML
serializations of t
and s
.
Subclass molecule. The subclass molecules of the
form t::s
are represented using
the SubclassOf
element as follows:
<SubclassOf>t' s'</SubclassOf>
As before, t'
and s'
represent RuleML
serializations of t
and s
, respectively.
Signature molecule. Signature molecules of the
form t[m => v]
are represented using
the Signature
element, where the prime represents
RuleML serialization of the corresponding term:
<Signature><oid>t'</oid><slot>m' v'</slot></Signature>
Boolean signature molecules. A Boolean signature
molecule has the form t[=>m]
. Its RuleML
serialization uses singleton slot
elements within a Signature
element:
<Signature><oid>t'</oid><slot>m'</slot></Signature>
Cardinality constraints. Signature molecules can have associated cardinality constraints. Such molecules have the form
t[s(t1,...,tn) {min : max}
=> v]
In RuleML this becomes:
<Signature> <oid>t'</oid> <slot mincard="min" maxcard="max"> <Hterm><Con>s'</Con>t1'...tn'</Hterm> v' </slot> </Signature>
Nested molecules. Direct serialization of nested molecules is not currently supported. Instead, they must first be broken into conjunctions of non-nested molecules and then serialized.
Slot access and path expressions. Serialization of slot access
uses the RuleML Get
primitive. Serialization of path expressions
is supported via the polyadic RuleML SlotProd
element.
For example, room.ceiling.color
becomes the following:
<Get> <oid><Con>room</Con></oid> <SlotProd><Con>ceiling</Con><Con>color</Con></SlotProd> </Get>
SWSL-Rules supports reification of F-logic molecules, formulas that can
occur in the head or the body of a rule, and of the rules themselves. The
only restriction is that explicit quantifiers cannot occur under the
scope of the reification operator. The main idea behind RuleML
serialization of such statements is that the corresponding serialized
statement must be embedded within a Reify
element.
To illustrate, consider the following molecule:
a[b -> ${p(X[foo -> bar])}]
Since the reified statement (p(X[foo -> bar])
is an
Hterm
, this tag becomes the child of the Reify
element.
<Hterm> <oid><Con>a</Con></oid> <slot> <Con>b</Con> <Reify> <Hterm> <op><Con>p</Con></op> <Hterm> <oid><Var>X</Var></oid> <slot><Con>foo</Con><Con>bar</Con></slot> </Hterm> </Hterm> </Reify> </slot> </Hterm>
The following example illustrates serialization of a reified rule.
john[believes -> ${p(?X) implies q(?X)}].
The corresponding serialization is shown below.
Since the top-level tag of a rule is Implies
,
this tag becomes the child of the Reify
element.
<Hterm> <oid>john</oid> <slot> <Con>believes</Con> <Reify> <Implies> <body> <Hterm> <op><Con>p</Con></op> <Var>X</Var> </Hterm> </body> <head> <Hterm> <op><Con>q</Con></op> <Var>X</Var> </Hterm> </head> </Implies> </Reify> </slot> </Hterm>
Serialization of SWSL-FOL reuses the existing FOL RuleML sublanguage. The serialization is accomplished through the following rules:
<Atom>...</Atom>
.
What actually goes between the Atom tags depends on the type
of the atomic formula (i.e., whether it is a predicate formula or a
F-logic frame).
<And>
φ ψ </And>
,
<Or>
φ ψ </Or>
,
<Neg>
φ </Neg>
,
<Implies>
φ
ψ </Implies>
(SWSL-FOL's
φ impliedBy
ψ must be first replaced
with ψ implies
φ), and <Equivalent>
φ
ψ </Equivalent>
(for SWSL-FOL's iff
).
X
is a variable and φ is a serialized SWSL-FOL
formula, then the following are also SWSL-FOL serialized formulas:
<Exists>
<Var>X</Var>
φ </Exists>
and
<Forall>
<Var>X</Var>
φ </Forall>
. Serialized SWSL-FOL also allows to
combine quantifiers of the same sort and reduce repetitiveness. For
instance, <Exists>
<Var>X</Var>
<Var>Y</Var>
φ </Exists>
is a shorthand for
<Exists>
<Var>X</Var>
<Exists>
<Var>Y</Var>
φ </Exists>
</Exists>
.