<?xml version="1.0" encoding="UTF-8"?>
<grammar 
  xmlns="http://relaxng.org/ns/structure/1.0"
  xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"
  datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
	<a:documentation>
		This schema proposes a description format for the output of text annotation tools. It is based on 
		the format used in the EDITOR tools being developed at the Huygens Instituut but meant to be 
		tool independent.     
	</a:documentation>
    <start>
    	<element name="annotationSet">
	    	<attribute name="schemaVersion">
    			<value>0.1</value>
    		</attribute>
    		<element name="setData">
				<a:documentation>Contains information about the annotation set.</a:documentation>
    			<ref name="setDataContent"/>
    		</element>
			<element name="editionData">
				<a:documentation>Contains information about the editions being annotated by this set.</a:documentation>
				<ref name="editionDataContent"/>
			</element>
    		<element name="typeData">
				<a:documentation>Contains information about the anotation types in the annotation set.</a:documentation>
    			<ref name="typeDataContent"/>
    		</element>
    		<element name="annotationData">
				<a:documentation>Contains information about the annotations.</a:documentation>
    			<ref name="annotationDataContent"/>
    		</element>
    	</element>
    </start>
	<define name="annotationDataContent">
		<zeroOrMore>
			<element name="annotation">
				<a:documentation>Each annotation corresponds to a single annotation element.</a:documentation>
				<attribute name="xml:id">
					<a:documentation>Annotations need an identifying attribute as it should be possible to point to 
					them from other annotations.</a:documentation>
					<data type="ID"/></attribute>
				<attribute name="editionRef">
					<a:documentation>Refers to the edition using its url attribute.</a:documentation>
					<data type="anyURI"></data>
				</attribute>
				<attribute name="typeRef">
					<a:documentation>Refers to the annotation type that types this annotation.</a:documentation>
					<data type="anyURI"></data>
				</attribute>
				<ref name="accounting"/>
				<attribute name="startsAtPath">
					<a:documentation>At present, a simple xpath tree expression, eg.  
					/TEI.2[1]/text[1]/group[1]/text[6].</a:documentation>
					<text/>
				</attribute>
				<attribute name="startsAtOffset">
					<a:documentation>Starting point of the annotation. Starts from zero. Zero if annotation 
					is on full element. The offset is an offset within the text nodes of the element identified by the 
					startsAtPath attribute, and does not consider text nodes at lower levels.</a:documentation>
					<data type="integer"/></attribute>
				<attribute name="endsAtPath">
					<a:documentation>At present, a simple xpath tree expression, eg.  
					/TEI.2[1]/text[1]/group[1]/text[6].</a:documentation>
					<text/></attribute>
				<attribute name="endsAtOffset">
					<a:documentation>End point of the annotation. Starts from zero. -1 if annotation 
					is on full element.</a:documentation>
					<data type="integer"/></attribute>
				<optional>
					<element name="selectedText">
						<a:documentation>For debugging, optimisation or other purposes, the annotation creation 
						tool may provide (a fragment of) the annotated text.</a:documentation>
						<text/></element>
				</optional>
				<oneOrMore>
					<element name="annotationField">
						<a:documentation>Annotations can consist of multiple fields.</a:documentation>
						<attribute name="typeFieldRef">
							<a:documentation>Refers to the field that types this annotation field, defined at the 
							annotation type level.</a:documentation>
							<data type="anyURI"></data>
						</attribute>
						<element name="value">
							<a:documentation>Value of the annotation field.</a:documentation>
							<text/></element>
					</element>
				</oneOrMore>
			</element>
		</zeroOrMore>
	</define>
	<define name="editionDataContent">
		<oneOrMore>
			<element name="edition">
				<attribute name="url">
					<a:documentation>Annotations use this url to refer to the edition.</a:documentation>
					<data type="anyURI"></data>
				</attribute>
				<attribute name="checksum">
					<a:documentation>May be used to check the integrity of the edition. [Needs 
					extra info about algorithm used?]</a:documentation>
				</attribute>
				<ref name="desc">
					<a:documentation>Used to give a brief description of the edition, 
						friendly to the human eye. Suggested content: author, 
						short title, year.</a:documentation>
				</ref>
			</element>
		</oneOrMore>
	</define>
	<define name="setDataContent">
		<attribute name="name">
			<text/>
		</attribute>
		<ref name="desc"/>
		<ref name="accounting"/>
		<optional>
			<element name="contactInfo">
				<a:documentation>Probably an email address of the set author.</a:documentation>
				<text/>
			</element>
		</optional>
		<element name="program">
			<a:documentation>Program used to create the annotations.</a:documentation>
			<text/></element>
		<element name="programVersion">
			<a:documentation>Program version used to create the annotations.</a:documentation>
			<text/></element>
		<element name="rights">
			<a:documentation>License that applies to this annotation set.</a:documentation>
			<text/></element>
		<zeroOrMore>
			<element name="setInfo">
				<a:documentation>
					Can be used either to describe the background and thinking behing the creation of the 
					annotation set or to refer to an explanation elsewhere, possible in a scholarly article 
					in a repository.
				</a:documentation>
				<oneOrMore>
					<element name="p">
						<a:documentation>Paragraphs of plain text</a:documentation>
						<text/>
					</element>
					<element name="uri"><data type="anyURI"/></element>
				</oneOrMore>
			</element>
		</zeroOrMore>
		<optional>
			<element name="colorScheme">
				<a:documentation>Suggests color series to be used in displaying this
					annotation set.</a:documentation>
				<oneOrMore>
					<ref name="color"/>
				</oneOrMore>
			</element>
		</optional>
	</define>
	<define name="typeDataContent">
		<oneOrMore>
			<element name="annotationType">
				<attribute name="xml:id">
					<a:documentation>Use by annotations to refer to annotation type.</a:documentation>
					<data type="ID"/></attribute>
				<attribute name="name">
					<a:documentation>Should be unique within annotation set.</a:documentation>
				</attribute>
				<optional>
					<attribute name="selectedTextEditable">
						<a:documentation>Boolean value that determines whther the 'selected text' value of the 
						annotation (see selectedTextDetermined attribute) can be modified by the researcher.</a:documentation>
						<data type="boolean"/></attribute>
				</optional>
				<optional>
					<attribute name="selectedTextDetermined">
						<a:documentation>Boolean value that determines whether the annotation creation application 
						will store (a fragment of) the selected text.</a:documentation>
						<data type="boolean"/></attribute>
				</optional>
				<ref name="label"/>
				<ref name="desc"/>
				<optional>
					<ref name="color">
						<a:documentation>Annotation types may be assigned their own identifying color 
						for consistent display.</a:documentation>
					</ref>
				</optional>
				<optional>
					<attribute name="highlighting">
						<a:documentation>Boolean value that suggests whether or not to highlight the annotated 
						text fragment on display of the annotations. Typically false for an annotation type 
						that is applied to larger textual units.</a:documentation>
						<data type="boolean"/>
					</attribute>
				</optional>
				<optional>
					<attribute name="highlightFieldRef">
						<a:documentation>When highlighting the annotated fragment is done by the value of 
							one of its category fields, the highlightFieldRef attribute determines 
							the default field to be used for that purpose.</a:documentation>
						<data type="anyURI"/></attribute>
				</optional>
				<oneOrMore>
					<element name="annotationTypeField">
						<a:documentation>Defines a field within an annotation type.</a:documentation>
						<attribute name="xml:id">
							<a:documentation>Used to refer to the type field from the annotation fields
							that it describes.</a:documentation>
							<data type="ID"/></attribute>
						<attribute name="name">
							<a:documentation>Must be unique within the annotation type. Need not be unique 
							within the annotation set.</a:documentation>
						</attribute>
						<attribute name="fieldType">
							<a:documentation>Data type of the field. Values: category (set of 
							values), text (string), memo (multi-line text), URL and annotation (reference to 
							another annotation by its id).</a:documentation>
							<choice>
								<value>Category</value> <!--  -->
								<value>Text</value> <!--  normalisedstring? -->
								<value>URL</value> <!-- anyURI -->
								<value>Memo</value> <!--  string? -->
								<value>Annotation</value> <!-- anyURI -->
							</choice>
						</attribute>
						<ref name="label"/>
						<ref name="desc"/>
						<zeroOrMore>
							<element name="fieldDefaultValue">
								<a:documentation>The values used for fields of type category are 
								stored at the type level. They may be assigned a label, a description 
								and an identifying color.</a:documentation>
								<attribute name="value"/>
								<ref name="label"/>
								<ref name="desc"/>
								<optional>
									<ref name="color"/>
								</optional>
							</element>
						</zeroOrMore>
					</element>
				</oneOrMore>
			</element>
		</oneOrMore>
	</define>
	<define name="desc">
		<optional>
			<element name="desc">
				<a:documentation>Description of an annotation set, type, field or value.</a:documentation>
				<text/>
			</element>
		</optional>
	</define>
	<define name="label">
		<optional>
			<attribute name="label">
				<a:documentation>Used as a brief label in presentations of annotation types, 
					fields or default values.</a:documentation>
				<text/>
			</attribute>
		</optional>
	</define>
	<define name="accounting">
		<optional>
			<attribute name="createdOn">
				<data type="string"/>
			</attribute>
		</optional>
		<optional>
			<attribute name="changedOn">
				<data type="string"/>
			</attribute>
		</optional>
		<optional>
			<element name="author">
				<text/>
			</element>
		</optional>
	</define>
	<define name="color">
					<element name="color">
						<attribute name="value"><text/></attribute>
					</element>
	</define>
</grammar>