<?xml version="1.0" encoding="utf-8"?>
<RuleML xmlns="http://ruleml.org/spec"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://ruleml.org/spec http://ruleml.org/1.0/xsd/datalog.xsd">

  <!-- start XML comment ...

Note: This is an expanded (i.e. normalized, including all role tags, canonical ordering and explicit attributes) version of this example.

This example rulebase contains four rules.
The first and second rules are implications; the third and fourth ones are facts.

In English:

The first rule implies that a person owns an object
if that person buys the object from a merchant and the person keeps the object.

As an OrdLab Tree:


Implies~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        |                                                                        |
        if~~                                                                    then~~         
           |                                                                         |
           And~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                              Atom~~~~~~~~~~~~~~~~             
                 |                                   |                                     |     |     |
               formula~~                           formula~~                               op~  arg~  arg~
                       |                                   |                                 |     |     |     
                      Atom~~~~~~~~~~~~~~~~~~~~~~~~        Atom~~~~~~~~~~~~~~~               Rel   Var   Var
                            |     |      |       |              |     |     |                .     .     .
                            op~  arg~   arg~    arg~            op~  arg~  arg~              .     .     .
                              |     |      |       |              |     |     |              .     .     .
                             Rel   Var    Var     Var            Rel   Var   Var            own  person object
                              .     .      .       .              .     .     . 
                              .     .      .       .              .     .     .
                             buy  person merchant object        keep  person object

... end XML comment -->
  <act index="1">
    <Assert mapClosure="universal">
      <formula>
        <Implies>
          <!-- explicit 'And' -->
          <if>
            <And>
              <formula>
                <Atom>
                  <op>
                    <Rel>buy</Rel>
                  </op>
                  <arg index="1">
                    <Var>person</Var>
                  </arg>
                  <arg index="2">
                    <Var>merchant</Var>
                  </arg>
                  <arg index="3">
                    <Var>object</Var>
                  </arg>
                </Atom>
              </formula>
              <formula>
                <Atom>
                  <op>
                    <Rel>keep</Rel>
                  </op>
                  <arg index="1">
                    <Var>person</Var>
                  </arg>
                  <arg index="2">
                    <Var>object</Var>
                  </arg>
                </Atom>
              </formula>
            </And>
          </if>
          <then>
            <Atom>
              <op>
                <Rel>own</Rel>
              </op>
              <arg index="1">
                <Var>person</Var>
              </arg>
              <arg index="2">
                <Var>object</Var>
              </arg>
            </Atom>
          </then>
        </Implies>
      </formula>
      <!-- The second rule implies that a person buys an object from a merchant
if the merchant sells the object to the person. -->
      <formula>
        <Implies>
          <if>
            <Atom>
              <op>
                <Rel>sell</Rel>
              </op>
              <arg index="1">
                <Var>merchant</Var>
              </arg>
              <arg index="2">
                <Var>person</Var>
              </arg>
              <arg index="3">
                <Var>object</Var>
              </arg>
            </Atom>
          </if>
          <then>
            <Atom>
              <op>
                <Rel>buy</Rel>
              </op>
              <arg index="1">
                <Var>person</Var>
              </arg>
              <arg index="2">
                <Var>merchant</Var>
              </arg>
              <arg index="3">
                <Var>object</Var>
              </arg>
            </Atom>
          </then>
        </Implies>
      </formula>
      <!-- The third rule is a fact that asserts that
John sells XMLBible to Mary. -->
      <formula>
        <Atom>
          <op>
            <Rel>sell</Rel>
          </op>
          <arg index="1">
            <Ind>John</Ind>
          </arg>
          <arg index="2">
            <Ind>Mary</Ind>
          </arg>
          <arg index="3">
            <Ind>XMLBible</Ind>
          </arg>
        </Atom>
      </formula>
      <!-- The fourth rule is a fact that asserts that
Mary keeps XMLBible.
 
Observe that this fact is binary - i.e., there are two arguments
for the relation. RDF viewed as a logical knowledge representation
is, likewise, binary, although its arguments have type restrictions,
e.g., the first must be a resource (basically, a URI). -->
      <formula>
        <Atom>
          <op>
            <Rel>keep</Rel>
          </op>
          <arg index="1">
            <Ind>Mary</Ind>
          </arg>
          <arg index="2">
            <Ind>XMLBible</Ind>
          </arg>
        </Atom>
      </formula>
    </Assert>
  </act>
</RuleML>

