Copyright © 2008 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C liability, trademark and document use rules apply.
This document specifies RIF-PRD, a Rule Interchange Format (RIF) dialect to enable the interchange of production rules.
This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.
This document is being published as one of a set of 8 documents:
The Rule Interchange Format (RIF) Working Group seeks public feedback on these Working Drafts. Please send your comments to public-rif-comments@w3.org (public archive). If possible, please offer specific changes to the text that would address your concern. You may also wish to check the Wiki Version of this document for internal-review comments and changes being drafted which may address your concerns.
Publication as a Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.
This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.
Contents |
This document specifies the production rule dialect of the W3C rule interchange format (RIF-PRD). Production rules are rules with an "if" part and a "then" part. The "if" part, also called a "condition", is like the condition part of logic rules (as covered by the basic logic dialect of the W3C rule interchange format, RIF-BLD). The "then" part of production rules may contain actions, unlike the conclusion of logic rules that may contain only a logical statement. Actions can modify the knowledge base and have other side-effects.
Example 1.1. A customer becomes a "Gold" customer as soon as his cumulative purchases during the current year top $5000; Customers that become "Gold" customers must be notified immediately, and a golden customer card will be printed and sent to them within one week; For shopping carts worth more than $1000, "Gold" customers receive an additional discount of 10% of the total amount are all examples of production rules.
As a common XML serialisation format for many production rule languages, RIF-PRD specifies an XML syntax for the most widely used features (section 2 - Syntax), and the operational semantics that RIF-PRD constructs are intended to represent (section 3 - Operational semantics).
This document is mostly intended for the designers and developers of RIF-PRD implementations, that is, applications that serialize production rules as RIF-PRD XML (producer applications) and/or that deserialize RIF-PRD XML documents into production rules (consumer applications).
Editor's Note: This working draft specifies the RIF-PRD serialisation of a set of core constructs only. Future versions of this document will extend the set of RIF-PRD constructs to cover the most widely used features of production rule languages. The working group seeks feedback on what features should be supported by RIF-PRD and what constructs should or should not be required from conformant RIF-PRD implementations.
As a RIF dialect, RIF-PRD has also been designed to maximize interoperability between rule languages over the World Wide Web. In this draft, this is achieved by sharing the same syntax for the subset of RIF documents where the semantics intended for a production ruleset serialized in RIF-PRD, and the semantics intended for a logic rule base serialized in the basic logic dialect of RIF, RIF-BLD, agree. The correspondence between RIF-PRD and RIF-BLD is detailed in Appendix: Compatibility with RIF-BLD.
Editor's Note: Future versions of this working draft will draw on other RIF documents to maximize interoperability with other rule languages, most noticeably the RIF data types and builtins specification, RIF-DTB, and the RIF extensibility framework (currently being specified by the working group; see also the RIF framework for logic dialects, RIF-FLD, that specifies a framework for designing RIF logic dialects).
In the section 2, two related but distinct syntaxes for RIF-PRD components are introduced:
Example 1.2. In RIF-PRD presentation syntax, the first rule in example 1.1. might be represented as follows:
Prefix(ex1 http://rif.example.com/2008/prd#) (* ex1:rule_1 *) Forall ?customer ?purchasesYTD ( ex1:Gold(?customer) :- And( ?customer#ex1:Customer ?customer[ex1:purchasesYTD->?purchasesYTD] pred:numeric-greater-than(?purchasesYTD 5000) ))
Editor's Note: As a consequence of the re-use of RIF-BLD presentation syntax, examples and fragments written in RIF-PRD non-normative presentation syntax may have an unfamiliar look to production rules developers and users. The working group seeks feedback on this issue as well.
The overall structure of the syntax of RIF-PRD is also presented as an UML-like diagram in appendix: UML-like diagram of RIF-PRD syntax. The diagram provides an overview of RIF-PRD syntactic classes and shows at a glance how they relate to each others. It is provided for informative purposes only.
In the section 3, the intended semantics for RIF-PRD constructs is specified normatively. As can be seen from the examples above, production rules, in general, are not logic rules, and they are not amenable to a model theory: followingly, the intended semantics of rules and set of rules serialized as RIF-PRD is specified operationally, in this document. The compatibility with the model theoretic semantics of RIF-BLD for the contructs they share is explained and proven in appendix: Compatibility with RIF-BLD.
Throughout this document, the xsd: prefix stands for the XML Schema namespace URI http://www.w3.org/2001/XMLSchema#, the rdf: prefix stands for http://www.w3.org/1999/02/22-rdf-syntax-ns#, and rif: stands for the URI of the RIF namespace, http://www.w3.org/2007/rif#.
Syntax such as xsd:string should be understood as a compact URI (CURIE) -- a macro that expands to a concatenation of the character sequence denoted by the prefix xsd and the string string. The compact URI notation is used for brevity only, and xsd:string should be understood, in this document, as an abbreviation for http://www.w3.org/2001/XMLSchema#string.
The XML syntax of RIF-PRD is specified for each component as a pseudo-schema, as part of the description of the component. The pseudo-schemas use BNF-style conventions for attributes and elements: "?" denotes optionality (i.e. zero or one occurrences), "*" denotes zero or more occurrences, "+" one or more occurrences, "[" and "]" are used to form groups, and "|" represents choice. Attributes are conventionally assigned a value which corresponds to their type, as defined in the normative schema. Elements are conventionally assigned a value which is the name of the syntactic class of their content, as defined in the normative schema.
<!-- sample pseudo-schema --> <defined_element required_attribute_of_type_string="xs:string" optional_attribute_of_type_int="xs:int"? > <required_element /> <optional_element />? <one_or_more_of_these_elements />+ [ <choice_1 /> | <choice_2 /> ]* </defined_element>
Three kinds of syntactic components are used to specify RIF-PRD:
This section describes the fictious RIF-PRD use case of Joe the Hen Public, and the rule that will be used as a running example in this document.
Joe the Hen Public developed a very sophisticated program to grow feeble chicks into deliciously plump chickens for a minimal cost. Joe publishes his method on his Web site www.juicychicken.org. Since he is still experimenting to improve his method, the rules to follow change quite often, and Joe decided to publish them in RIF as well, so that his followers can easily, even automatically, implement the very latest version.
Joe's method is a complex exercise of behavioural hen psychology: one aspect that is relevant for the example is that it requires that, under certain internal and/or external conditions, hen own potatoes, hen owned potatoes are mashed, hen daily grain allowance is increased or decreased etc.
Joe's latest addition to his knowledge base is an advice that: on a Monday, if a chicken over 8 months old owns a potato that weights (in decigrams) more than half its age, and if the fox is not in the hen house, then the potato should be mashed and the daily grain allowance of the chicken increased by 10%.
Joe calls it the "Chicken and Mashed Potatoes", or CMP, rule. The
CMP rule is a production rule: that is, when the condition is
satisfied and the rule is implemented (that is, fired), the
consequence is that some actions are executed (mashing potatoes,
modifying a chicken's diet, managing ownership relations etc).
Therefore, it is best interchanged using RIF-PRD, the production
rule dialect of RIF.
The CMP rule might be rephrased in RIF-PRD non-normative presentation syntax as follows:
(* joe:ChickenAndMashedPotatoes *) // The identifier of the rule is the IRI "joe:ChickenAndMashedPotatoes" Forall ?chicken ?potato ?allowance ?age ?weight ( // The Forall construct is used to declare the rule variables: "?chicken" etc Do( // Rule actions list Execute(joe:mash(?potato)) // The first action is to mash the potato that is bound to variable ?potato Retract(?chicken[joe:allowance->?allowance]) ?chicken[joe:allowance->External(func:numeric-multiply(?allowance 1.1))] // The value of the "allowance" property of the chicken that is bound to ?chicken // is increased by 10% Retract(joe:owns(?chicken ?potato)) ) :- // IF And( // Rule conditions ?chicken#joe:Chicken // The object bound to ?chicken is a "Chicken" as specified in Joe's object model ?chicken[joe:age->?age joe:allowance->?allowance] // The value of the "age" property of the "Chicken" object bound to ?chicken is // equal to the value bound to the variable ?age, and the values of the "allowance" // property is equal to the value bound to ?allowance External(pred:numeric-greater-than(?age 8)) // The value bound to ?age is greater than 8, where the function "numeric-grater-than" // is specified by RIF-PRD and must be supported by all implementations ?potato#joe:Potato ?potato[joe:weight->?weight] joe:owns(?chicken ?potato) External(pred:numeric-greater-than(?weight External(func:numeric-divide(?age 2)))) External(pred:string-not-equal(External(joe:today()) "Tuesday")) Not(External(joe:foxAlarm())) ))
To make sure that his rules can be implemented unambiguously, Joe published a data model (e.g., an XML schema) that identifies Chicken and Potato as two classes of objects:
Joe further specifies:
All these (types and names) are defined in Joe's namespace http://rif.examples.com/2008/joe#.
The assumption is that a system that consumes a RIF document published by Joe knows how to map Joe's published data model and specification of predicates and functions to/from its own underlying data representation. What a consumer is expected to do when this is not the case is still under discussion and will be specified as a conformance clause in a future version of this document.
This section specifies the XML syntax for serializing the rule conditions and the rule actions, as well as complete production rules, groups of rules and formulae, and any accompanying metadata. Finally, RIF-PRD presentation syntax is specified.
This section specifies the XML syntax that is used to serialize, in RIF-PRD, the different boolean expressions that can be found in production rules. That syntax is sometimes called the condition language, by reference to the condition language of RIF-BLD, which determines what conditions in a logic rule can be represented in RIF-BLD. It plays a similar role in RIF-PRD and, to maximize interoperability, the two dialects share the same constructs everywhere they agree on the semantics.
The most basic construct in RIF is the TERM. The TERM is an abstract construct, concretely visible, in RIF-PRD, as a Const, a Var or an External.
The ATOMIC is the basic building block of RIF. ATOMIC is an abstract class: it is visible in RIF-PRD as either an Atom, an Equal, a Member, a Subclass or a Frame. Each kind of ATOMIC is a composition of TERMs.
The next level of constructs are assemblies of ATOMICs. Together, the various kinds of assemblies form the abstract construct FORMULA. RIF-PRD knows six kinds of FORMULAs: the single ATOMIC, the Externally evaluated Atom or Frame, and the recursively specified And, Or, NmNot and Exists.
The following sections specify each construct separately, grouped by abstract syntactic classes.
Editor's Note: Future version of this document will specify additional constructs to increase the expressive coverage of RIF-PRD, and the precise syntax of some constructs may change. The working group seeks feedback on which additional constructs and/or which extension of specified constructs would be most useful to add.
The TERM class of constructs is used to represent constants, variables and the application of function symbols to other TERMs.
As an abstract class, TERM is not associated with specific XML markup in RIF-PRD instance documents.
[ Const | Var | External ]
In RIF, the Const construct is used to represent a constant.
The Const element has a required type attribute and an optional xml:lang attribute:
The content of the Const element is the constant's litteral, which can be any Unicode character string.
<Const type=xsd:anyURI [xml:lang=xsd:language]? > Any Unicode string </Const>
Constant types. RIF requires that all dialects include the following builtin constant types. Rule sets that are exchanged through RIF can use additional symbol spaces.
The lexical spaces of the above symbol spaces are defined in the document [XML-SCHEMA2].
These two symbol spaces represent two subtypes of the XML Schema data type xs:duration with well-defined value spaces, since xs:duration does not have a well-defined value space (this may be corrected in later revisions of XML Schema data types, in which case the revised data type would be suitable for RIF DTB). The lexical spaces of the above symbol spaces are defined in the document [XDM].
This symbol space represents XML content. The lexical space of rdf:XMLLiteral is defined in the document [RDF-CONCEPTS].
This symbol space represents text strings with a language tag attached. The lexical space of rif:text is the set of all Unicode strings of the form ...@LANG, i.e., strings that end with @LANG where LANG is a language identifier as defined in [RFC-3066].
Constants in this symbol space are intended to be used in a way similar to RDF resources [RDF-SCHEMA]. The lexical space consists of all absolute IRIs as specified in [RFC-3987]; it is unrelated to the XML primitive type anyURI. A rif:iri constant must be interpreted as a reference to one and the same object regardless of the context in which that constant occurs.
Constants in this symbol space are local to the RIF documents in which they occur. This means that occurrences of the same rif:local constant in different documents are viewed as unrelated distinct constants, but occurrences of the same rif:local constant in the same document must refer to the same object. The lexical space of rif:local is the same as the lexical space of xs:string.
Editor's Note: The list of builtin constant types may be modified in future versions of this document, based on the content of future versions of the RIF data types and builtins document, RIF-DTB.
Editor's Note: The case of non-standard data types, that is, of constants that do not belong or cannot be cast in one of RIF builtin types for interchange purposes, is still under discussion in the WG. The WG seeks feedback on whether they should be allowed and why.
Symbols with an ill-formed lexical part. Constants that are represented in RIF in one of the aforesaid builtin types must be well-formed, i.e., their representation must belong to the lexical space associated with the type. For instance, 123^^xsd:long (that is, <Const type="xsd:long">123</Const>) has a correct lexical part, since 123 belongs to the lexical space of the data type xsd:long. In contrast, abc^^xsd:long (<Const type="xsd:long">abc</Const>) is ill-formed, as it does not have a correct lexical part. A compliant RIF-PRD translator MUST reject ill-formed symbols.
Example 2.1. In each of the examples below, a constant is first described, followed by its representation in RIF-PRD XML syntax.
a. A constant with builtin type xsd:integer and value 123:
<Const type="xsd:integer">123</Const>
b. A constant which symbol today is defined in Joe the Hen Public's namespace http://rif.examples.com/2008/joe#. The type of the constant is rif:iri:
<Const type="rif:iri"> http://rif.examples.com/2008/joe#today </Const>
c. A constant with symbol BigPotato that is local to the set of rules where it appears (e.g. a RuleSet specific to Paula's farm). The type of the constant is rif:local:
<Const type="rif:local">BigPotato</Const>
d. A constant with non-builtin type xsd:int and value 123:
<Const type="xsd:int">123</Const>
In RIF, the Var construct is used to represent variables.
The content of the Var element is the variable's name, represented as an Unicode character string.
<Var> any Unicode string </Var>
Example 2.2. The example below shows the XML serialization of the variable ?chicken.
Notice that the content of the Var element is the Unicode string chicken: in the RIF presentation syntax, the ?-prefix is used as a syntactic marker to denote a variable identifier, but RIF leaves it to the implementations to use whatever prefix they choose or require, if any.
<Var> chicken <Var>
As a TERM, an External element is used to represent an externally specified function, e.g. a builtin, a user-defined function, a query to an external data source...
The External element contains one content element, which in turn contains one Expr element that contains one op element, followed zero or one args element or zero of more slot elements:
<External> <content> <Expr> <op> Const </op> [ <args rif:ordered="yes"> TERM* </args>? | <slot rif:ordered="yes"> <Name> Any Unicode string </Name> TERM <slot>* ] </Expr> </content> </External>
Editor's Note: The slotted, or named arguments form of the External TERM construct is still under discussion (see also ISSUE-68). The working group seeks feedback on whether or not it should be included in PRD.
Builtin functions. RIF-PRD specifies a subset of XPath/XQuery Functions and Operators (XPath-Functions) that any conformant RIF-PRD implementation MUST support. The RIF-PRD builtin functions are listed in the Data Type and Builtins document.
The op Const must represent a constant symbol of type rif:iri that must uniquely identify the evaluated function to be applied to the args TERMs. It can be one of the builtin functions specified for RIF-PRD, or it can be application specific. In the latter case, it is the responsibility of the producers and consumers of RIF-PRD rulesets that reference non-builtin functions to agree on their semantics.
Example 2.3.
a. The first example below shows one way to represent, in RIF-PRD, the sum of integer 1 and a variable ?x, where the addition conforms to the specification of the builtin fn:numeric-add.
The prefix fn is associated with the namespace http://www.w3.org/2007/rif-builtin-function#.
<External> <content> <Expr> <op> <Const type="rif:iri"> fn:numeric-add </Const> </op> <args rif:ordered="yes"> <Const type="xsd:integer"> 1 </Const> <Var> x </Var> </args> </Expr> </content> </External>
b. Another example, that shows the RIF XML representation of a call to the application-specific nullary function today(), which symbol is defined in the example's namespace http://rif.examples.com/2008/joe#:
<External> <content> <Expr> <op> <Const type="rif:iri"> http://rif.examples.com/2008/joe#today </Const> </op> </Expr> </content> </External>
The ATOMIC class is used to represent atomic truth-valued statements. RIF-PRD covers rule languages in which the truth values of atomic statements can only be "true" or "false": that is, ATOMICs represent boolean statements. Dialects extending RIF-PRD may support additional truth values.
As an abstract class, ATOMIC is not associated with specific XML markup in RIF-PRD instance documents. It is specified in the normative schema as a substitution group.
[ Atom | Equal | Member | Subclass | Frame ]
In RIF, the Atom element is used to represent a relation (or predicate).
The Atom element contains one op element, followed by zero or one args element or zero or more slot arguments:
<Atom> <op> Const </op> [ <args rif:ordered="yes"> TERM* </args>? | <slot rif:ordered="yes"> <Name> Any Unicode string </Name> TERM <slot>* ] </Atom>
Editor's Note: The slotted, or named arguments form of the Atom construct is still under discussion (see also ISSUE-68). The working group seeks feedback on whether or not it should be included in PRD.
Example 2.4. The example below shows the RIF XML representation of the predicate owns(?c ?p), where the predicate symbol owns is defined in the example namespace http://rif.examples.com/2008/joe#.
<Atom> <op> <Const type="rif:iri"> http://rif.examples.com/2008/joe#owns </Const> </op> <args rif:ordered="yes"> <Var> c </Var> <Var> p </Var> </args> </Atom>
In RIF, Equal is used to represent equality relations.
The Equal element must contain one left sub-element an done right sub-element. The content of the left and right elements must be a construct from the TERM abstract class. The order of the sub-elements is not significant.
<Equal> <left> TERM </left> <right> TERM </right> </Equal>
In RIF, the Member element is used to represent membership relations.
The Member element contains two unordered sub-elements:
<Member> <instance> TERM </instance> <class> TERM </class> </Member>
Example 2.5. The example below shows the RIF XML representation of a boolean expression that tests whether the individual denoted by the variable ?c is a member of the class Chicken that is defined in the example namespace http://rif.examples.com/2008/joe#.
<Member> <instance> <Var> c </Var> </instance> <class> <Const type="rif:iri"> http://rif.examples.com/2008/joe#Chicken </Const> </class> </Member>
In RIF, the Subclass element is used to represent class inclusion relations.
The Subclass element contains unordered two sub-elements:
<Subclass> <sub> TERM </sub> <super> TERM </super> </Subclass>
In RIF, the Frame construct is used to represent relations that hold between an individual, also called an object, and the values of some its properties or attributes: that is, object-attribute-value triples.
Accordingly, a Frame element must contain:
<Frame> <object> TERM </object> <slot rif:ordered="yes"> TERM TERM </slot>* </Frame>
Example 2.6. The example below shows the RIF XML syntax of an expression that states that the object denoted by the variable ?c has the value denoted by the variable ?a for the property Chicken/age that is defined in the example namespace http://rif.examples.com/2008/joe#.
<Frame> <object> <Var> c </Var> </object> <slot rif:ordered="yes"> <Const type="rif:iri"> ttp://rif.examples.com/2008/joe#Chicken/age </Const> <Var> a </Var> </slot> </Frame>
Editor's Note: The example uses an XPath style for the key. How externally specified data models and their elements should be referenced is still under discussion (see ISSUE-37).
The FORMULA class is used to represent any truth-valued statement, atomic or not, that is allowed in the condition part of a rule covered by RIF-PRD. In rule languages covered by RIF-PRD, the truth values of statements can be "true" or "false": that is, FORMULAs can only represent boolean statements.
Dialects extending RIF-PRD may support additional truth values.
As an abstract class, FORMULA is not associated with specific XML markup in RIF-PRD instance documents.
[ ATOMIC | External | And | Or | NmNot | Exists ]
A FORMULA can be a single ATOMIC statement. See specification of ATOMIC, above.
In RIF-PRD, an External represents an externally specified predicate when it is a FORMULA (as opposed to a TERM; that is, in particular, when it appears in a place where a FORMULA is required, and not a TERM).
The External element contains one content element that contains one Atom element:
<External> <content> Atom </content> </External>
Builtin predicates. RIF-PRD specifies a subset of XPath/XQuery Functions and Operators (XPath-Functions) that any conformant RIF-PRD implementation MUST support. The RIF-PRD builtin predicates are listed in the Data Types and Builtins document.
The op Const in the Atom element must be a symbol of type rif:iri that must uniquely identify the evaluated predicate to be applied to the args TERMs. It can be one of the builtin predicates specified for RIF-PRD, or it can be application specific. In the latter case, it is up to the producers and consumers of RIF-PRD rulesets that reference non-builtin predicates to agree on their semantics.
Example 2.7. The example below shows the RIF XML representation of a boolean expression that tests whether the value denoted by variable ?a (e.g. the age of a chicken) is greater than the integer value 8, where the test is intended to behave like the builtin predicate op:numeric-greater-than as specified in XQuery 1.0 and XPath 2.0 Functions and Operators.
In the example, the prefix op: is associated with the namespace http://www.w3.org/2007/rif-builtin-predicate#.
<External> <content> <Atom> <op> <Const type="rif:iri"> op:numeric-greater-than </Const> </op> <args rif:ordered="yes"> <Var> a </Var> <Const type="xsd:decimal"> 8 </Const> </args> </Atom> </content> </External>
A FORMULA can represent the conjunction of zero of more statements, each of them represented by a FORMULA. This is represented by the And construct.
The And element contains zero or more formula elements, each containing an element of the FORMULA group.
<And> <formula> FORMULA </formula>* </And>
A FORMULA can represent the disjunction of zero of more statements, each of them represented by a FORMULA. This is represented by the Or construct.
The Or element contains zero or more formula elements, each containing an element of the FORMULA group.
<Or> <formula> FORMULA </formula>* </Or>
A FORMULA can represent the non-monotonic negation of a statement, itself represented by a FORMULA: this is represenetd by the NmNot construct.
The NnNot element contains exactly one formula element. The formula element contains an element of the FORMULA group, that represents the negated statement.
<NmNot> <formula> FORMULA </formula> </NmNot>
Editor's Note: The name of that construct may change, including the tag of the XML element.
In RIF, the Exists construct is used to represent an existentially quantified FORMULA.
The Exists element contains:
<Exists> <declare> Var </declare>+ <formula> FORMULA </formula> </Exists>
Example 2.8. The example below shows the RIF XML representation of a boolean expression that tests whether the chicken denoted by variable ?c is older than 8 months, by testing the existence of a value, denoted by variable ?a, that is both the age of ?c, as represented by a Frame as in example 2.6, and greater than 8, as represented by an External ATOMIC as in example 2.7.
<Exists> <declare> <Var> a </Var> </declare> <formula> <And> <Frame> <object> <Var> c </Var> </object> <slot rif:ordered="yes"> <Const type="rif:iri"> http://rif.examples.com/2008/joe#Chicken/age </Const> <Var> a </Var> </slot> </Frame> <External> <content> <Atom> <op> <Const type="rif:iri"> op:numeric-greater-than </Const> </op> <args rif:ordered="yes"> <Var> a </Var> <Const type="xsd:decimal"> 8 </Const> </args> </Atom> </content> </External> </And> </formula> </Exists>
This section specifies the XML syntax that is used to serialize, in RIF-PRD, what can appear in the action part of a rule supported by RIF-PRD.
RIF-PRD defines one single abstract class for actions,
ACTION, that is realized by:
The following sections specify each construct separately, grouped by abstract syntactic classes.
Editor's Note: This section is still under discussion in the working group (see ISSUE-62). The working group considers adding an Assign action to represent the modification of the value of an attribute in a fact represented by a Frame, and an Execute action to represent the execution of an arbitrary, externally specified procedure. The working group seeks feedback regarding the proposed syntax for the currently specified actions, as well as regarding which constructs for serializing individual actions should be supported by RIF-PRD and/or required from RIF-PRD implementations.
The ACTION class of constructs is used to represent the individual actions in the action part of a production rule represented in RIF-PRD.
This version of RIF-PRD covers fourACTIONs: ASSERT, New, Retract and ACTION_BLOCK .
As an abstract class, ACTION is not associated with specific XML markup in RIF-PRD instance documents.
[ ASSERT | New | Retract | ACTION_BLOCK ]
An ASSERT construct is used to represent actions that result in asserting an Atom or a Frame.
For compatibility with RIF-BLD, ASSERT is not associated with specific XML markup in RIF-PRD instance documents, and it is represented only as the target Atom or Frame.
[ Atom | Frame ]
Editor's Note: The working group seeks feedback regarding whether a specific XML element, Assert, modeled after the Retract element, below, should be used to serialize assertions, instead, to the price of reducing the interoperability with RIF-BLD.
The New construct is used to create a new frame object with membership in a given class.
The New element has an optional instance sub-element that contains a Var and a class sub-element that contains a Const. A new instance of the given class is created and bound to the instance variable.
<New> <instance> Var </instance>? <class> Const </class> </New>
Example 2.9. The example below shows the RIF XML representation of an action that asserts a new potato.
<New> <class> <Const type="rif:iri">http://rif.examples.com/2008/joe#Potato</Const> </class> </New>
The Retract construct is used to represent actions that result in negating an atomic statement.
An Atom, a Frame, or a frame object may be retracted. A frame object is denoted using a TERM. A frame object is retracted by removing it from the Member relation and removing all its Frames.
The Retract element has one target sub-element that contains an Atom, a Frame, or a TERM construct that represents the facts to be removed on implementing the action.
<Retract> <target> [ Atom | Frame | TERM ] </target> </Retract>
Example 2.10. The example below shows the RIF XML representation of an action that updates the chicken-potato ownership table by removing the predicate that states that the chicken denoted by variable ?c owns the potato denoted by variable ?p. The predicate is represented as in example 2.4.
<Retract> <target> <Atom> <op> <Const type="rif:iri"> http://rif.examples.com/2008/joe#owns </Const> </op> <args rif:ordered="yes"> <Var> c </Var> <Var> p </Var> </args> </Atom> </target> </Retract>
An ACTION_BLOCK construct is used to represent an ordered list of ACTIONs. There are two kinds of ACTION_BLOCK. One uses a restricted And construct for compatibility with RIF-BLD. The other uses a Do construct that is specific to RIF-PRD and permits local variables to be declared.
[ And | Do ]
<And> <formula> ASSERT </formula>* </And>
<Do> <declare> Var </declare>* <action> ACTION </action>* </Do>
Example 2.11. The example below shows the RIF XML representation of an action block that asserts a new 100 decigram potato.
<Do rif:ordered="yes"> <declare><Var>p</Var></declare> <New> <instance><Var>p</Var></instance> <class> <Const type="rif:iri">http://rif.examples.com/2008/joe#Potato</Const> </class> </New> <Frame> <object><Var>p</Var></object> <slot rif:ordered="yes"> <Const type="rif:iri">http://rif.examples.com/2008/joe#weight</Const> <Const type="xsd:decimal">100</Const> </slot> </Frame> </Do>
This section specifies the RIF-PRD constructs that are required, in addition to the ones specified in the sections on Conditions and Actions, to serialize, and interchange, complete production rules and rule sets.
The RULE construct is an abstract class: in RIF-PRD instance documents, it is either visible as a Implies, as a Forall, or as a single ACTIONS:
Editor's Note: This version of the draft does not specify a specific construct to serialize a ruleset in RIF-PRD: the generic Group construct can be used for that purpose - as specified in the next section, Groupings and metadata. Future versions of this draft may specify a specific-purpose construct, especially if semantically significant information has to be associated to rulesets (e.g. parameters etc). The working group seeks feedback on this (see also ISSUE-63).
The following sections specify each construct separately, grouped by abstract syntactic classes.
In RIF-PRD, the RULE class of constructs is used to represent rules.
As an abstract class, RULE is not associated with specific XML markup in RIF-PRD instance documents.
[ Implies | Forall | ACTION ]
The Implies construct is used to represent the conditional statement (that is, the "if-then", or condition-conclusion, or antecedent-consequent pair) that is at the core of a rule.
The Implies element contains an optional if sub-element and a then sub-element:
<Implies> <if> FORMULA </if>? <then rif:ordered="yes"> ACTION ACTION* </then> </Implies>
The Forall construct is used to represent universally quantified rules.
The Forall element contains:
<Forall> <declare> Var </declare>+ <pattern> FORMULA </pattern>* <formula> RULE </formula> </Forall>
Editor's Note: Nested Foralls make explicit the scope of the declared variables, and, thus, impose an order on the evaluation of the pattern and if FORMULAe in a rule. That ordering and the use of patterns to constrain the binding of variables may be of practical significance for some production rule systems, but they are irrelevant with respect to the intended semantics of the rules being interchanged (although they would be relevant if RIF-PRD was to be extended to support some kind of "else" or "case" construct). In addition, RIF-BLD does not allow nested Forall and does not support the association of contraining patterns to declared variables. The working group seeks feedback regarding whether nested Forall and constrainting pattern should be supported in RIF-PRD, to the cost of reducing the interoperability with RIF-BLD.
Example 2.10. The example below shows how the CMP rule extract: "if a chicken owns a potato and ..." could be serialized using a binding pattern FORMULA:
<Forall> <declare><Var>chicken</Var></declare> <formula> <Forall> <declare><Var>potato</Var></declare> <pattern> <External> <content> <Atom> <Const type="rif:iri"> http://rif.examples.com/2008/joe#owns </Const> <Args rif:ordered="yes"> <Var>chicken</Var> <Var>potato</Var> </Args> </Atom> </content> </External> </pattern> <formula> ... </formula> </Forall> </formula> </Forall>
This section specifies the additional constructs that are needed to build a complete instance RIF-PRD document, to group rules into rulesets, and to serialize the metadata that is possibly associated with elements of a rule, a group of rules or a RIF-PRD instance document.
The Group construct is used to represent groups of rules. In RIF-PRD, it is used to serialize rulesets, but it can be used more generally.
The Group element has zero or more sentence sub-elements that contain each another Group element or an element of the abstract RULE class of constructs.
<Group> <sentence> [ RULE | Group ] </sentence>* </Group>
The Document is the top level construct in a RIF-PRD instance document.
The Document contains zero or one payload sub-element, that must contain a Group element.
<Document> <payload> Group </payload>? </Document>
Metadata can be associated with any construct that represents a concrete class element in RIF-PRD: those are the elements with a CamelCase tagname starting with an upper-case character:
CLASSELT = [ TERM | ATOMIC | FORMULA | ACTION | RULE | Group | Document ]
An identifier can be associated to any construct of the abstract CLASSELT class of constructs, as an optional id sub-element that MUST contain a Const of type rif:local or rif:iri.
Metadata can be included in any instance of a concrete class element using the meta sub-element.
The RIF-PRD Frame construct is used to serialize metadata: the content of the Frame's object sub-element identifies the object to which the metadata is associated:, and the Frame's slots represent the metadata properly said as property-value pairs.
If the all the metadata is related to the same object, the meta element can contain a single Frame sub-element. If metadata related to several different objects need be serialized, the meta role can contain an And with zero or more formula sub-elements, each containing one Frameelement.
<CLASSELT> <id> Const </id>? <meta> [ Frame | <And> <formula> Frame </formula>* </And> ] </meta>? other CLASSELT content </CLASSELT>
Notice that the content of the meta sub-element of an instance of a RIF-PRD class element is not necessarily associated to that same instance element: only the content of the object sub-element of the Frame that represents the metadata specifies what the metadata is about, not where it is included in the instance RIF document.
It is suggested to use Dublin Core, RDFS, and OWL properties for metadata, along the lines of http://www.w3.org/TR/owl-ref/#Annotations -- specifically owl:versionInfo, rdfs:label, rdfs:comment, rdfs:seeAlso, rdfs:isDefinedBy, dc:creator, dc:description, dc:date, and foaf:maker.
Example 2.11. TBC
This section specifies a presentation syntax for RIF-PRD. The presentation syntax is not normative: its main purpose is to help make the normative specification of the semantics easier to read.
The presentation syntax is designed to be very close to RIF-BLD. A line by line comparison of the EBNF will show these few differences:
It is intended that the syntax and semantics of RIF-BLD and RIF-PRD are the same when the rule conclusion contains a single Atom or Frame, Not is not used, and logical functions are not used.
The following EBNF is from RIF-BLD, with lines prefixed with ! indicating a change for RIF-PRD:
FORMULA ::= 'And' '(' FORMULA* ')' | 'Or' '(' FORMULA* ')' | 'Exists' Var+ '(' FORMULA ')' | ATOMIC | 'External' '(' Atom | Frame ')' | ! 'Not' '(' FORMULA ')' ATOMIC ::= Atom | Equal | Member | Subclass | Frame Atom ::= UNITERM UNITERM ::= Const '(' (TERM* <| (Name '->' TERM)*) ')' Equal ::= TERM ' = ' TERM Member ::= TERM '#' TERM Subclass ::= TERM '##' TERM Frame ::= TERM '[' (TERM '->' TERM)* ']' ! TERM ::= Const | Var | 'External' '(' Expr ')' Expr ::= UNITERM Var ::= '?' UNICODESTRING
The following EBNF is taken from RIF-DTB and is unchanged for PRD. Its purpose is to provide shortcuts for constants.
ANGLEBRACKIRI ::= '<' IRI_REF '>' STRING ::= '"' UNICODESTRING '"' CURIE ::= PNAME_LN | PNAME_NS → see RIF-DTB Const ::= STRING '^^'ANGLEBRACKIRI | STRING '^^' CURIE | ANGLEBRACKIRI → shortcut for rif:iri | CURIE → shortcut for rif:iri | STRING → shortcut for xsd:string | NumericLiteral → shortcut for xsd:integer,xsd:decimal,xsd:double | '_' LocalName → shortcut for rif:local
The following EBNF is from RIF-BLD and defines rules, groups of rules, and the containing document. Changed lines are prefixed with !. Metadata can be associated with Document, Group, and RULE constructs.
! Document ::= IRIMETA? 'Document' '(' Group? ')' Group ::= IRIMETA? 'Group' '(' (RULE | Group)* ')' ! RULE ::= (IRIMETA? 'Forall' Var+ ('(' FORMULA '))* '(' RULE ')') | CLAUSE ! CLAUSE ::= Implies | ACTION ! Implies ::= IRIMETA? (ACTION | 'Do' '(' ACTION* ')') ':-' FORMULA IRIMETA ::= '(*' Const? (Frame | 'And' '(' Frame* ')')? '*)' IRI ::= UNICODESTRING Profile ::= UNICODESTRING
Finally, the following EBNF describes the syntax of PRD actions.
ACTION ::= ASSERT | Retract | New | ACTION_BLOCK ASSERT ::= Atom | Frame New ::= 'New' ( Var '#' )? Const Retract ::= 'Retract' '(' Atom | Frame | TERM ')' ACTION_BLOCK ::= 'And' '(' ASSERT+ ')' | 'Do' Var* '(' ACTION* ')'
For the purpose of specifying the semantics of a RIF-PRD RuleSet, a production rule system PRS is defined as a labeled terminal transition system (e.g. PLO04).
Definition (labeled terminal transition system): A labeled terminal transition system is a structure {C, L, →, T}, where
A labeled transition system is a structure {C, L, →} (without a set T of final configurations).
The idea of describing a PRS as a labeled terminal transition system is that, given a set of production rules RS and a set of facts w0, the rules in RS that are satisfied, in some sense, in w0 determine an action a1, which execution results in a new set of facts w1; the rules in RS that are satisfied in w1 determine an action a2 to execute in w1, and so on, until the system reaches a final configuration and stops. The result is the set of facts wn when the system stops.
Example 3.1. Judicael, one follower of Joe the Hen Public's method, has four chickens, Joe, Jack, Joe and Julia, that own three potatoes (BigPotato, SmallPotato, UglyPotato) among them:
That is the initial set of facts w0. Paula's rule set contains one single rule, that is, Joe's CMP rule:
(* joe:ChickenAndMashedPotatoes *) Forall ?chicken ?potato ?allowance ?age ?weight ( Do( Execute(joe:mash(?potato)) Retract(?chicken[joe:allowance->?allowance]) ?chicken[joe:allowance->External(func:numeric-multiply(?allowance 1.1))] Retract(joe:owns(?chicken ?potato)) ) :- And( ?chicken#joe:Chicken ?chicken[joe:age->?age joe:allowance->?allowance] External(pred:numeric-greater-than(?age, 8)) ?potato#joe:Potato ?potato[joe:weight->?weight] joe:owns(?chicken ?potato) External(pred:numeric-greater-than(?weight External(func:numeric-divide(?age 2)))) External(pred:string-not-equals(External(joe:today()), "Tuesday")) Not(External(joe:foxAlarm())) ))
When the rule is applied to w0:
Suppose that Judicael's implementation of today() returns Monday and that the foxAlarm() is false when the CMP rule is applied: the condition is satisfied, and the actions in the conclusion are executed with BigPotato substituted for ?potato, Joe substituted for ?chicken, and 10 substituted for ?allowance. This results in the following changes in the set of facts:
The resulting set of facts w1 is thus:
When the CMP rule in applied to w1, the first External predicate still selects {Joe/?chicken, Jack/?chicken, Julia/?chicken} as possible values for variable ?chicken, but the joe:own relation and the second External predicate do not select any possible substitution for the couple (?chicken, ?potato) anymore: the rule cannot be satisfied, and the system, having detected a final configuration, stops.
The result of the execution of the system is w1.
Let Const be the set of constant symbols that can be represented in RIF-PRD; Var, the set of variable symbols that can be represented in RIF-PRD; and Term the set of terms that can be represented in RIF-PRD.
Definition (signature): Let PRD be a signature of RIF-PRD defined as a tuple < DTS, Pred, Frame, Act, =, #, ##, External, Const, ArgNames, arity, type > with
Editor's Note: Or do we even want to associate a type to frames and actions itself (not just the arguments), i.e. the type of a frame object, the type of an action function?.
Definition
(alphabet). The alphabet of the presentation
language of RIF-PRD consists of
Definition (rule instance): An instance of a rule
r is a pair (rid, σ), where
rid uniquely identifies r and σ is a
ground substitution such that Var(r) ⊆ Dom(σ). Given
a rule r, id(r) denotes rid, the unique
identifier of r; given a rule instance ri =
(rid, σ), rule(ri) denotes the rule that is
uniquely identified by rid.
Definition (ruleset instance): an instance of a rule set RS is a set of rule instances rii, where ∀ i, rule(rii) ∈ RS. Given a rule set RS, Inst(RS) denotes the set of all the possible instances of all the rules in RS.
Let W be the set of ground formulas that can be represented in RIF-PRD, defined as follows:
Let L be the set of the atomic ground actions that can be represented in RIF-PRD:
Editor's Note: The definition of L is subject to change as the ACTION constructs are still under discussion.
Finally, let R be the set of all the rules that can be represented in RIF-PRD.
In this document, given a set X, P(X) denotes the power set of X, and S(X) denotes the set of the ordered lists of elements of X.
Given an expression f and a set of ground instances w, Eval(f, w) denotes the set of ground formulae that results of evaluating f in the context of w. The expression, f, is evaluated as a black-box: any side-effect of the evaluation, on w or otherwise, depends only on the specification of the semantics of f.
In accordance with the general semantics of the RIF framework described in [RIF-FLD] the truth values and
interpretations in RIF-PRD are defined as follows:
Definition (truth values) The set TV of truth
values in RIF-PRD consists of just two values, t and
f.
Definition (semantic structure) Let PRD be a signature. I is a semantic structure for PRD if I = <TV, DTS, D, Dind, IC, IV, Iframe, Isub, 'Iisa, I=, Iexternal, Itruth> consists of the following.
D is a non-empty set of elements called the domain of I. Dind is a nonempty subsets of D. Dind is used to interpret the elements of Const of PRD that are individuals. TV denotes the set of truth values that the semantic structure uses and DTS of PRD is set of identifiers for primitive datatypes.
The other components of I are total mappings defined as follows:
This mapping interprets constant symbols: IC(c) ∈ Dind
This mapping interprets variable symbols.
This mapping interprets frame terms. An argument, d ∈ Dind, to Iframe represents an object and the finite bag {<a1,v1>, ..., <ak,vk>} represents a bag of attribute-value pairs for d. We will see shortly how Iframe is used to determine the truth valuation of frame terms.
Bags (multi-sets) are used here because the order of the attribute/value pairs in a frame is immaterial and pairs may repeat: o[a->b a->b]. Such repetitions arise naturally when variables are instantiated with constants. For instance, o[?A->?B ?C->?D] becomes o[a->b a->b] if variables ?A and ?C are instantiated with the symbol a and ?B, ?D with b.
The operator ## is required to be transitive, i.e., c1 ## c2 and c2 ## c3 must imply c1 ## c3. This is ensured by a restriction in Section Interpretation of Formulas.
The relationships # and ## are required to have the usual property that all members of a subclass are also members of the superclass, i.e., o # cl and cl ## scl must imply o # scl. This is ensured by a restriction in Section Interpretation of Formulas.
It gives meaning to the equality operator.
It is used to define truth valuation for formulas.
For every external schema, σ, associated with the language, Iexternal(σ) is assumed to be specified externally in some document (hence the name external schema). In particular, if σ is a schema of a RIF built-in predicate or function, Iexternal(σ) is specified in [RIF-DTB] so that:
For convenience, we also define the following mapping I from terms to D:
Here {...} denotes a bag of attribute/value pairs.
Note that, by definition, External(t) is well-formed only if t is an instance of an external schema. Furthermore, by the definition of coherent sets of external schemas, t can be an instance of at most one such schema, so I(External(t)) is well-defined.
The effect of datatypes. The set DTS must include the datatypes described in Section Primitive Datatypes of [RIF-DTB].
The datatype identifiers in DTS impose the following
restrictions. Given dt ∈ DTS, let
LSdt denote the lexical space of
dt, VSdt denote its value
space, and Ldt:
LSdt → VSdt the
lexical-to-value-space mapping (for the definitions of these
concepts, see Section Primitive Datatypes of [RIF-DTB]. Then the following must hold:
That is, IC must map the constants of a datatype dt in accordance with Ldt.
RIF-PRD does not impose restrictions on IC for constants in symbol spaces that are not datatypes included in DTS. ☐
Editor's Note: The operational semantics of actions in RIF-PRD is still under discussion (see ISSUE-66). It will evolve as the semantics to be associated with the actions that are already specified is refined, in particular with respect to the creation and delation of objects; and as new ACTION constructs are added. The working group seeks feedback regarding what operational semantics would be most usefully associated with RIF-PRD ACTION constructs.
Let The transition relation →RIF-PRD ⊆ P(W) × L × P(W) is defined as follows:
Rule 1 specifies that the Assert construct should be used
when the intended action is to add a fact to a set of ground facts
w. Rule 2 specifies that the Retract construct
should be used when the intended action is to remove a fact from
w, instead.
The intended semantics of the actions that can be represented in
RIF-PRD is completely specified by the definition of the labelled
transition system {P(W), L,
→RIF-PRD}.
The relation →*RIF-PRD ⊆
P(W) × S(L) × P(W) denote the transitive
closure of the transition relation
→RIF-PRD.
A RIF-PRD production rule system is defined as a labelled terminal transition system: given a rule set RS ⊆ R, let CRS ⊆ P(W) × P(Inst(RS)) be a set of configurations, where a configuration is a pair c = (w, ric), such that w ⊆ W is a set of facts, and ric ∈ P(Inst(RS)) is an instance of RS. Given a configuration c = (w, ric), let facts(c) denote the first element, the set of facts w; and let instance(c) denote the second element, the ruleset instance, ric.
The idea is that a configuration, c, is made of a set, w, of ground FORMULAe that represent a state of facts; and the set, ric, of all the instances of the rules in the considered ruleset RS that are satisfied, in some sense to be further specified, in that state of facts.
Let further assume three functions:
Let extractActions: S(Inst(R)) → S(L), be a helper function that, given an ordered set, ori, of rule instances, returns the sequence of ACTIONs that is the concatenation, preserving the order in ori, of the sequences of ground actions determined by each of the rule instances in ori.
Given a ruleset RS and a selection strategy LS, a RIF-PRD production rule system is defined as a labelled terminal transition system PRSRS,LS = {CRS, S(L), →RS, TRS}, where :
Intuitively, the conditions 1 in the definition of the transition relation →RS guarantees that only the specification of the function PICK and the selection strategy determine which are the allowed transition paths out of a given configuration, and condition 2 guarantees that all transitions are compliant with the semantics of the individual actions, as specified the relation →RIF-PRD. Condition 3 guarantees that the instance component of any reachable configuration contains all the instances of the rules in RS that are satisfied in the configuration's state of facts, in the sense that is determined by the specification of the function INSTANTIATE, and only those instances. And condition 4 guarantees that the system halts as soon as it encounters a terminal configuration.
The input function is defined as:Or, using →*RS to denote the transitive closure of the transition relation:
Given the specification of PRSRS,LS, the intended operational semantics of a production ruleset represented by a RIF-PRD RuleSet RS is completely specified by the specification of the three functions INSTANTIATE, PICK and FINAL.
The evaluation of the function INSTANTIATE corresponds to the step that is often called matching in the description of production rule systems (e.g. PRR07). Given a collection of rules, it considers all possible ground rule instances, obtained by assigning ground terms to the variables occuring in them. Its semantics is defined in accordance with the semantics of the condition language of the RIF logic framework in terms of assignment into the universe of a structure of the PRD language and a satisfaction relation for instantiated rules.
Definition (Assignment): Let PRD be the language of
PRD, Var its countable set of variables, and I a
structure for PRD. An assignment is a function σ from
Var (or a subset of Var) into the universe of
I. The assignmment function is given by a ground
substitution as defined below.
In PRD the assignment function additionally needs to consider the binding patterns defined by the FORALL quantifier, that is it assigns a value to each variable in such a way all constraints imposed by the binding patterns are satisfied by these values. Such an assignment is called consistent.
Definition (Consistent Assignment): Let Var be a set
of variables, D the non-empty domain of possible values for
the variables, P the set of binding patterns, and C
as set of constraints. Each constraint Ci ∈ C
involves the set of variables X ⊆ Var from a binding pattern
Pi ∈ P and specifies the allowable combinations
of assigned values Pi[σ]. An assignment σ: Var
-> D satisfies a constraint Ci iff ∀
Xj ∈ X ⊆ Var: σ(Xj) ∈ Pi[σ].
An assignment that satisfies all constraints C is called a
consistent assignment.
For assigning terms to variables a substitution is defined as follows (e.g. HAK07):
Definition (substitution): A substitution is a finitely non-identical assignment of terms to variables; i.e., a function σ from Var to Term such that the set {x ∈ Var | x ≠ σ(x)} is finite. This set is called the domain of σ and denoted by Dom(σ). Such a substitution is also written as a set such as σ = {ti/xi}i=1..n where Dom(σ) = {xi}i=1..n and σ(xi) = ti for i = 1 to n.
Given X, a set of variables, and σ, a substitution such that X ⊆ Dom(σ), σX denotes, in this document, the restriction of σ to the variables in X: σX = {σ(x)/x | x ∈ X}.
Let TermΣ be the set of ground terms (that can be represented in RIF-PRD), defined as follows:
Definition (ground substitution): A ground substitution is a substitution σ such that ∀ x ∈ Dom(σ), σ(x) ∈ TermΣ.
The function Var(e) that maps a RIF-PRD element e to the set of its free or universally quantified variables is defined as follows:
Definition (Satisfaction): A RIF-PRD Formula
φ is satisfied (is true) in the structure I of
PRD under assignment σ, written as I |= φ[σ],
if there is an consistent assignment σ to I. The
inductive requirements of the satisfaction relation |=
are:
Editor's Note: Note, that :- might change to =>
Definition (Pattern Matching): Given a set w ⊆
W of ground RIF-PRD ATOMICs and a RIF-PRD
FORMULA φ, φ is said to match
w and an assignment σ, iff I |=
φ[σ(w)].
All possible instantiation of a RIF-PRD formula φ are obtained by substituting each variable ?Xi ∈ Var of φ with the value of σ(?Xi) from the matching facts w ∈ W.
Editor's Note: This section is still under discussion (see ISSUE-64). This version of RIF-PRD specifies five elementary strategies, a way of combining them, and a default combination. Future working drafts may specify different and/or additional elementary strategies, and no or a different default. The Working Group seeks feedback on which instances selection strategies and which combinations of strategies should be supported by RIF-PRD and/or required from RIF-PRD implementations; and which strategy or combination should be the default, if any.
A rule instance determines a sequences of ground actions, by application of the associated substitution to the variables in the ACTIONs in the then component of the instantiated rule. The decision to implement the sequence of actions that a rule instance determines is often called: firing the rule instance.
Most implementations of production rule languages select the rule instances to be fired, and, therefore, the sequence of actions to be implemented, based on one or a combination of the following strategies (under these or other, idiosyncratic names; and possibly combined with additional, idiosyncratic rules):
Let fireableINSTANCES: S(Inst(R)) × P(Inst(R)) × {no-repeat, priority, recency, random, all} → S(Inst(R)) be a function that, given an ordered set, ori, of candidate rule instances, a set, h, of excluded rule instances, and a keyword, k, indicative of an single selection strategy, return a subset fri ⊆ ori, selected and ordered according to the strategy indicated by k. The keywords "no-repeat"" and "all" indicate, respectively, the no-repetition and all-at-once selection strategies, and the other keywords indicate each the strategy by the same name.
The function fireableINSTANCES is precisely specified in the next subsection.
The function PICK(c, LS) can be specified with the help of a terminal transition system where:
Intuitively, the strategy for the selection of the rule instances to be fired that is intended for the set of rules represented by a RIF-PRD Ruleset, is :
The operational semantics of the function fireableINSTANCES depends on its third argument, the elementary selection strategy. It is therefore specified separately for each value of that parameter, that is, for each individual rule instances selection strategy supported by RIF-PRD.
Editor's Note: The precise operational semantics of the "no-repetition", "priority" and "recency" strategies are still under discussion in the working group. In addition, this working draft does not specify a way to specify the intended instance selection strategy for a RIF-PRD ruleset in a RIF document. As a consequence, only the "random" strategy is precisely specified in this version.
No-Repetition. TBD
Priority. TBD
Recency. TBD
Random. fireableINSTANCES(ori, h, "random"), where ori ∈ S(Inst(R)) and h ∈ P(Inst(R)), returns a randomly selected singleton subset of ori:Editor's Note: This section is still under discussion (see ISSUE-65). This version specifies a single, default halting test: future version of this draft may specify additional halting tests, and/or a different default. The Working Group seeks feedback on which halting tests and which combinations of tests should be supported by RIF-PRD and/or required from RIF-PRD implementations; and which halting test should be the default, if any.
By default, the specification for a terminal configuration that is intended for a set of production rules, when no halting test is explicitely associated to its representation as a RIF-PRD Ruleset, is when no rule instance is fireable: this is the case when INSTANTIATE returns an empty set of rule instances, or when all the rule instances that are satisfied in the configuration, according to the semantics of INSTANTIATE, have already been fired in a configuration that has not since changed significantly. That latter condition guarantees, in particular, that the system halts when it reaches a fixpoint.
Formally, ∀ RS ⊆ R, ∀ c ∈ CRS, PICK(c, RS) = true if and only if instance(c) - history(c) = ∅. Otherwise, PICK(c, RS) = false.
TBD
RIF-PRD and RIF-BLD share essentially the same presentation syntax and XML syntax.
The syntactic differences between the two dialects are summarized below:
Below is a complete, construct by construct, comparison table of RIF-PRD and RIF-BLD presentation and XML syntaxes. A construct is tagged "BLD" or "PRD" if it is specific to the dialect, or tagged "Core" if it is common to both.
Editor's Note: RIF-Core will be equal to or included in the intersection of RIF-PRD and RIF-BLD. The exact scope of RIF-Core is still under discussion. Until RIF-Core is specified more precisely, this document assumes that it will be equal to the intersection of RIF-PRD and RIF-BLD.
Presentation syntax | XML syntax | |
---|---|---|
TERM ::= | ||
BLD |
[Const | Var | Expr | External] |
|
PRD |
[Const | Var | External] |
|
Const ::= | ||
Core |
'"' UNICODESTRING '"^^' SYMSPACE |
<Const type=xsd:anyURI [xml:lang=xsd:language]? > Any Unicode string </Const> |
Var ::= | ||
Core |
'?' Any Unicode string |
<Var> Any Unicode string </Var> |
Expr ::= | ||
BLD |
Const '(' (TERM* | (Name '->' TERM)*) ')' |
<Expr> <op> Const </op> [ <args rif:ordered="yes"> TERM* </args>? | <slot rif:ordered="yes"> <Name> Any Unicode string </Name> TERM </slot>* ] </Expr> |
PRD |
Undefined except when wrapped in an External (as TERM), as follows. |
|
External (as TERM) ::= | ||
Core |
'External' '(' Expr ')' |
<External> <content> Expr </content> </External> |
ATOMIC ::= | ||
Core |
[Atom | Equal | Member | Subclass | Frame] |
|
Atom ::= | ||
Core |
Const '(' (TERM* | (Name '->' TERM)*) ')' |
<Atom> <op> Const </op> [ <args rif:ordered="yes"> TERM* </args>? | <slot rif:ordered="yes"> <Name> Any Unicode string </Name> TERM </slot>* ] </Atom> |
Equal ::= | ||
Core |
TERM = TERM |
<Equal> <left> TERM </left> <right> TERM </right> </Equal> |
Member ::= | ||
Core |
TERM # TERM |
<Member> <instance> TERM </instance> <class> TERM </class> </Member> |
Subclass ::= | ||
Core |
TERM ## TERM |
<Subclass> <sub> TERM </sub> <super> TERM </super> </Subclass> |
Frame ::= | ||
Core |
TERM ' [ ' (TERM ' -> ' TERM)* ' ] ' |
<Frame> <object> TERM </object> <slot rif:ordered="yes"> TERM TERM </slot>* </Frame> |
FORMULA ::= | ||
BLD |
[ATOMIC | External | And | Or | Exists] |
|
PRD |
[ATOMIC | External | And | Or | NmNot | Exists] |
|
External (as FORMULA) ::= | ||
Core |
'External '(' [Atom | Frame] ')' |
<External> <content> [ Atom | Frame ] </content> </External> |
And ::= | ||
Core |
'And' '(' FORMULA* ')' |
<And> <formula> FORMULA </formula>* </And> |
Or ::= | ||
Core |
'Or' '(' FORMULA* ')' |
<Or> <formula> FORMULA </formula>* </Or> |
NmNot ::= | ||
BLD |
Undefined |
|
PRD |
'Not' '(' FORMULA ')' |
<NmNot> <formula> FORMULA </formula> </NmNot> |
Exists ::= | ||
Core |
'Exists' Var+ '(' FORMULA ')' |
<Exists> <declare> Var </declare>+ <formula> FORMULA </formula> </Exists> |
ACTION ::= | ||
BLD |
Undefined |
|
PRD |
[ ASSERT | Retract ] |
|
ASSERT ::= | ||
BLD |
Undefined |
|
PRD |
[ Atom | Frame ] |
|
Retract ::= | ||
BLD |
Undefined |
|
PRD |
'Retract' '(' Atom | Frame ' ) ' |
<Retract> <target> [ Atom | Frame ] </target> </Retract> |
RULE ::= | ||
BLD |
[ Forall | Implies | ATOMIC ] |
|
PRD |
[ Forall | Implies | ACTION ] |
|
Forall ::= | ||
BLD |
' Forall ' Var+ ' ( ' [Implies | ATOMIC] ' ) ' |
<Forall> <declare> Var </declare>+ <formula> [Implies | ATOMIC ] </formula> </Forall> |
PRD |
' Forall ' Var+ (' ( ' FORMULA ' ) ')* ' ( ' RULE ' ) ' |
<Forall> <declare> Var </declare>+ <pattern> FORMULA </pattern>* <formula> RULE </formula> </Forall> |
Implies ::= | ||
BLD |
(ATOMIC | 'And' '(' ATOMIC* ')') ':-' FORMULA |
<Implies> <if> FORMULA </if> <then> [ ATOMIC | <And> <formula> ATOMIC </formula>* </And> ] </then> </Implies> |
PRD |
(ACTION | 'Do' '(' ACTION* ')') ':-' FORMULA |
<Implies> <if> FORMULA </if> <then> ACTION ACTION* </then> </Implies> |
Group ::= | ||
Core |
METADATA? 'Group' '(' ([RULE | Group])* ')' |
<Group> <sentence> [ RULE | Group ] </sentence>* </Group> |
Import ::= | ||
BLD |
'Import' '(' IRI Profile? ')' |
<Import> <location>lAny Unicode string</location> <profile><Profile>Any Unicode String1</Profile></profile> </Import> |
PRD |
Undefined in this version of the draft |
|
Document ::= | ||
BLD |
METADATA? 'Document' '(' [Import | Prefix | Base]* Group? ')' |
<Document> <directive> [ Import | Prefix | Base]* </directive> <payload> Group </payload>? </Document> |
PRD |
METADATA? 'Document' '(' Group? ')' |
<Document> <payload> Group </payload>? </Document> |
METADATA ::= | ||
Core |
'(*' Const? (Frame | 'And' '(' Frame* ')')? '*)' |
<AnyClassTag> <id> Const </declare>? <meta> [ Frame | <And> <formula> Frame </formula> </And> ] </meta>? other content of AnyClassTag </AnyClassTag> |
The intended semantics of any RIF XML document which is both a syntactically valid RIF-PRD document and a syntactically valid RIF-BLD document is the same whether it is considered a RIF-PRD or a RIF-BLD document. For any input set of facts, the set of rules contained in the document must produce the same output set of facts whether it is consumed as a RIF-PRD or a RIF-BLD document.
Proof. TBC
The picture below represents the complete syntax of RIF-PRD, according to this version of the draft, except for the Metadata construct, which is omitted for readibility's sake.