<?xml version="1.0"?>

<xs:schema 
targetNamespace="http://www.ruleml.org/0.88/xsd"
xmlns="http://www.ruleml.org/0.88/xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
>

<!-- note that elementFormDefault is qualified because of the local declaration of And -->

	<xs:annotation>
		<xs:documentation xml:lang="en">
			Connective RuleML elements module.
			This is the XML Schema connectives module for RuleML.
			File: connective_module.xsd
			Version: 0.88
			Last Modification: 2005-02-24
			
			This module declares the following RuleML connectives:
			* Implies
			* body
			* head
			* Equivalent
			* torso
			* And (see the quantifier module for the "formula" role)
			* Or
			* formula			
			* @direction
			* @innerclose
			* @closure
			
			The approach is modelled after that used in "Modularization of XHTML in XML Schema"
			WD [http://www.w3.org/TR/xhtml-m12n-schema/], which will soon be integrated with
			"Modularization of XHTML" (REC-xhtml-modularization-20010410)
			[http://www.w3.org/TR/xhtml-modularization/].
		</xs:documentation>
	</xs:annotation>

	<!--
		*** Implies ***
		content model:
		( oid?, ( head, body) | ( body, head) | ( (Atom | And | Or), Atom ) )

		An implication rule.

		'Implies' rules are usable as general implications.  They use
		a conclusion role 'head' followed by a premise role 'body', or, equivalently
		(since roles constitute unordered elements), a premise role 'body'
		followed by a conclusion role 'head'.  These roles may also be omitted,
		the body coming first (Atom, Or or And) followed by the head (Atom).

		e.g.
		"<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".		
	-->
	<xs:attributeGroup name="Implies.attlist">
		<xs:attributeGroup ref="closure.attrib"/>
	</xs:attributeGroup>
	<xs:group name="Implies.content">
		<xs:sequence>
			<xs:choice minOccurs="0">
				<xs:element ref="oid"/>
			</xs:choice>	
			<xs:choice>
				<xs:sequence>
					<xs:element ref="head"/>
					<xs:element ref="body"/>
				</xs:sequence>
				<xs:sequence>
					<xs:element ref="body"/>
					<xs:element ref="head"/>
				</xs:sequence>			
				<xs:sequence>
					<xs:group ref="body.content"/>
					<xs:group ref="head.content"/>					
				</xs:sequence>
			</xs:choice>
		</xs:sequence>			
	</xs:group>
	<xs:complexType name="Implies.type">
		<xs:group ref="Implies.content"/>
		<xs:attributeGroup ref="Implies.attlist"/>
	</xs:complexType>
	<xs:element name="Implies" type="Implies.type"/>		

	<!-- 
		*** body ***
		content model: (Atom | And | Or)
	
		The body of a rule, also known as the "antecedent" or "if" part of the rule.

		The body role is only usable within  implication rules.  It uses an atomic
		(or, in equalog, equational) formula, an 'And' or an 'Or'.
	-->
	<xs:attributeGroup name="body.attlist"/>
	<xs:group name="body.content">
		<xs:choice>
			<xs:element ref="Atom"/>
			<xs:element name="And" type="And-inner.type"/>
			<xs:element name="Or" type="Or-inner.type"/>			
		</xs:choice>
	</xs:group>
	<xs:complexType name="body.type">
		<xs:group ref="body.content"/>
		<xs:attributeGroup ref="body.attlist"/>
	</xs:complexType>
	<xs:element name="body" type="body.type"/>
	
	<!--
		*** head ***
		content model: (Atom)
		
		The head of a rule, also known as the "consequent" or "then" part of the rule.

		The head role is only usable within  implication rules.  It uses an atomic
		(or, in equalog, equational) formula.
	-->
	<xs:attributeGroup name="head.attlist"/>
	<xs:group name="head.content">
		<xs:choice>
			<xs:element ref="Atom"/>
		</xs:choice>
	</xs:group>
	<xs:complexType name="head.type">
		<xs:group ref="head.content"/>
		<xs:attributeGroup ref="head.attlist"/>
	</xs:complexType>
	<xs:element name="head" type="head.type"/>	

	<!--
		*** Equivalent ***
		content model:
		( oid?, ( ( torso, torso) | ( Atom, Atom) ) )

		Syntactic sugar for a pair of conjoined converse 'Implies' expressing equivalence.  An 'Equivalent' may
		have a pair of symmetric 'torso' roles (combining the asymmetric 'head' and 'body').
	-->
	<xs:attributeGroup name="Equivalent.attlist">
		<xs:attributeGroup ref="closure.attrib"/>
	</xs:attributeGroup>
	<xs:group name="Equivalent.content">
		<xs:sequence>
			<xs:choice minOccurs="0">
				<xs:element ref="oid"/>
			</xs:choice>	
			<xs:choice>
				<xs:sequence>
					<xs:element ref="torso" minOccurs="2" maxOccurs="2"/>
				</xs:sequence>
				<xs:sequence>
					<xs:group ref="torso.content" minOccurs="2" maxOccurs="2"/>
				</xs:sequence>
			</xs:choice>
		</xs:sequence>			
	</xs:group>
	<xs:complexType name="Equivalent.type">
		<xs:group ref="Equivalent.content"/>
		<xs:attributeGroup ref="Equivalent.attlist"/>
	</xs:complexType>
	<xs:element name="Equivalent" type="Equivalent.type"/>
	
	<!--
		*** torso ***
		content model: (Atom)
		
		A symmetric role used in 'Equivalent' combining the asymmetric 'head' and 'body'.
	-->
	<xs:attributeGroup name="torso.attlist"/>
	<xs:group name="torso.content">
		<xs:choice>
			<xs:element ref="Atom"/>			
		</xs:choice>
	</xs:group>
	<xs:complexType name="torso.type">
		<xs:group ref="torso.content"/>
		<xs:attributeGroup ref="torso.attlist"/>
	</xs:complexType>
	<xs:element name="torso" type="torso.type"/>	

	<!--
		*** And ***
		Note that this element's content model is context-sensitive, so it is locally declared.
		See http://www.w3.org/2000/04/26-csrules.html.

		content model (below Assert): ( oid?, (formula | Atom | Implies | Equivalent | Forall)* )
		content model (below Query, Implies, body, And/Or): ( (formula | Atom | And | Or)* )

		Note that below Assert, And can have innerclose="universal", but below Query,
		only closure="existential".

		A conjunctive expression.

		"<And>Atom</And>" is equivalent to "Atom", while "<And></And>"
		is equivalent to "true".
	-->
	<xs:attributeGroup name="And-assert.attlist">
		<xs:attributeGroup ref="direction.attrib"/>
		<xs:attributeGroup ref="innerclose-universal.attrib"/>
	</xs:attributeGroup>
	<xs:attributeGroup name="And-query.attlist">
		<xs:attributeGroup ref="closure-existential.attrib"/>
	</xs:attributeGroup>	
	<xs:attributeGroup name="And-inner.attlist"/>
	<xs:group name="And-top.content">
		<xs:sequence>
			<xs:choice minOccurs="0">
				<xs:element ref="oid"/>
			</xs:choice>			
			<xs:choice minOccurs="0" maxOccurs="unbounded">
				<xs:element name="formula" type="formula-top-and.type"/>
				<xs:group ref="formula-top-and.content"/>
			</xs:choice>	
		</xs:sequence>			
	</xs:group>	
	<xs:group name="And-inner.content">
		<xs:sequence>
			<xs:choice minOccurs="0" maxOccurs="unbounded">
				<xs:element name="formula" type="formula-and-or.type"/>		
				<xs:group ref="formula-and-or.content"/>
			</xs:choice>		
		</xs:sequence>			
	</xs:group>
	<xs:complexType name="And-assert.type">
		<xs:group ref="And-top.content"/>
		<xs:attributeGroup ref="And-assert.attlist"/>
	</xs:complexType>
	<xs:complexType name="And-query.type">
		<xs:group ref="And-inner.content"/>
		<xs:attributeGroup ref="And-query.attlist"/>
	</xs:complexType>	
	<xs:complexType name="And-inner.type">
		<xs:group ref="And-inner.content"/>
		<xs:attributeGroup ref="And-inner.attlist"/>
	</xs:complexType>	

	<!--
		*** Or ***
		Note that this element's content model is context-sensitive, so it is locally declared.
		See http://www.w3.org/2000/04/26-csrules.html.		
		
		content model: ( (formula | Atom | And | Or)* )
		
		Under Query, Or may have attribute closure="existential"; elsewhere, it may not
		have any attributes.

		An 'Or' uses zero or more atomic formulas or conjunctions.  It is usable within Implies, body and And/Or.
		"<Or>Atom</Or>" is equivalent to "Atom".
	-->
	<xs:attributeGroup name="Or-query.attlist">	
		<xs:attributeGroup ref="closure-existential.attrib"/>
	</xs:attributeGroup>
	<xs:attributeGroup name="Or-inner.attlist"/>
	<xs:group name="Or.content">
		<!-- note the min and maxOccurs constraints on the reference to this content model -->
		<xs:choice>
			<xs:element name="formula" type="formula-and-or.type"/>
			<xs:group ref="formula-and-or.content"/>
		</xs:choice>
	</xs:group>
	<xs:complexType name="Or-query.type">
		<xs:group ref="Or.content" minOccurs="0" maxOccurs="unbounded"/>
		<xs:attributeGroup ref="Or-query.attlist"/>
	</xs:complexType>
	<xs:complexType name="Or-inner.type">
		<xs:group ref="Or.content" minOccurs="0" maxOccurs="unbounded"/>
		<xs:attributeGroup ref="Or-inner.attlist"/>
	</xs:complexType>	

	<!--
		*** formula ***
		Note that this element's content model is context-sensitive, so it is locally declared.
		See http://www.w3.org/2000/04/26-csrules.html.

		content model (below top level And): ( Atom | Implies | Equivalent | Forall )

		Note that this must be distinguished from when below Forall because in Equalog, Equal is
		permitted in top level Ands but not in Forall.

		content model (below And/Or): (Atom | And | Or)

		This is a metarole which may be left implicit.

		Note that "formula" may also appear below "Forall".  See the quantifier module for details.
	-->
	<xs:attributeGroup name="formula.attlist"/>
	<xs:group name="formula-top-and.content">
		<xs:choice>
			<xs:element ref="Atom"/>
			<xs:element ref="Implies"/>			
			<xs:element ref="Equivalent"/>			
			<xs:element ref="Forall"/>			
		</xs:choice>
	</xs:group>
	<xs:group name="formula-and-or.content">
		<xs:choice>
			<xs:element ref="Atom"/>
			<xs:element name="And" type="And-inner.type"/>
			<xs:element name="Or" type="Or-inner.type"/>
		</xs:choice>
	</xs:group>	
	<xs:complexType name="formula-top-and.type">
		<xs:group ref="formula-top-and.content"/>
		<xs:attributeGroup ref="formula.attlist"/>
	</xs:complexType>
	<xs:complexType name="formula-and-or.type">
		<xs:group ref="formula-and-or.content"/>
		<xs:attributeGroup ref="formula.attlist"/>
	</xs:complexType>	

	<!--
		*** @direction ***
		
		The direction attribute indicates the intended direction of implication rule
		inferencing in a rulebase.  It has a neutral default value of "bidirectional".
	-->
	<xs:attributeGroup name="direction.attrib">
		<xs:attribute name="direction" use="optional" default="bidirectional">
			<xs:simpleType>
				<xs:restriction base="xs:NMTOKEN">
					<xs:enumeration value="forward"/>
					<xs:enumeration value="backward"/>
					<xs:enumeration value="bidirectional"/>
				</xs:restriction>
			</xs:simpleType>
		</xs:attribute>
	</xs:attributeGroup>
	
	<!--
		*** @innerclose ***
		
		The innerclose attribute indicates how the free variables falling within its
		element's scope are quantified.
	-->
	<xs:attributeGroup name="innerclose-universal.attrib">
		<xs:attribute name="innerclose" use="optional">
			<xs:simpleType>
				<xs:restriction base="xs:NMTOKEN">
					<xs:enumeration value="universal"/>
				</xs:restriction>
			</xs:simpleType>
		</xs:attribute>
	</xs:attributeGroup>	
	<xs:attributeGroup name="innerclose.attrib">
		<xs:attribute name="innerclose" use="optional">
			<xs:simpleType>
				<xs:restriction base="xs:NMTOKEN">
					<xs:enumeration value="universal"/>
					<xs:enumeration value="existential"/>
				</xs:restriction>
			</xs:simpleType>
		</xs:attribute>
	</xs:attributeGroup>	

	<!--
		*** @closure ***
		
		The closure attribute indicates how the free variables falling within its
		element's scope are quantified.  Usable in Atom, Implies and Equivalent.
	-->
	<xs:attributeGroup name="closure-existential.attrib">
		<xs:attribute name="closure" use="optional">
			<xs:simpleType>
				<xs:restriction base="xs:NMTOKEN">
					<xs:enumeration value="existential"/>
				</xs:restriction>
			</xs:simpleType>
		</xs:attribute>
	</xs:attributeGroup>	
	<xs:attributeGroup name="closure.attrib">
		<xs:attribute name="closure" use="optional">
			<xs:simpleType>
				<xs:restriction base="xs:NMTOKEN">
					<xs:enumeration value="universal"/>
					<xs:enumeration value="existential"/>
				</xs:restriction>
			</xs:simpleType>
		</xs:attribute>
	</xs:attributeGroup>
	
</xs:schema>
