<TEI xmlns="http://www.tei-c.org/ns/1.0">
  <teiHeader>
    <fileDesc>
      <titleStmt>
        <title type="main">TEI by Example</title>
        <title type="sub">Module 8: Customising TEI, ODD, Roma</title>
        <author xml:id="RvdB">Ron Van den Branden</author>
        <editor xml:id="EV">Edward Vanhoutte</editor>
        <editor xml:id="MT">Melissa Terras</editor>
        <sponsor>Association for Literary and Linguistic Computing (ALLC)</sponsor>
        <sponsor>Centre for Data, Culture and Society, University of Edinburgh, UK</sponsor> 
        <sponsor>Centre for Digital Humanities (CDH), University College London, UK</sponsor>
        <sponsor>Centre for Computing in the Humanities (CCH), King’s College London, UK</sponsor>
        <sponsor>Centre for Scholarly Editing and Document Studies (CTB) , Royal Academy of Dutch Language and Literature, Belgium</sponsor>
        <funder>
          <address>
            <addrLine>Centre for Scholarly Editing and Document Studies (CTB)</addrLine>
            <addrLine>Royal Academy of Dutch Language and Literature</addrLine>
            <addrLine>Koningstraat 18</addrLine>
            <addrLine>9000 Gent</addrLine>
            <addrLine>Belgium</addrLine>
          </address>
          <email>ctb@kantl.be</email>
        </funder>
        <principal>Edward Vanhoutte</principal>
        <principal>Melissa Terras</principal>
      </titleStmt>
      <publicationStmt>
        <publisher>Centre for Scholarly Editing and Document Studies (CTB) , Royal Academy of Dutch Language and Literature, Belgium</publisher>
        <distributor>Centre for Scholarly Editing and Document Studies (CTB) , Royal Academy of Dutch Language and Literature, Belgium</distributor>
        <pubPlace>Gent</pubPlace>
        <address>
          <addrLine>Centre for Scholarly Editing and Document Studies (CTB)</addrLine>
          <addrLine>Royal Academy of Dutch Language and Literature</addrLine>
          <addrLine>Koningstraat 18</addrLine>
          <addrLine>9000 Gent</addrLine>
          <addrLine>Belgium</addrLine>
        </address>
        <availability status="free">
          <p>Licensed under a <ref target="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution ShareAlike 3.0 License</ref>
                    </p>
        </availability>
        <date when="2010-07-09">9 July 2010</date>
      </publicationStmt>
      <seriesStmt>
        <title>TEI By Example.</title>
        <editor>Edward Vanhoutte</editor>
        <editor>Ron Van den Branden</editor>
        <editor>Melissa Terras</editor>
      </seriesStmt>
      <sourceDesc>
        <p>Digitally born</p>
      </sourceDesc>
    </fileDesc>
    <encodingDesc>
      <projectDesc>
        <p>TEI By Example offers a series of freely available online tutorials walking individuals through the different stages in marking up a document in TEI (Text Encoding Initiative). Besides a general introduction to text encoding, step-by-step tutorial modules provide example-based introductions to eight different aspects of electronic text markup for the humanities. Each tutorial module is accompanied with a dedicated examples section, illustrating actual TEI encoding practise with real-life examples. The theory of the tutorial modules can be tested in interactive tests and exercises.</p>
      </projectDesc>
    </encodingDesc>
    <profileDesc>
      <langUsage>
        <language ident="en-GB">en-GB</language>
      </langUsage>
    </profileDesc>
    <revisionDesc>
      <change when="2020-06-15" who="#RvdB">proofing corrections</change>
      <change when="2020-06-11" who="#RvdB">revision</change>
      <change when="2020-04-30" who="#RvdB">updated to Pure ODD + RomaJS</change>
      <change when="2010-07-13" who="#RvdB">
        <list>
          <item>added distinction <gi>gi</gi> — <tag>gi scheme="..."</tag> — <gi>tag</gi>
                    </item>
          <item>final spellcheck</item>
        </list>
      </change>
      <change when="2010-07-09" who="#RvdB">release</change>
      <change when="2008-11-05" who="#RvdB">
        <list>
          <item>updated to TEI P5-1.2.0 + Roma 3.5 (04/11/2008)</item>
          <item>corrected errors + typos</item>
        </list>
      </change>
      <change when="2008-08-21" who="#RvdB">
        <list>
          <item>corrected typos</item>
          <item>elaborated on didactic motivations for some choices in the tutorial</item>
        </list>
      </change>
      <change when="2008-08-19" who="#RvdB">replaced <title level="m">Alice’s Adventures Under Ground</title> example with <title level="m">Alice’s Adventures in Wonderland</title> due to copyright concerns with the images</change>
      <change when="2008-08-01" who="#RvdB">revisions</change>    
      <change when="2008-07-15" who="#RvdB">creation</change>
    </revisionDesc>
  </teiHeader>
  <text xml:id="TBED08v00" type="tutorials">
    <body>
            <div xml:id="extending">
        <head>Extending TEI</head>
        <p>So far, all modifications described were reductions of the general TEI model: either by selecting existing modules, elements, or attributes; or reducing the possible values of attributes. These kinds of modifications define true subsets of the TEI model, as long as they don’t remove any mandatory elements or attributes. In other words: TEI documents that are valid according to a schema generated from such reductive TEI customisations (like ours so far), will always be valid against the <ident type="file">tei_all</ident> customisation, which includes all TEI elements and attributes: see <ptr target="https://tei-c.org/release/xml/tei/custom/odd/tei_all.odd"/>.</p>
        <p>Not so for customisations that add things to the maximal TEI schema: these will produce TEI schemas that add new elements and/or attributes, or extend existing TEI definitions in such ways that they are not fully <soCalled>backward compatible</soCalled> with <soCalled>native TEI</soCalled>. In order to facilitate the understanding of TEI customisations, following terms are used:
          <list type="gloss">
            <label>TEI conformant customisation</label> 
            <item>a reductive customisation, that only restricts and constrains existing components of the TEI model (without removing mandatory components). TEI conformant customisations define schemas that are a subset of the maximal TEI schema. Everything documented in a TEI conformant customisation is documented in the TEI Guidelines.</item>
            <label>TEI extension</label> 
            <item>additive customisation, extending the TEI model with new components. TEI extensions produce schemas that aren’t subsets of the maximal TEI schema. TEI extensions define concepts that are not documented in the TEI Guidelines.</item>
          </list>
        </p>
        <p>It is very common to create TEI extensions: often, projects can have specific encoding needs for which no ideal TEI solution exists. In order to avoid <soCalled>tag abuse</soCalled>, where existing TEI elements or attributes are used in a way that more or less stretches their actual definition in the TEI Guidelines, projects can define their own means for encoding such phenomena in a TEI extension. These can be used internally in a project, or—if a proposed encoding solution has broader use—, it can eventually be incorporated in the TEI Guidelines, through the process of <ref target="https://github.com/TEIC/TEI/issues?q=label%3A%22Type%3A+FeatureRequest%22+">Feature Requests</ref> in the TEI source code repository.</p>
        <p>While TEI extensions are a very common way of customising TEI, in order to guarantee maximal interoperability for TEI documents, the TEI Guidelines strongly advise to formally separate elements and attributes added in a TEI extension from the <soCalled>native</soCalled> ones in the standard TEI schema. This can be done by defining them in another namespace than the TEI namespace (<ident type="ns">http://www.tei-c.org/ns/1.0</ident>). You can freely decide on this/these extension namespace/s; for the purpose of this tutorial, we’ll use a dedicated TBE namespace: <ident type="ns">http://teibyexample.org/ns/TBE</ident>. Notice that this namespace URI (Uniform Resource Identifier) doesn’t need to be officially registered, nor lead to an actual web resource. It can indeed be any URI, as long as it provides a unique identification for the non-TEI parts of your TEI customisation (so it must definitely differ from <ident type="ns">http://www.tei-c.org/ns/1.0</ident>). In the context of an encoding project, it is often a good idea to relate the namespace URI to the project’s URI in some way.</p>
        <div xml:id="addElements">
          <head>Adding Elements</head>
          <p>So far, our <ident type="file">TBEcustom</ident> customisation includes a generic <gi>name</gi> element (from the <ident type="module">core</ident> module) for identifying names in our <title level="m">Alice</title> encoding project. Apart from this generic element, TEI defines a set of more specialised elements for encoding names, in the <ident type="module">namesdates</ident> module. These elements add more semantic detail and leave more room for further (sub)typing. Let’s use Roma to have a look at what <ident type="module">namesdates</ident> has to offer:
            <list rend="ordered">
              <item>load the <ident type="file">TBEcustom</ident> customisation again in Roma if you haven’t done so already, and click the <q>Customize ODD</q> button,</item>
              <item>in the <q>Elements</q> tab, click the <q>by module</q> button at the top right of the Roma screen and scroll down to the elements of the <ident type="module">namesdates</ident> class.</item>
            </list>
            <figure xml:id="figure22">
              <graphic url="../../../images/tutorials/TBED08v00/romaNamesdates.png"/>
              <head type="legend">Grouping all elements of a TEI module in Roma.</head>
            </figure>
          </p>
          <p>In this long list of specific elements for names and dates, two look particularly interesting for our purposes: <gi>persName</gi> (as an alternative for <tag>name type="person"</tag>) and <gi>placeName</gi> (as an alternative for <tag>name type="place"</tag>). Let’s include them in our customisation: tick the boxes in Roma, and store the ODD file via the <q>Download</q> &gt; <q>Customization as ODD</q> button at the top right of the Roma screen. As you probably have expected, this will add following instruction to the ODD file:
          <egXML xmlns="http://www.tei-c.org/ns/Examples">
            <moduleRef key="namesdates" include="persName placeName"/>
          </egXML>
          </p>
          <p>If we generated a schema of the <ident type="file">TBEcustom</ident> customisation at this point, we would be able to rephrase the encoding of the different names in our <title level="m">Alice</title> fragment as follows:
            <egXML xmlns="http://www.tei-c.org/ns/Examples">
              <persName>Alice</persName>
              <name type="animal">Lobster</name>
              <name type="animal">Gryphon</name>
              <name type="animal">Mock Turtle</name>
            </egXML>
          </p>
          <p>Of course, this dual approach to name encoding, with the specialised <gi>persName</gi> and <gi>placeName</gi> elements for person and place names respectively, and the general <gi>name</gi> element with <att>type</att>=<val>animal</val> for animals, is undesirable. Therefore, we’ll extend our TEI customisation with a dedicated element for encoding animal names. As before, the remainder of this section first outlines the necessary steps in Roma, and next discusses the resulting ODD file.</p>
          <p>In Roma, new components (elements, classes, datatypes) can be added to a TEI customisation by clicking the <q>NEW</q> button at the bottom right of the screen:
            <figure xml:id="figure24">
              <graphic url="../../../images/tutorials/TBED08v00/romaNewMenu.png"/>
              <head type="legend">The <q>NEW</q> menu for adding new TEI components in Roma.</head>
            </figure>
          </p>
          <p>We’ll be creating a new element for animal names, so click the <q>Element</q> button of the pop-up menu. This opens a form with three fields. Let’s fill them:
            <list rend="bulleted">
              <item>
                                <q>Name</q>: the name of the element. By analogy to <gi>persName</gi> and <gi>placeName</gi>, let’s make this <gi scheme="TBE">animalName</gi>
                            </item>
              <item>
                                <q>Module</q>: the TEI module this new element will belong to. Since this is a specialised naming element, let’s select <ident type="module">namesdates</ident>.</item>
              <item>
                                <q>Namespace</q>: the namespace of the (non-TEI) element. As we’ve mentioned before, let’s make this <ident type="ns">http://teibyexample.org/ns/TBE</ident>
                            </item>
            </list>
            <figure xml:id="figure25">
              <graphic url="../../../images/tutorials/TBED08v00/romaNewElement-1.png"/>
              <head type="legend">
                                <q>Create new element</q> form in Roma.</head>
            </figure>
          </p>
          <p>After clicking the <q>Create</q> button, our new element is born! If an ODD file is generated at this point, it would be expanded with following instructions:
            <egXML xmlns="http://www.tei-c.org/ns/Examples">
              <elementSpec ident="animalName" ns="http://teibyexample.org/ns/TBE" mode="add" module="namesdates">
                <classes/>
                <attList/>
              </elementSpec>
            </egXML>
            This tells that our customisation defines a new element <gi scheme="TBE">animalName</gi> in the <ident type="ns">http://teibyexample.org/ns/TBE</ident> namespace, which will be made available in the <ident type="module">namesdates</ident> module.</p>
          <p>Yet, with empty <gi>classes</gi> and <gi>attList</gi> children, this element definition is still utterly useless. We have to define a number of essential properties:
            <list rend="bulleted">
              <item>the <hi rend="bold">attribute classes</hi> this new element belongs to</item>
              <item>the <hi rend="bold">model classes</hi> this new element belongs to</item>
              <item>the <hi rend="bold">content</hi> of this new element</item>
            </list>
          </p>
          <note type="reference">Exhaustive reference information for the TEI class system can be found in the TEI Guidelines, <ref target="https://tei-c.org/release/doc/tei-p5-doc/en/html/REF-CLASSES-MODEL.html">Appendix A: Model Classes</ref> and <ref target="https://tei-c.org/release/doc/tei-p5-doc/en/html/REF-CLASSES-ATTS.html">Appendix B: Attribute Classes</ref>. Datatypes definitions can be accessed from <ref target="https://tei-c.org/release/doc/tei-p5-doc/en/html/REF-MACROS.html">Appendix E: Datatypes and Other Macros</ref>. For an in-depth prose description of the entire TEI infrastructure, see chapter <ref target="https://tei-c.org/release/doc/tei-p5-doc/en/html/ST.html">1 The TEI Infrastructure</ref> of the TEI Guidelines.</note>
          <p>These are important decisions to make, which require conscious thought, as well as an understanding of the TEI class system. Fortunately, we can learn by example: since <!--
            
            
            Since we're modelling this new <gi scheme="TBE">animalName</gi> element on the existing <gi>persName</gi> and <gi>placeName</gi> elements, let's inspect how they are defined, with Roma.
            
            An explanation of all options on this page admittedly is too advanced for the purposes of this tutorial. As always, Roma offers a quite intuitive way to gain information by clicking the names of the different classes in the lists, which will provide you with their formal definition.</p>
          <p rend="crosslink">Exhaustive sources of reference information for the TEI class system can be found in the TEI Guidelines, <ref target="http://www.tei-c.org/release/doc/tei-p5-doc/en/html/REF-CLASSES-MODEL.html">Appendix A: Model Classes</ref> and <ref target="http://www.tei-c.org/release/doc/tei-p5-doc/en/html/REF-CLASSES-ATTS.html">Appendix B: Attribute Classes</ref>. Datatypes definitions can be accessed from <ref target="http://www.tei-c.org/release/doc/tei-p5-doc/en/html/REF-MACROS.html">Appendix E: Datatypes and Other Macros</ref>. For an in-depth prose description of the entire TEI infrastructure, see <ref target="http://www.tei-c.org/release/doc/tei-p5-doc/en/html/ST.html">Chapter 1</ref> of the TEI Guidelines.</p>
          <p>It will be clear by now that adding elements requires conscious thought. Of course, the easiest design choice could be to define a new element as freely as possible, for example by declaring it as member of the <ident type="class">model.global</ident> model class of global elements that can occur anywhere, and declaring the broadest possible content definition. However, this would leave judgement on the most sensible use of this element completely to the encoder, which would lead to highly unpredictable encoding results and thus reduce the value of this encoding. Therefore, it is strongly advised to determine the contexts and contents of new elements as precise as possible, in order to ensure that they fit neatly in the TEI semantic model of a text. Consequently, defining new elements requires some insight in the TEI's internals (organisation of modules, model classes, attribute classes, content macros). However, for simple cases like ours we can follow a common sense approach. Since--> we are modelling a new element for animal names to the existing <gi>persName</gi> TEI element, we can use the declaration of the latter as a source of inspiration, or just plainly copy it. Let’s have a look at the definition page for <gi>persName</gi>:
            <list rend="ordered">
              <item>load the <ident type="file">TBEcustom</ident> customisation again in Roma if you haven’t done so already, and click the <q>Customize ODD</q> button,</item>
              <item>move to the <q>Elements</q> tab and scroll down to the definition of <gi>persName</gi>.</item>
            </list>
          </p>
          <p>The <q>Documentation</q> button shows the description for the <gi>persName</gi> element.
            <figure xml:id="figure26">
              <graphic url="../../../images/tutorials/TBED08v00/romaPersNameDocumentation.png"/>
              <head type="legend">Display of the documentation for the <gi>persName</gi> element in Roma.</head>
            </figure>
          </p>
          <p>The <q>Attributes</q> button shows us the attribute classes. If only the top-level attribute classes are considered, that aren’t defined inside other attribute classes, <!-- [RvdB] check this! -->(the others are being included automatically when their superclass is included), this list can be reduced to:
            <list rend="bulleted">
              <item>
                                <ident type="class">att.datable</ident>: groups attributes for normalisation of names or dates</item>
              <item>
                                <ident type="class">att.editLike</ident>: groups attributes for describing the nature of an encoded interpretation</item>
              <item>
                                <ident type="class">att.global</ident>: groups common attributes for all TEI elements</item>
              <item>
                                <ident type="class">att.personal</ident>: groups common attributes for names</item>
              <item>
                                <ident type="class">att.typed</ident>: groups attributes that allow (sub)classification of an element</item>
            </list>
            <figure xml:id="figure27">
              <graphic url="../../../images/tutorials/TBED08v00/romaPersNameAttributes.png"/>
              <head type="legend">Display of the attributes for the <gi>persName</gi> element in Roma.</head>
            </figure>
          </p>
          <p>The <q>Class Membership &amp; Content Model</q> button shows us the model classes of which <gi>persName</gi> is a member:
            <list rend="bulleted">
              <item>
                                <ident type="class">model.nameLike.agent</ident>: groups elements which contain names of individuals or corporate bodies</item>
              <item>
                                <ident type="class">model.persStateLike</ident>: groups elements describing changeable characteristics of a person which have a definite duration, for example occupation, residence, or name</item>
            </list>
            This means that <gi>persName</gi>, and all other members of these model classes, can occur wherever TEI elements specify their contents in terms of these classes.
            <figure xml:id="figure28">
              <graphic url="../../../images/tutorials/TBED08v00/romaPersNameClasses.png"/>
              <head type="legend">Display of the class membership for the <gi>persName</gi> element in Roma.</head>
            </figure>
          </p>
          <p>The content model of the <gi>persName</gi> element is represented graphically in Roma. It refers to the <ident type="macro">macro.phraseSeq</ident> macro, which represents a predefined sequence of character data and phrase-level elements. This means that <gi>persName</gi> can contain text intermixed with a whole range of sub-paragraph level elements (<gi>abbr</gi>, <gi>expan</gi>, <gi>name</gi>, <gi>persName</gi>, ...).</p>
          <p>Let’s copy these same declarations to our new element. Return to the <q>Elements</q> tab and click the <gi scheme="TBE">animalName</gi> element. 
            In the description box, we can enter a prose description for the <gi scheme="TBE">animalName</gi> element, for example: 
            <figure xml:id="figure29">
              <graphic url="../../../images/tutorials/TBED08v00/romaAnimalNameDocumentation.png"/>
              <head type="legend">Editing the documentation for the <gi scheme="TBE">animalName</gi> element in Roma.</head>
            </figure>
          </p>
          <p>Clicking the button labeled <q>
                            <gi scheme="TBE">animalName</gi> &lt;</q> on top left of the Roma screen, gets us back to the overview of the <gi scheme="TBE">animalName</gi> definition. A click on the <q>Attributes</q> button shows us that its attribute list is empty, as we saw already in the generated ODD file. In order to declare its membership of the 5 attribute classes we had identified in the definition of <gi>persName</gi>, start by clicking the plus sign in the <q>Attribute from Classes</q> row. Next, filter or scroll through the list of attribute classes, and click the plus sign next to the ones we want to add.
                <!-- [RvdB] follow up Roma bug https://github.com/TEIC/romajs/issues/101: apparently, model.persStateLike must be added manually (not present on persName either) -->
            <figure xml:id="figure30">
              <graphic url="../../../images/tutorials/TBED08v00/romaAnimalNameAttributes.png"/>
              <head type="legend">Adding the <gi scheme="TBE">animalName</gi> element to attribute classes in Roma.</head>
            </figure>
          </p>
          <p>Finally, return to the overview of the <gi scheme="TBE">animalName</gi> definition, and click the <q>Class Membership &amp; Content Model</q> button. In order to define how our <gi scheme="TBE">animalName</gi> element will behave, click the plus sign in the <q>Model Classes</q> row and select the 2 model classes we had identified by clicking the plus sign next to their name. 
            <figure xml:id="figure31">
              <graphic url="../../../images/tutorials/TBED08v00/romaAnimalNameModelClass.png"/>
              <head type="legend">Editing the class membership of the <gi scheme="TBE">animalName</gi> element in Roma.</head>
            </figure>
            Next, its content can be defined by first clicking one of the <q>Groups</q>, <q>References</q>, or <q>Nodes</q> blocks. This will produce an overlay menu, with a graphical indication of the different types of ODD constructs that can be used for selecting individual nodes or combining them in groups, or referencing one of the predefined TEI macros or classes. We’ll be inserting a reference to the <ident type="macro">macro.phraseSeq</ident> macro, so we’ll click the <q>References</q> block.
            <figure xml:id="figure32">
              <graphic url="../../../images/tutorials/TBED08v00/romaAnimalNameContentReferences.png"/>
              <head type="legend">Selecting a macro for the content model of the <gi scheme="TBE">animalName</gi> element in Roma.</head>
            </figure>
            We want to include a reference to a macro, so <q>macroRef</q> is the block we’ll want to add. This is done by <emph>dragging</emph> that block into the graphical editor screen of Roma. Next, clicking the arrow in that <q>macroRef</q> block calls a dialog window where the <ident type="macro">macro.phraseSeq</ident> macro can be selected via the plus sign next to it. Finally, make sure to drag this populated <q>macroRef</q> block <emph>into</emph> the empty space of the blue <q>content</q> block in the graphical editor (you’ll hear a little <soCalled>click</soCalled> sound if it succeeds):
            <figure xml:id="figure33">
              <graphic url="../../../images/tutorials/TBED08v00/romaAnimalNameContent.png"/>
              <head type="legend">Adding a macro to the content model of the <gi scheme="TBE">animalName</gi> element in Roma.</head>
            </figure>
          </p>
          <p>Now it’s time to inspect our ODD customization: store the ODD file via the <q>Download</q> &gt; <q>Customization as ODD</q> button at the top right of the Roma screen. The resulting ODD file looks as follows:
            <!-- [RvdB] Roma bug https://github.com/TEIC/romajs/issues/108: <content> is not created -->
            <figure xml:id="example5">
              <egXML xmlns="http://www.tei-c.org/ns/Examples">
                <schemaSpec ident="TBEcustom" start="TEI" prefix="tei_" targetLang="en" docLang="en">
                  <moduleRef key="figures" include="figDesc figure"/>
                  <moduleRef key="header" include="teiHeader fileDesc titleStmt publicationStmt sourceDesc"/>
                  <moduleRef key="core" include="p title emph lg l pb pubPlace publisher q quote name graphic"/>
                  <moduleRef key="textstructure" include="TEI text body titlePage docTitle docImprint docDate docAuthor byline div"/>
                  <moduleRef key="tei"/>
                  <moduleRef key="namesdates" include="persName placeName"/>
                  <elementSpec ident="name" mode="change">
                    <classes mode="change">
                      <memberOf key="att.datable" mode="delete"/>
                      <memberOf key="att.editLike" mode="delete"/>
                      <memberOf key="att.personal" mode="delete"/>
                    </classes>
                    <attList>
                      <attDef ident="subtype" mode="delete"/>
                      <attDef ident="nymRef" mode="delete"/>
                      <attDef ident="type" mode="change">
                        <valList type="closed" mode="change">
                          <valItem mode="add" ident="place">
                            <desc versionDate="2020-04-23" xml:lang="en">used for place names</desc>
                          </valItem>
                          <valItem mode="add" ident="person">
                            <desc versionDate="2020-04-23" xml:lang="en">used for person names</desc>
                          </valItem>
                          <valItem mode="add" ident="animal">
                            <desc versionDate="2020-04-23" xml:lang="en">used for animal names</desc>
                          </valItem>
                        </valList>
                      </attDef>
                      <attDef ident="cert" mode="delete"/>
                      <attDef ident="resp" mode="delete"/>
                      <attDef ident="source" mode="delete"/>
                    </attList>
                  </elementSpec>
                  <classSpec ident="att.naming" type="atts" mode="change">
                    <attList>
                      <attDef ident="nymRef" mode="delete"/>
                    </attList>
                  </classSpec>
                  <elementSpec ident="animalName" ns="http://teibyexample.org/ns/TBE" mode="add" module="namesdates">
                    <desc>contains a proper noun referring to an animal</desc>
                    <classes>
                      <memberOf key="att.datable"/>
                      <memberOf key="att.editLike"/>
                      <memberOf key="att.global"/>
                      <memberOf key="att.personal"/>
                      <memberOf key="att.typed"/>
                      <memberOf key="model.nameLike.agent"/>
                      <memberOf key="model.persStateLike"/>
                    </classes>
                    <content>
                      <macroRef key="macro.phraseSeq"/>
                    </content>
                  </elementSpec>
                </schemaSpec>
              </egXML>
              <head type="legend">ODD definition of a new (non-TEI) element (<ref target="../download/TBEcustom-5-animalName.odd">download</ref>).</head>
            </figure>
          </p>
          <p>We see how an extra <gi>elementSpec</gi> element is added to the ODD file, with the definition for our newly added <gi scheme="TBE">animalName</gi> element. Its name is given in the <att>ident</att> attribute, and <att>mode</att>=<val>add</val> indicates that this is a new element. The <att>ns</att> attribute contains the namespace URI we specified for this element.</p>
          <p>The description of our brand new <gi scheme="TBE">animalName</gi> element is provided in a <gi>desc</gi> element. Its class membership is declared in a <gi>classes</gi> element; each of the attribute and model classes we had selected, is listed in a separate <gi>memberOf</gi> element, whose <att>key</att> attribute identifies the relevant class. The content of the element is declared within a <gi>content</gi> element. Since we included the shortcut to the <ident type="macro">macro.phraseSeq</ident> macro, this is recorded in a <gi>macroRef</gi> element, whose <att>key</att> attribute identifies the macro.</p>
          <p>In order to give an impression of the convenience of macros, let’s see what this <ident type="macro">macro.phraseSeq</ident> macro resolves to when the ODD file is being processed:
            <egXML xmlns="http://www.tei-c.org/ns/Examples">
              <alternate minOccurs="0" maxOccurs="unbounded">
                <textNode/>
                <classRef key="model.gLike"/>
                <classRef key="model.qLike"/>
                <classRef key="model.phrase"/>
                <classRef key="model.global"/>
              </alternate>
            </egXML>
          </p>
          <p>We’ll not go into full details here, but you’ll be able to understand that this macro defines a sequence with zero (<att>minOccurs</att>=<val>0</val>) or more (<att>maxOccurs</att>=<val>unbounded</val>) combinations of plain text nodes (<tag type="empty">textNode</tag>), or the elements from the 4 model classes identified in <gi>classRef</gi>. For full coverage of the definition of content models: see section <ref target="https://tei-c.org/release/doc/tei-p5-doc/en/html/TD.html#DEFCONTEI">22.5.1.1 Defining Content Models: TEI</ref> of the TEI Guidelines.</p>
          <note type="summary">Elements can be added to the existing TEI model by declaring them with an <gi>elementSpec</gi> element, with the value <val>add</val> for its <att>mode</att> attribute. The <att>ident</att> attribute must give the name of the element. Specific to added elements is the use of the <att>ns</att> attribute, whose value should provide a unique namespace URI for this element, different from the default TEI namespace (<ident type="ns">http://www.tei-c.org/ns/1.0</ident>). A prose description of the element can be given in a <gi>desc</gi> element. The structural behaviour and attributes of an element are defined in the <gi>classes</gi> element, containing <gi>memberOf</gi> declarations for each model or attribute class to which the element is added, identified with the <att>key</att> attribute. The content of the element is declared in the <gi>content</gi> element, containing either references to TEI macros, or hand-crafted sequences of nodes, elements, or element classes.</note>
        </div>
        <div xml:id="addAttributes">
          <head>Adding Attributes</head>
          <p>So far, we have customised our schema for the transcription of the <title level="m">Alice</title> text in such a way that we can distinguish between person, place, and animal names, either with specific <att>type</att> values of the generic <gi>name</gi> element (namely <val>person</val>, <val>place</val>, or <val>animal</val>), or by means of the TEI elements <gi>persName</gi> and <gi>placeName</gi>, and the non-TEI element <gi scheme="TBE">animalName</gi>. We fine-tuned all elements belonging to the <ident type="class">att.naming</ident> class by deleting the unneeded <att>nymRef</att> attribute from this class.</p>
          <p>For our specific analysis of <title level="m">Alice’s Adventures in Wonderland</title> we would like to experiment with a basic way of adding further information on the ontological status of the referents of the names in this fictitious story: it could be interesting to analyse the characters in terms of the kind of reality they exist in. A possible place for such information could be the <att>type</att> and <att>subtype</att> attributes of the <ident type="class">att.typed</ident> class. However, we would prefer a more specific label for this kind of information, and reserve these TEI attributes for possible different categorisations in the future. Therefore, we want to add a new attribute to our customisation. Similar to deleting attributes, adding new ones can happen on two levels:
            <list rend="bulleted">
              <item>element level: attributes may be added to an individual element, which will apply to this element only <lb/>→ This is accessible in Roma via the <q>Attributes</q> button in an element’s definition (via the <q>Elements</q> tab), where you can click the plus sign in the <q>Element attributes</q> row. In ODD, it will affect the attribute definition inside an <gi>elementSpec</gi> element.</item>
              <item>class level: attributes may be added to an attribute class, which will apply to all elements that are member of this class <lb/>→ This is accessible in Roma from the attribute class’s definition (via the <q>Attribute Classes</q> tab), where you can click the desired class name, click the <q>Attributes</q> button, and add additional attributes to the class. In ODD, it will affect the attribute definition inside a <gi>classSpec</gi> element.</item>
            </list>
          </p>
          <p>In this case, information on the ontological status of names’ referents not only applies to personal and place names, but also to our recently added animal names, names in general, and by extension all kinds of referring strings. This suggests the <ident type="class">att.naming</ident> attribute class as a good place to add this attribute.</p>
          <p>Let’s head over to Roma! Click the <q>Attribute Classes</q> tab for our TEI customisation, click the <ident type="class">att.naming</ident> class, and next hit the <q>Attributes</q> button. 
            <figure xml:id="figure34">
              <graphic url="../../../images/tutorials/TBED08v00/romaAttNaming.png"/>
              <head type="legend">Editing an attribute class for a TEI customisation in Roma.</head>
            </figure>
          </p>
          <p>This calls an overview of the attributes in this class (notice how the <att>nymRef</att> attribute still is excluded from our modification). Adding a new attribute to an attribute class can be done by clicking the plus sign in the <q>Class attributes</q> row. This produces a dialog window:
            <figure xml:id="figure35">
              <graphic url="../../../images/tutorials/TBED08v00/romaAttNamingNewAttribute.png"/>
              <head type="legend">Creating a new attribute in Roma.</head>
            </figure>
          </p>
          <p>This form asks us first for the name of this new attribute. Before we start defining the attribute, some thought is needed on its design. Following examples could illustrate different possibilities:
            <egXML xmlns="http://www.tei-c.org/ns/Examples">
              <persName fantastic="no">Alice</persName>
              <animalName realistic="0.5">Mock Turtle</animalName>
              <animalName ontStatus="mythological">Gryphon</animalName>
            </egXML>
          </p>
          <p>Attributes could be designed as binary choices taking some form of truth value, as categories taking some kind of degrees on a scale, as neutral labels taking a list of keywords, or many more. As we are in the early stages of the encoding project, and feel this ontological classification is still experimental, we can anticipate that categories are likely to pop up, merge, or be adapted along the way. Therefore, it makes most sense to design it as a general semantic field, allowing for an open-ended list of keywords. Considering these requirements, a sensible name for this attribute could be <soCalled>ontStatus</soCalled>. Let’s fill that name, and click the <q>Create</q> button. Now, this (empty) attribute definition is added to the list of <q>Class attributes</q>. In order to define this attribute, click the pencil icon next to its name. This will produce a page similar to the one we’ve seen before (when restricting the values of the <att>type</att> attribute for <gi>name</gi>). We’ll define this <att scheme="TBE">ontStatus</att> attribute as an <val>optional</val> attribute, by selecting this in the dropdown box next to <q>Usage</q>. In the <q>Description</q> field, we can provide a description, such as: 
            <eg>describes the ontological status of a name’s referent</eg>
            <figure xml:id="figure36">
              <graphic url="../../../images/tutorials/TBED08v00/romaOntStatusUsageDescription.png"/>
              <head type="legend">Editing documentation for a new attribute in Roma.</head>
            </figure>
          </p>
          <p>The other fields define the actual content of the attribute. For this example, suppose that an initial (experimental) categorisation for the ontological status of the people, places and animals in the <title level="m">Alice</title> story could look like this:
            <list rend="bulleted">
              <item>
                                <val>realistic</val>: the referent can / could occur in the extra-textual reality</item>
              <item>
                                <val>mythological</val>: the referent does not exist in real life, but belongs to a major mythology</item>
              <item>
                                <val>fantastic</val>: the referent belongs to an idiosyncratic fantasy universe</item>
            </list>
            However, it is prone to be extended with other categories, and would probably allow more categories to be applied simultaneously, for names referring to ambiguous creatures or places.</p>
          <p>This analysis obviously translates into a <q>semi-open</q> list: choose that option for the <q>Values</q> field. Attribute lists in ODD can have three types:
            <list type="gloss">
              <label>
                                <val>closed</val>
                            </label>
              <item>only the values defined in <gi>valList</gi> are permitted</item>
              <label>
                                <val>semi</val>
                            </label>
              <item>the values defined in <gi>valList</gi> are treated as suggested values, but others are allowed</item>
              <label>
                                <val>open</val>
                            </label>
              <item>any value is allowed (as long as it complies with the datatype); values in <gi>valList</gi> are treated as mere examples</item>
            </list>
          </p>
          <p>Suggested values can be entered in the text field of the <q>Values</q> field, and next pressing the plus sign next to the value. Let’s add the values mentioned above, as well as their description.
            <figure xml:id="figure37">
              <graphic url="../../../images/tutorials/TBED08v00/romaOntStatusValues.png"/>
              <head type="legend">Defining attribute values for a new attribute in Roma.</head>
            </figure>
          </p>
          <!-- [RvdB] follow up Roma bug https://github.com/TEIC/romajs/issues/109: currently, there's no way to specify @minOccurs and@maxOccurs for <datatype> in Roma -->
          <p>Finally, the datatype <!--and occurrence -->for the attribute’s value can be declared in the <q>Datatype</q> field. The TEI datatype <ident type="datatype">teidata.enumerated</ident>, which is explicitly designed to define a single word from a list of possibilities, seems the best fit. <!-- [RvdB] follow up Roma bug https://github.com/TEIC/romajs/issues/109: currently, there's no way to specify @minOccurs and@maxOccurs for <datatype> in Roma --><!--Although we defined the attribute as optional, we wouldn't like it to be empty when used on an element. Therefore, we can specify the value '1' after the <code>>=</code> sign, specifying that at least one value is expected for this attribute. To allow for an unlimited combination of values from the list in the attribute, the value 'unbounded' can be selected after the <code><=</code> sign.-->
            <!-- [RvdB] follow up Roma bug https://github.com/TEIC/romajs/issues/109: currently, there's no way to specify @minOccurs and@maxOccurs for <datatype> in Roma -->
            <figure xml:id="figure38">
              <graphic url="../../../images/tutorials/TBED08v00/romaOntStatusDatatype.png"/>
              <head type="legend">Defining the datatype for a new attribute in Roma.</head>
            </figure>
          </p>
          <p>In the introduction to this section we stated that extending the TEI always leads to TEI document models that are broader than and hence possibly incompatible with the standard TEI model. For maximal separation of extension features from the standard TEI model, the TEI Guidelines therefore advice to define extensions in their own namespace. We already did so when adding new elements in the previous section. Let’s declare the same namespace <ident type="ns">http://teibyexample.org/ns/TBE</ident> in the <q>Namespace</q> field for our <att scheme="TBE">ontStatus</att> attribute:
            <figure xml:id="figure39">
              <graphic url="../../../images/tutorials/TBED08v00/romaOntStatusNamespace.png"/>
              <head type="legend">Defining a namespace for a new attribute in Roma.</head>
            </figure>
          </p>
          <p>To save these changes as an ODD file, click the <q>Download</q> &gt; <q>Customization as ODD</q> button at the top right of the Roma screen. We’ll notice how a defintition of the new <att scheme="TBE">ontStatus</att> attribute now is added to the <gi>classSpec</gi> declaration for the <ident type="class">att.naming</ident> attribute class:
            <!-- [RvdB] roma questions:
              -shouldn't ontStatus have mode="add"?
              -<datatype> was placed after <valList>, which is not allowed
              -->
            <!-- [RvdB] follow up Roma bug https://github.com/TEIC/romajs/issues/109: currently, there's no way to specify @minOccurs and@maxOccurs for <datatype> in Roma -->
            <figure xml:id="example6">
              <egXML xmlns="http://www.tei-c.org/ns/Examples">
                <classSpec ident="att.naming" type="atts" mode="change">
                  <attList>
                    <attDef ident="nymRef" mode="delete"/>
                    <attDef ident="ontStatus" mode="change" usage="opt" ns="http://teibyexample.org/ns/TBE">
                      <desc versionDate="2020-04-28" xml:lang="en">describes the ontological status of a name's referent</desc>
                      <datatype maxOccurs="unbounded">
                        <dataRef key="teidata.enumerated"/>
                      </datatype>
                      <valList mode="change" type="semi">
                        <valItem mode="add" ident="realistic">
                          <desc versionDate="2020-04-28" xml:lang="en">the referent can / could occur in the extra-textual reality</desc>
                        </valItem>
                        <valItem mode="add" ident="mythological">
                          <desc versionDate="2020-04-28" xml:lang="en">the referent does not exist in real life, but belongs to a major mythology</desc>
                        </valItem>
                        <valItem mode="add" ident="fantastic">
                          <desc versionDate="2020-04-28" xml:lang="en">the referent can / could occur in the extra-textual reality</desc>
                        </valItem>
                      </valList>
                    </attDef>
                  </attList>
                </classSpec>
              </egXML>
              <head type="legend">ODD definition of a new (non-TEI) attribute in an attribute class (<ref target="../download/TBEcustom-6-ontStatus.odd">download</ref>).</head>
            </figure>
          </p>
          <p>Since we added the <att scheme="TBE">ontStatus</att> attribute to the <ident type="class">att.naming</ident> attribute class, the corresponding <gi>attDef</gi> declaration is added to the list of attribute declarations of the corresponding <gi>classSpec</gi> element. As before, the class specification’s <att>mode</att> attribute is set to <val>change</val>, indicating that only the declarations present in this ODD file will update the existing TEI definitions. Inside the <gi>attList</gi> section, the <att>nymRef</att> attribute still is deleted, in accordance with our previous changes.</p>
          <p>However, there’s a new <gi>attDef</gi> element for our <att scheme="TBE">ontStatus</att> attribute (identified in the <att>ident</att> attribute), this time with the value <!-- [RvdB] check with Roma: output is "change" -->
                        <val>change</val> for its <att>mode</att> attribute (since there was no existing definition for this element, this has the same effect as <att>mode</att>=<val>add</val>). The <val>opt</val> value for the <att>usage</att> attribute indicates that the <att scheme="TBE">ontStatus</att> attribute will be optional in our customisation (required attributes would have <val>req</val>).</p>
          <p>Inside the attribute definition, the <gi>desc</gi> element contains the prose description of the attribute. <!-- [RvdB] no longer / not yet supported in Roma? --><!--The <gi>datatype</gi> section declares that the <att scheme="TBE">ontStatus</att> attribute should have minimally one value (<att>minOccurs</att> = <val>1</val>), while there's no limit on the frequency of its values (<att>maxOccurs</att> = <val>unbounded</val>).--> The datatype of the attribute is defined in <gi>datatype</gi>. By means of a <gi>dataRef</gi> element, it is referring to the existing TEI datatype definition <val>teidata.enumerated</val> (which is given as the value for its <att>key</att> attribute). This datatype basically restricts the possible values to strings consisting of words or a limited range of punctuation marks. <!-- [RvdB] Roma bug https://github.com/TEIC/romajs/issues/109: currently, there's no way to specify @minOccurs and@maxOccurs for <datatype> in Roma -->Combined with the declarations in <!--<att>minOccurs</att> and--> <att>maxOccurs</att>, this means that the <att scheme="TBE">ontStatus</att> attribute for <gi scheme="TBE">animalName</gi> can contain a white space separated list of word characters and some punctuation marks.</p>
          <note type="reference">This introductory tutorial doesn’t cover the advanced inner mechanisms of TEI in full; for more information you can read section <ref target="https://tei-c.org/release/doc/tei-p5-doc/en/html/ST.html#DTYPES">1.4.2 Datatype Specifications</ref> of the TEI Guidelines, or the reference section in <ref target="https://tei-c.org/release/doc/tei-p5-doc/en/html/REF-MACROS.html">Appendix E: Datatypes and Other Macros</ref>.</note>
          <p>Finally, the list of possible values is given inside <gi>valList</gi>, which is declared as a semi-open list. Each of these values is given in its own <gi>valItem</gi> element, with a description of that value in <gi>desc</gi>.</p>
          <note type="summary">Adding attributes is done within an <gi>attDef</gi> declaration inside the <gi>attList</gi> declaration, either in the definition of a single element (<gi>elementSpec</gi>) or an attribute class (<gi>classSpec</gi>). The addition is specified in the <!-- [RvdB] check with Roma: output is "change" -->
                        <val>add</val> value for the <att>mode</att> attribute of the attribute definition; the name of the attribute is given in the <att>ident</att> attribute. Additionally, <gi>attDef</gi> specifies the usage of the attribute within <att>usage</att> (<val>opt</val> for optional attributes, <val>req</val> for mandatory ones). In order to distinguish added attributes from standard TEI ones, it is highly recommended to declare a dedicated namespace in the <att>ns</att> attribute. An attribute definition typically contains a prose description in <gi>desc</gi>, an indication of the attribute’s datatype in <gi>datatype</gi> (referring to one or more of the predefined TEI datatypes), and a list of possible values in <gi>valList</gi>. Such lists may be specified as <val>closed</val>, <val>semi</val>, or <val>closed</val> in the <att>type</att> attribute. Each predefined attribute value is declared in the <att>ident</att> attribute of a separate <gi>valItem</gi> element.</note>
        </div>
        <div xml:id="otherExtensions">
          <head>Other Types of Extension</head>
          <p>Besides these common cases of TEI extension, involving the addition and deletion of elements and attributes, TEI can be extended in both more subtle and complex ways:
            <list rend="bulleted">
              <item>existing TEI elements can be renamed</item>
              <item>content models of existing TEI elements can be broadened</item>
              <item>datatypes and occurrence indicators of attributes can be broadened</item>
              <item>existing TEI elements can be redefined to different model classes</item>
            </list>
          </p>
          <p>Most of these types of customisations make use of the mechanisms covered in this tutorial. However, these kinds of modifications are considered advanced topics and are not treated in this introductory tutorial. For more information, you are referred to chapters <ref target="https://tei-c.org/release/doc/tei-p5-doc/en/html/TD.html">22. Documentation Elements</ref> and <ref target="https://tei-c.org/release/doc/tei-p5-doc/en/html/USE.html">23. Using the TEI</ref> of the TEI Guidelines. <!-- [RvdB] obsolete--><!--, or one of these tutorials:
            <list>
              <item><ref target="http://www.tei-c.org/Guidelines/Customization/odds.xml">TEI: Getting Started with ODDs</ref></item>
              <item><ref target="http://www.tei-c.org/Guidelines/Customization/use_roma.xml">TEI: Using Roma</ref></item>
            </list>-->
          </p>
        </div>
      </div>
        </body>
  </text>
  <!-- 
      $Date: 2020-11-16 12:33:38 +0100 (Mon, 16 Nov 2020) $
      $Id: TBED08v00.xml 460 2020-11-16 11:33:38Z ron.vandenbranden $  -->
</TEI>