<?xml version="1.0" encoding="UTF-8"?>

<!-- An XML Schema for a Datalog RuleML Sublanguage: Monolith Version -->
<!-- Last Modification: 2001-09-25 -->



<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">


<!-- Top-level element Declaration -->

<!-- 'rulebase' root element uses 'imp' rules and 'fact' assertions as top-level elements -->

  <xsd:element name="rulebase">
    <xsd:complexType>
      <xsd:choice minOccurs="0" maxOccurs="unbounded">
	<xsd:element name="imp" type="impType"/>
        <xsd:element name="fact" type="factType"/>
      </xsd:choice>
    </xsd:complexType>
  </xsd:element>


<!-- complexType Definitions -->


<!-- 'imp' rules are usable as general implications on the top-level -->
<!-- 'imp' element uses a conclusion role _head followed by a premise role _body, or equivalently -->
<!-- (since roles constitute unordered elements), uses a premise role _body followed by a conclusion role _head -->
<!-- "<imp>_head _body</imp>" stands for "_head is implied by _body", i.e., "_head is true is implied by _body is true", or equivalently, -->
<!-- "<imp>_body _head</imp>" stands for "_body implies _head", i.e., "_body is true implies _head is true" -->

  <xsd:complexType name="impType">
    <xsd:all>
      <xsd:element name="_head" type="_headType"
                   minOccurs="1" maxOccurs="1"/>
      <xsd:element name="_body" type="_bodyType"
                   minOccurs="1" maxOccurs="1"/>
    </xsd:all>
  </xsd:complexType>


<!-- 'fact' assertions are usable as degenerate rules on the top-level -->
<!-- 'fact' element uses just a conclusion role _head -->
<!-- "<fact>_head</fact>" stands for "_head is implied by true", i.e., "_head is true" -->

  <xsd:complexType name="factType">
    <xsd:sequence>
      <xsd:element name="_head" type="_headType"/>
    </xsd:sequence>
  </xsd:complexType>


<!-- _head role is usable within 'imp' rules and 'fact' assertions -->
<!-- _body role is usable within 'imp' rules -->
<!-- _head uses an atomic formula -->
<!-- _body uses an atomic formula or an 'and' -->

  <xsd:complexType name="_headType">
    <xsd:sequence>
      <xsd:element name="atom" type="atomType"/>
    </xsd:sequence>
  </xsd:complexType>

  <xsd:complexType name="_bodyType">
    <xsd:choice>
      <xsd:element name="atom" type="atomType"/>
      <xsd:element name="and" type="andType"/>
    </xsd:choice>
  </xsd:complexType>

 
<!-- an 'and' is usable within _body's -->
<!-- 'and' uses zero or more atomic formulas -->
<!-- "<and>atom</and>" is equivalent to "atom"-->
<!-- "<and></and>" is equivalent to "true"-->

  <xsd:complexType name="andType">
    <xsd:sequence>
      <xsd:element name="atom" type="atomType" minOccurs="0" maxOccurs="unbounded"/>
    </xsd:sequence>
  </xsd:complexType>
 
 
<!-- atomic formulas are usable within _head's, _body's, and 'and's -->
<!-- atom element uses an: -->
<!-- _opr ("operator of relations") role followed by a sequence of zero or more arguments, or similarly -->
<!-- (since roles constitute unordered elements, and the zero-argument case must not cause ambiguity), -->
<!-- a sequence of one or more arguments followed by an _opr role -->
<!-- the arguments may be ind(ividual)s or var(iable)s -->

<!-- Since xsd:all groups don't permit complex content, the following is not permitted ...

  <xsd:complexType name="atomType">
    <xsd:all>
      <xsd:element name="_opr" type="_oprType"
                   minOccurs="1" maxOccurs="1"/>
      <xsd:sequence minOccurs="1" maxOccurs="1">
        <xsd:choice minOccurs="0" maxOccurs="unbounded">
	  <xsd:element name="ind" type="indType"/>
	  <xsd:element name="var" type="varType"/>
        </xsd:choice>
      </xsd:sequence>
    </xsd:all>
  </xsd:complexType>

... hence must be circumscribed via xsd:choice, like in DTDs: -->


  <xsd:complexType name="atomType">
    <xsd:choice>
      <xsd:sequence>
        <xsd:element name="_opr" type="_oprType"/>
        <xsd:choice minOccurs="0" maxOccurs="unbounded">
          <xsd:element name="ind" type="indType"/>
          <xsd:element name="var" type="varType"/>
        </xsd:choice>
      </xsd:sequence>
      <xsd:sequence>
        <xsd:choice maxOccurs="unbounded">
          <xsd:element name="ind" type="indType"/>
          <xsd:element name="var" type="varType"/>
        </xsd:choice>
        <xsd:element name="_opr" type="_oprType"/>
      </xsd:sequence>
    </xsd:choice>
  </xsd:complexType>


<!-- _opr is usable within atoms -->
<!-- _opr uses rel(ation) symbol -->

  <xsd:complexType name="_oprType">
    <xsd:sequence>
      <xsd:element name="rel" type="relType"/>
    </xsd:sequence>
  </xsd:complexType>


<!-- simpleType Definitions -->


<!-- there is one kind of fixed argument -->
 
<!-- individual constant, as in predicate logic -->

  <xsd:simpleType name="indType">
    <xsd:restriction base="xsd:string">
    </xsd:restriction>
  </xsd:simpleType>
 
 
<!-- there is one kind of variable argument -->
 
<!-- logical variable, as in logic programming -->

  <xsd:simpleType name="varType">
    <xsd:restriction base="xsd:string">
    </xsd:restriction>
  </xsd:simpleType>
 
 
<!-- there are only fixed (first-order) relations -->
 
<!-- relation or predicate symbol -->

  <xsd:simpleType name="relType">
    <xsd:restriction base="xsd:string">
    </xsd:restriction>
  </xsd:simpleType>


</xsd:schema>

