<?xml version='1.0'?>

<!-- CardinalityIndication - a property restriction on the number of properties on an instance. -->
<!-- Cardinality -->

<rdf:RDF
  xmlns:rdf ="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
  xmlns:xsd ="http://www.w3.org/2000/10/XMLSchema#"
  xmlns:daml="http://www.daml.org/2001/03/daml+oil#"
  xmlns:ont3="http://www.daml.org/validator/examples/ont3.daml#"
  xmlns:dt2 ="http://www.daml.org/validator/examples/dt2.xsd#"
  xmlns     ="http://www.daml.org/validator/examples/in8.daml#"
>

<!-- A ont3:AnimalWithOneChild must have exactly one ont3:hasChild predicate --> 

<!-- OK - This animal has exactly one child -->
<ont3:AnimalWithOneChild rdf:ID="motherBear">
  <ont3:hasChild>
    <ont3:Animal rdf:ID="babyBear"/>
  </ont3:hasChild>
</ont3:AnimalWithOneChild>

<!-- Error - Must have one child -->
<ont3:AnimalWithOneChild rdf:ID="childlessHen"/>

<!-- Error - Has too many children -->
<ont3:AnimalWithOneChild rdf:ID="motherPig">
  <ont3:hasChild>
    <ont3:Animal rdf:ID="piglet1"/>
  </ont3:hasChild>
  <ont3:hasChild>
    <ont3:Animal rdf:ID="piglet2"/>
  </ont3:hasChild>
</ont3:AnimalWithOneChild>

<ont3:Animal rdf:ID="kid"/>

<!-- OK - Here the children are the same, so only one child -->
<ont3:AnimalWithOneChild rdf:ID="motherGoat">
  <ont3:hasChild rdf:resource="#kid"/>
  <ont3:hasChild rdf:resource="#kid"/>
</ont3:AnimalWithOneChild>


<!-- We can define a sublcass that will also inherit the restriction -->

<daml:Class rdf:ID="PersonWithOneChild">
  <daml:subClassOf rdf:resource="http://www.daml.org/validator/examples/ont3.daml#AnimalWithOneChild"/>
  <daml:subClassOf rdf:resource="http://www.daml.org/validator/examples/ont3.daml#Person"/>
</daml:Class>

<!-- ERROR - must have one child -->
<PersonWithOneChild rdf:ID="john"/>

<!-- OK - has one child -->
<PersonWithOneChild rdf:ID="jane">
  <ont3:hasChild rdf:resource="#john"/>
</PersonWithOneChild>

<!-- ERROR - has more than one child -->
<PersonWithOneChild rdf:ID="jack">
  <ont3:hasChild rdf:resource="#john"/>
  <ont3:hasChild>
     <ont3:Person rdf:ID="jill"/>
  </ont3:hasChild>
</PersonWithOneChild>


<!-- ERROR - child is wrong type - Range Type Mismatch -->
<PersonWithOneChild rdf:ID="fatherPig">
  <ont3:hasChild rdf:resource="#piglet1"/>
</PersonWithOneChild>

</rdf:RDF>
