<?xml version="1.0" encoding="UTF-8"?>

<xs:schema 
targetNamespace="http://www.ruleml.org/0.9/xsd"
xmlns="http://www.ruleml.org/0.9/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">
			This is the XML Schema module for connective-related RuleML elements.
			File: connective_module.xsd
			Version: 0.9
			Last Modification: 2005-11-14
			
			This module declares the following RuleML elements and attributes:
			* Implies
			* body
			* head
			* Integrity
			* Equivalent
			* torso
			* And
			* Or
			* formula			
			* @kind
			* @mapDirection
			* @direction
			* @mapClosure
			* @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 ***
		An implication rule.

		See http://www.ruleml.org/0.9/glossary/#gloss-Implies

		content model:
		( oid?, ( head, body) | ( body, head) | ( (Atom | And | Or), Atom ) )
	-->
	<xs:attributeGroup name="Implies.attlist">
		<xs:attributeGroup ref="closure.attrib"/>
		<xs:attributeGroup ref="direction.attrib"/>	
		<xs:attributeGroup ref="kind.attrib"/>
	</xs:attributeGroup>
	<xs:group name="Implies.content">
		<xs:sequence>
			<xs:element ref="oid" minOccurs="0"/>
			<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 ***
		The body of an implication rule containing the premise(s), also known as the "antecedent" or "if" part of the rule.

		See http://www.ruleml.org/0.9/glossary/#gloss-body

		content model: (Atom | And | Or)
	-->
	<xs:attributeGroup name="body.attlist"/>
	<xs:group name="body.content">
		<xs:choice>
			<xs:element name="Atom" type="Atom.type"/>
			<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 ***
		The head of an implication rule containing the conclusion, also known as the "consequent" or "then" part of the rule.

		See http://www.ruleml.org/0.9/glossary/#gloss-head

		content model: (Atom)
	-->
	<xs:attributeGroup name="head.attlist"/>
	<xs:group name="head.content">
		<xs:choice>
			<xs:element name="Atom" type="Atom.type"/>
		</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"/>	


	<!--
		*** Integrity ***
		An integrity constraint.
		
		See http://www.ruleml.org/0.9/glossary/#gloss-Integrity
		
		content model:
		( oid?, (formula | Atom | And | Or) )

		Note that Integrity generalizes 0.89's Mutex in the following way:

		<Mutex>
		 <oppo>
		   <And> ... </And>
		 </oppo>
		 <mgiv>
		   <Atom> ... </Atom>
		 </mgiv>
		</Mutex>

		rewritten as

		<Integrity>
		 <Implies>
		   <head>
		     <Neg><And> ... </And></Neg>
		   </head>
		   <body>
		     <Atom> ... </Atom>
		   </body>
		 </Implies>
		</Integrity>

		A Mutex without an 'mgiv' goes as follows:

		<Mutex>
		 <oppo>
		   <And> ... </And>
		 </oppo>
		</Mutex>

		rewritten as

		<Integrity>
   	          <Neg>
                    <And> ... </And>
                  </Neg>
		</Integrity>
	-->
	<xs:attributeGroup name="Integrity.attlist">
		<xs:attributeGroup ref="closure.attrib"/>
		<xs:attributeGroup ref="direction.attrib"/>	
	</xs:attributeGroup>
	<!-- necessary for adding Implies in hohornlog -->
	<xs:group name="Integrity.extend">
		<xs:choice>
			<xs:element name="formula" type="formula-and-or.type"/>		
			<xs:group ref="formula-and-or.content"/>
		</xs:choice>
	</xs:group>	
	<xs:group name="Integrity.content">
		<xs:sequence>
			<xs:element ref="oid" minOccurs="0"/>
			<xs:group ref="Integrity.extend"/>
		</xs:sequence>			
	</xs:group>
	<xs:complexType name="Integrity.type">
		<xs:group ref="Integrity.content"/>
		<xs:attributeGroup ref="Integrity.attlist"/>
	</xs:complexType>
	<xs:element name="Integrity" type="Integrity.type"/>


	<!--
		*** Equivalent ***
		An equivalence expression, which is "syntactic sugar" for a pair of conjoined converse implication rules.
		
		See http://www.ruleml.org/0.9/glossary/#gloss-Equivalent

		content model:
		( oid?, ( ( torso, torso) | ( Atom, Atom) ) )
	-->
	<xs:attributeGroup name="Equivalent.attlist">
		<xs:attributeGroup ref="closure.attrib"/>
	</xs:attributeGroup>
	<xs:group name="Equivalent.content">
		<xs:sequence>
			<xs:element ref="oid" minOccurs="0"/>
			<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 ***
		A symmetric role used in an equivalence expression combining the asymmetric <head> and <body>.

		See http://www.ruleml.org/0.9/glossary/#gloss-torso

		content model: (Atom)
	-->
	<xs:attributeGroup name="torso.attlist"/>
	<xs:group name="torso.content">
		<xs:choice>
			<xs:element name="Atom" type="Atom.type"/>			
		</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 ***
		A conjunctive expression, where <And>Atom</And> is equivalent to Atom.

		See http://www.ruleml.org/0.9/glossary/#gloss-And
		
		Note that in naffolog and naffologeq, Naf cannot be prevented from
		occurring within the head via And/Or due to XSD technical reasons:
		the two types of the context sensitive tag both being in the content
		model of Implies would violate the "Element Declarations Consistent" constraint
		(http://www.w3.org/TR/xmlschema-1/#cos-element-consistent).

		Because not all validators enforce this constraint (e.g. Saxon), the
		modules and schemas retain the types and redefinitions to prevent Naf
		from occurring, but they are commented out.

		Under Query, And may have attribute closure="existential"; elsewhere, it may
		not have any attributes.

		content model: ( oid?, (formula | Atom | And | Or)* )

		This element's content model is context-sensitive.
		See http://www.w3.org/2000/04/26-csrules.html for details.	
	-->
	<xs:attributeGroup name="And-inner.attlist"/>
	<xs:attributeGroup name="And-query.attlist">	
		<xs:attributeGroup ref="closure.attrib"/>
	</xs:attributeGroup>
	<xs:group name="And.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-and-or.type"/>		
				<xs:group ref="formula-and-or.content"/>
			</xs:choice>		
		</xs:sequence>			
	</xs:group>
	<!-- The following content model is not actually used; see above. -->
	<xs:group name="And-head.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-and-or-head.type"/>		
				<xs:group ref="formula-and-or-head.content"/>
			</xs:choice>		
		</xs:sequence>			
	</xs:group>
	<xs:complexType name="And-query.type">
		<xs:group ref="And.content"/>
		<xs:attributeGroup ref="And-query.attlist"/>
	</xs:complexType>
	<xs:complexType name="And-inner.type">
		<xs:group ref="And.content"/>
		<xs:attributeGroup ref="And-inner.attlist"/>
	</xs:complexType>
	<!-- The following type is not actually used; see above. -->
	<xs:complexType name="And-head.type">
		<xs:group ref="And-head.content"/>
		<xs:attributeGroup ref="And-inner.attlist"/>
	</xs:complexType>	
	<xs:element name="And" type="And-inner.type"/>

	<!--
		*** Or ***
		A disjunctive expression, where <Or>Atom</Or> is equivalent to Atom.
		
		See http://www.ruleml.org/0.9/glossary/#gloss-Or

		Note that in naffolog and naffologeq, Naf cannot be prevented from
		occurring within the head via And/Or due to XSD technical reasons:
		the two types of the context sensitive tag both being in the content
		model of Implies would violate the "Element Declarations Consistent" constraint
		(http://www.w3.org/TR/xmlschema-1/#cos-element-consistent).

		Because not all validators enforce this constraint (e.g. Saxon), the
		modules and schemas retain the types and redefinitions to prevent Naf
		from occurring, but they are commented out.

		Under Query, Or may have attribute closure="existential"; elsewhere, it may not
		have any attributes.

		content model: ( oid?, (formula | Atom | And | Or)* )
		
		This element's content model is context-sensitive.
		See http://www.w3.org/2000/04/26-csrules.html for details.
	-->
	<xs:attributeGroup name="Or-query.attlist">	
		<xs:attributeGroup ref="closure.attrib"/>
	</xs:attributeGroup>
	<xs:attributeGroup name="Or-inner.attlist"/>
	<xs:group name="Or.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-and-or.type"/>
				<xs:group ref="formula-and-or.content"/>
			</xs:choice>
		</xs:sequence>
	</xs:group>
	<!-- The following content model is not actually used; see above. -->
	<xs:group name="Or-head.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-and-or-head.type"/>
				<xs:group ref="formula-and-or-head.content"/>
			</xs:choice>
		</xs:sequence>
	</xs:group>
	<xs:complexType name="Or-query.type">
		<xs:group ref="Or.content"/>
		<xs:attributeGroup ref="Or-query.attlist"/>
	</xs:complexType>
	<xs:complexType name="Or-inner.type">
		<xs:group ref="Or.content"/>
		<xs:attributeGroup ref="Or-inner.attlist"/>
	</xs:complexType>
	<!-- The following type is not actually used; see above. -->
	<xs:complexType name="Or-head.type">
		<xs:group ref="Or-head.content"/>
		<xs:attributeGroup ref="Or-inner.attlist"/>
	</xs:complexType>	
	<xs:element name="Or" type="Or-inner.type"/>

	<!--
		*** formula ***
		The formula role of a conjunctive or disjunctive expression, or a performative (<Assert>, <Query> or <Protect>).

		See http://www.ruleml.org/0.9/glossary/#gloss-formula

		Note that this role may also appear within quantifiers.  See the quantifier module for details.
		
		(The cases must be distinguished, even though the content model is the same,
		because Equal is permitted within Assert but not in Forall in hornlogeq.)

		content model (below Assert): ( Atom | Implies | Equivalent | Forall )
		content model (below And/Or): (Atom | And | Or)
		content model (below Query): (Atom | And | Or | Exists)

		This element's content model is context-sensitive.
		See http://www.w3.org/2000/04/26-csrules.html for details.
	-->
	<xs:attributeGroup name="formula.attlist"/>
	<xs:group name="formula-assert.content">
		<xs:choice>
			<xs:element name="Atom" type="Atom.type"/>
			<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 name="Atom" type="Atom.type"/>
			<xs:element name="And" type="And-inner.type"/>
			<xs:element name="Or" type="Or-inner.type"/>
		</xs:choice>
	</xs:group>
	<xs:group name="formula-query.content">
		<xs:choice>
			<xs:element name="Atom" type="Atom.type"/>
			<xs:element name="And" type="And-query.type"/>
			<xs:element name="Or" type="Or-query.type"/>
			<xs:element ref="Exists"/>
		</xs:choice>
	</xs:group>
	<!-- The following content model is not actually used; see above. -->	
	<xs:group name="formula-and-or-head.content">
		<xs:choice>
			<xs:element name="Atom" type="Atom.type"/>
			<xs:element name="And" type="And-head.type"/>
			<xs:element name="Or" type="Or-head.type"/>
		</xs:choice>
	</xs:group>	
	<xs:complexType name="formula-assert.type">
		<xs:group ref="formula-assert.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>
	<xs:complexType name="formula-query.type">
		<xs:group ref="formula-query.content"/>
		<xs:attributeGroup ref="formula.attlist"/>
	</xs:complexType>
	<!-- The following type is not actually used; see above. -->	
	<xs:complexType name="formula-and-or-head.type">
		<xs:group ref="formula-and-or-head.content"/>
		<xs:attributeGroup ref="formula.attlist"/>
	</xs:complexType>

	<!--
		*** @kind ***
		An attribute indicating the kind of an implication rule.
		
		See http://www.ruleml.org/0.9/glossary/#gloss-@kind
	-->
	<xs:attributeGroup name="kind.attrib">
		<xs:attribute name="kind" use="optional" default="fo">
			<xs:simpleType>
				<xs:restriction base="xs:NMTOKEN">
					<xs:enumeration value="fo"/>
					<xs:enumeration value="lp"/>
				</xs:restriction>
			</xs:simpleType>
		</xs:attribute>
	</xs:attributeGroup>	

	<!--
		*** @mapDirection ***
		An attribute indicating the intended direction of implication rule inferencing of elements
		falling within its scope (i.e. all child elements)
		
		See http://www.ruleml.org/0.9/glossary/#gloss-@mapDirection
	-->
	<xs:attributeGroup name="mapDirection.attrib">
		<xs:attribute name="mapDirection" 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>

	<!--
		*** @direction ***
		An attribute indicating the intended direction of an implication rule's inferencing.
		
		See http://www.ruleml.org/0.9/glossary/#gloss-@direction
	-->
	<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>
	
	<!--
		*** @mapClosure ***
		An attribute indicating how the free variables falling within its scope (i.e. all child elements) are quantified.
		
		See http://www.ruleml.org/0.9/glossary/#gloss-@mapClosure
	-->
	<xs:attributeGroup name="mapClosure.attrib">
		<xs:attribute name="mapClosure" 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 ***
		An attribute indicating how the contained free variables are quantified.
		
		See http://www.ruleml.org/0.9/glossary/#gloss-@closure		
	-->
	<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>