RuleML Systematics

From RuleML Wiki
Jump to: navigation, search

This design document systematically develops central RuleML features using independent ('orthogonal') dimensions. It starts with basic Derivation RuleML features @@@although doesn't show yet a complete derivation rule@@@ and proceeds to Reaction RuleML features.


1 Dimensions of Operation Calls

Five dimensions characteristic of RuleML operation calls (queries, goals) will be distinguished:

  • Unanchored vs. Anchored
  • Atom vs. Expr
  • Copy vs. Value vs. Effect
  • Positional vs. Slotted
  • Locally Defined vs. Imported/Builtin

We assume readers are already familiar with local vs. global individuals such as, respectively, in <Ind>John</Ind> vs. <Ind iri="http://example.inst#John/>, both used either as normal call arguments or as OIDs.

These dimensions are orthogonal, hence freely combinable in a design space of modular building blocks.

@@@This initial presentation is example-driven@@@

@@@Replaced 'in' (interpreted) attribute with a 'per' attribute:

in="no" --> per="plain" --> per="copy"

(in="semi" --> per="open" -TBD-> per="avail")

in="yes" --> per="value"

in="pure" --> per="value"

in="effect" --> per="effect" @@@

@@@val="1" vs. val="0.." (if not further refined as in val="2", val="0..1", etc.) could perhaps be combined with per: copy | avail | value (val="1") | set (val="0..") while per effect would be in a separate dimension relevant for per non-copy.@@@

1.1 Unanchored vs. Anchored

1.1.1 Unanchored

Example:

<Atom>
  <Rel per="value">profile</Rel>
  <Ind>John</Ind>
  <Ind>gold</Ind>
</Atom>

This Atom returns true if it is derivable that the profile status of John is gold, returns false if it is derivable that John's profile status is not gold, and otherwise fails.

Example:

<Expr>
  <Fun per="value">salary</Fun>
  <Ind>Sue</Ind>
</Expr>

This Expr returns x (say, 100000) if it is derivable that the salary of Sue is x, otherwise fails.


1.1.2 Anchored

Example:

<Atom>
  <Rel per="value">profile</Rel>
  <oid><Ind>John</Ind></oid>
  <Ind>gold</Ind>
</Atom>

This Atom returns true if it is derivable that object/agent John's profile status is gold, returns false if it is derivable that John's profile status is not gold, and otherwise fails.

Example:

<Expr>
  <Fun per="value">salary</Fun>
  <oid><Ind>Sue</Ind></oid>
</Expr>

This Expr returns x (say, 100000) if it is derivable that object/agent Sue's salary is x, otherwise fails.


1.2 Atom vs. Expr

1.2.1 Atom

Example:

<Atom>
  <Rel per="value">buy</Rel>
  <Ind>John</Ind>
  <Ind>Mary</Ind>
  <Ind>Honda</Ind>
</Atom>

This Atom returns true if it is derivable that John buys a Honda from Mary, returns false if it can be derived that John does not buy a Honda from Mary, and otherwise fails.

The following example is a pure version of commands similar to those in [1].

Example:

<Atom>
  <Rel per="value">put</Rel>
  <oid><Ind>SHRDLU</Ind></oid>
  <Ind>SUPERBLOCK</Ind>
  <Ind>BOX</Ind>
</Atom>

This Atom returns true if it is derivable that object/agent SHRDLU can put the SUPERBLOCK into the BOX, returns false if it is derivable that SHRDLU cannot put the SUPERBLOCK into the BOX, and otherwise fails.


1.2.2 Expr

Example:

<Expr>
  <Fun per="value">mother</Fun>
  <Ind>Sue</Ind>
</Expr>

This Expr returns x (say, Mary) if it is derivable that x is the mother of Sue, otherwise fails.

The following example is a pure version of commands similar to those in [2].

Example:

<Expr>
  <Fun per="value">pop</Fun>
  <oid><Ind>SHRDLU</Ind></oid>
  <Ind>TOWER</Ind>
</Expr>

This Expr returns x (say, SUPERBLOCK) if it is derivable that object/agent SHRDLU can pop x from the TOWER, otherwise fails.


1.3 Copy vs. Value vs. Effect

A Rel or Fun per "copy" is left uninterpreted, per "value" is interpreted purely for its value, and per "effect" is interpreted impurely both for its value and its (side-)effect action, as needed for (E)CA rules in Production and Reaction RuleML.


1.4 Copy

Example:

<Atom>
  <Rel per="copy">profile</Rel>
  <Ind>John</Ind>
  <Ind>gold</Ind>
</Atom>

This Atom just returns itself.

Example:

<Expr>
  <Fun per="copy">salary</Fun>
  <Ind>Sue</Ind>
</Expr>

This Expr just returns itself, realizing an uninterpreted salary function.


1.4.1 Value

Example:

<Atom>
  <Rel per="value">profile</Rel>
  <Ind>John</Ind>
  <Ind>gold</Ind>
</Atom>

This Atom returns true if it is derivable that the profile status of John is gold, returns false if it is derivable that John's status is not gold, and otherwise fails.

Example:

<Expr>
  <Fun per="value">salary</Fun>
  <Ind>Sue</Ind>
</Expr>

This Expr returns x (say, 100000) if it is derivable that the salary of Sue is x, otherwise fails.


1.4.2 Effect

Example:

<Atom>
  <Rel per="effect">update</Rel>
  <Ind>John</Ind>
  <Ind>gold</Ind>
</Atom>

This Atom returns true if John's status can be successfully updated to gold, returns false if it is derivable that John's status cannot be updated to gold, and otherwise fails.

Example:

<Expr>
  <Fun per="effect">promote</Fun>
  <Ind>Sue</Ind>
</Expr>

This Expr returns x (say, 100000) if Sue can be successfully promoted to new salary x, otherwise fails.

Complementing the earlier pure SHRDLU versions, the following examples use effectful versions of commands similar to those in [3].

Example:

<Atom>
  <Rel per="effect">put</Rel>
  <oid><Ind>SHRDLU</Ind></oid>
  <Ind>SUPERBLOCK</Ind>
  <Ind>BOX</Ind>
</Atom>

This Atom returns true if object/agent SHRDLU can successfully put the SUPERBLOCK into the BOX, returns false if it is derivable that SHRDLU cannot put the SUPERBLOCK into the BOX, and otherwise fails.

Example:

<Expr>
  <Fun per="effect">pop</Fun>
  <oid><Ind>SHRDLU</Ind></oid>
  <Ind>TOWER</Ind>
</Expr>

This Expr returns x (say, SUPERBLOCK) if object/agent SHRDLU can successfully pop x from the TOWER, otherwise fails.


1.5 Positional vs. Slotted

1.5.1 Positional

Example:

<Atom>
  <Rel per="value">profile</Rel>
  <Ind>John</Ind>
  <Ind>gold</Ind>
</Atom>

This Atom returns true if it is derivable that the profile status of John is gold, returns false if it is derivable that John's profile status is not gold, and otherwise fails.


1.6 Slotted

Example:

<Atom>
  <Rel per="value">profile</Rel>
  <slot><Ind>customer</Ind><Ind>John</Ind></slot>
  <slot><Ind>status</Ind><Ind>gold</Ind></slot>
</Atom>

This Atom returns true if it is derivable that the profile status slot of customer=John slot is gold, returns false if it is derivable that customer John's profile status slot is not gold, and otherwise fails.


1.7 Locally Defined vs. Imported/Builtin

1.7.1 Locally Defined

All previous calls used symbolic names assuming operations are locally defined.

For instance,

Example:

<Atom>
  <Rel per="value">profile</Rel>
  <Ind>John</Ind>
  <Ind>gold</Ind>
</Atom>

and

Example:

<Expr>
  <Fun per="value">salary</Fun>
  <Ind>Sue</Ind>
</Expr>

assume that the symbolic names profile and salary are locally defined, e.g. by a fact and an equation, respectively.


1.7.2 Imported/Builtin

Calls can also import globally defined operations by omitting the symbolic names (leaving empty elements) and instead referencing other rulesets or builtin libraries (giving the empty elements an iri attribute). Call syntax is agnostic about whether such external operations are rules or builtins, hence calls do not need to change when rules are being replaced with (e.g. 'compiled' into) builtins as long as their iri names do not change.

Example:

<Atom>
  <Rel per="value" iri="http://example.dec#test"/>
  <Ind>John</Ind>
  <Ind>gold</Ind>
</Atom>
Example:

<Expr>
  <Fun per="value" iri="http://example.dec#wage"/>
  <Ind>Sue</Ind>
</Expr>
Example:

<Atom>
  <Rel per="value" iri="http://example.dec#test"/>
  <oid><Ind>John</Ind></oid>
  <slot><Ind>status</Ind><Ind>gold</Ind></slot>
</Atom>
Example:

<Expr>
  <Fun per="value" iri="http://example.dec#wage"/>
  <oid><Ind iri="http://example.inst#Sue/></oid>
</Expr>
Example:

<Atom>
  <Rel per="effect" iri="http://example.imp#renew"/>
  <Ind>John</Ind>
  <Ind>gold</Ind>
</Atom>
Example:

<Atom>
  <Rel per="effect" iri="http://example.imp#renew"/>
  <oid><Ind iri="http://example.inst#John/></oid>
  <slot>
    <Ind iri="http://example.prop#status"/>
    <Ind iri="http://en.wikipedia.org/wiki/Gold"/>
  </slot>
</Atom>



2 Performatives as Builtins

The basic performatives Assert and Retract are focused here, but other ones (incl. Update, Setter) can be added via a user-level extension mechanism.

@@@Need Atom in Atom be 'quoted' as in Fun RuleML?@@@


2.1 Assert

The former

<Assert>
  ...
</Assert>

can now be written as

<Atom>
  <Rel per="effect" iri="http://www.ruleml.org/builtins#assert"/>
  ...
</Atom>

or as

...
rulemlb="http://www.ruleml.org/builtins#"
...
<Atom>
  <Rel per="effect" iri="rulemlb:assert"/>
  ...
</Atom>


Example:

<Atom>
  <Rel per="effect" iri="http://www.ruleml.org/builtins#assert"/>
  <Atom>
    <Rel per="value">profile</Rel>
    <Ind>John</Ind>
    <Ind>gold</Ind>
  </Atom>
</Atom>

or

Example:

...
rulemlb="http://www.ruleml.org/builtins#"
...
<Atom>
  <Rel per="effect" iri="rulemlb:assert"/>
  <Atom>
    <Rel per="value">profile</Rel>
    <Ind>John</Ind>
    <Ind>gold</Ind>
  </Atom>
</Atom>

This asserts a clause defining the profile status of John as gold.

Users can specify their assert variants in their own namespaces, e.g. on top of the above rulemlb:assert. Instead of being a Rel, a user assert can also be a Fun returning values more specific than true or false.

Suppose an assert function in user namespace ex only performs a rulemlb:assert of a fact if this is not already defined, otherwise just returns the value 'redundant'. After the above rulemlb:assert call, the following ex:assert call would then return that value.

Example:

<Expr>
  <Fun per="effect" iri="ex:assert"/>
  <Atom>
    <Rel per="value">profile</Rel>
    <Ind>John</Ind>
    <Ind>gold</Ind>
  </Atom>
</Expr>


2.2 Retract

The former

<Retract>
  ...
</Retract>

can now be written as

<Atom>
  <Rel per="effect" iri="http://www.ruleml.org/builtins#retract"/>
  ...
</Atom>

or as

...
rulemlb="http://www.ruleml.org/builtins#"
...
<Atom>
  <Rel per="effect" iri="rulemlb:retract"/>
  ...
</Atom>



3 CA Rules

@@@order attribute in <And> not yet introduced@@@

@@@Would per="effect" be required also in <And>?@@@

Example:

...
rulemlb="http://www.ruleml.org/builtins#"
...

<Rule kind="ca" ...>  <!-- formerly <Production> -->
  <if>
    <And>
      <Atom>
        <Rel per="value">profile</Rel>
        <Var>P</Var>
        <Ind>silver</Ind>
      </Atom>
      <Atom>
        <Rel iri="rulemlb:greaterThan"/>
        <Expr>
          <Fun per="value">spending</Fun>
          <Var>P</Var>
        </Expr>
        <Data>1000</Data>
      </Atom>
    </And>
  </if>
  <do>
    <And order="sequential">  <!--  transaction as implicit on top-level of <RuleML> -->
      <Atom>
        <Rel per="effect" iri="rulemlb:retract"/>
        <Atom>
          <Rel per="value">profile</Rel>
          <Var>P</Var>
          <Ind>silver</Ind>
        </Atom>
      </Atom>
      <Atom>
        <Rel per="effect" iri="rulemlb:assert"/>
        <Atom>
          <Rel per="value">profile</Rel>
          <Var>P</Var>
          <Ind>gold</Ind>
        </Atom>
      </Atom>
    </And>
  </do>
</Rule>



4 Global Variables

Global variables can be represented as Atoms by regaring a global variable name as the OID for anchoring the Atom and regaring a variable value as the only (positional) argument of that Atom (the Atom does not need a Relation, but could have a dummy Relation such as gloval). To assign a new value to a global variable, we can (1) retract the Atom with that variable name and whatever value and (2) assert an Atom with the same variable name and the new value. Generally, name:=value can be stored as the Atom (name^value) or gloval(name^value), where "^" separates an OID from the arguments. For example, N:=8 can be stored as the Atom (N^8) or gloval(N^8). To assign a new value, as in N:=9, we can retract (N^8) or gloval(N^8) and assert (N^9) or gloval(N^9). Assign can be defined as a user-level performative exhibiting this reassignment effect as shown below. Note that this is a Conclusion-Action rule called 'top-down'/'backward' through the effectful assign Relation in the <then> part.

Example:


<Rule kind="conca" ...>  <!--  conclusion-action rule> -->
  <then>
    <Atom>
      <Rel per="effect">assign</Rel>
      <oid><Var>name</Var></oid>
      <Var>newvalue</Var>
    </Atom>
  </then>
  <do>
    <And order="sequential">
      <Atom>
        <Rel per="effect" iri="rulemlb:retract"/>
        <Atom>
          <oid><Var>name</Var></oid>
          <Var>oldvalue</Var>
        </Atom>
      </Atom>
      <Atom>
        <Rel per="effect" iri="rulemlb:assert"/>
        <Atom>
          <oid><Var>name</Var></oid>
          <Var>newvalue</Var>
        </Atom>
      </Atom>
    </And>
  </do>
</Rule>

To effect the above N:=9 reassignment, we would call it thus:

Example:

<Atom>
  <Rel per="effect">assign</Rel>
  <oid><Ind>N</Ind></oid>
  <Ind>9</Ind>
</Atom>

This call unifies with the <then> part of the assign-defining rule, binding the logic variable name to the global variable <Ind>N</Ind>. In the <do> part of the rule, name is dereferenced to <Ind>N</Ind>.

If the assign-defining rule is made available as a RuleML builtin, it can called from everywhere as shown for the same reassignment below.

Example:

...
rulemlb="http://www.ruleml.org/builtins#"
...

<Atom>
  <Rel per="effect" iri="rulemlb:assign"/>
  <oid><Ind>N</Ind></oid>
  <Ind>9</Ind>
</Atom>