PREFIX st:   <http://ns.inria.fr/sparql-template/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX fun: <http://w3id.org/sparql-generate/fn/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX obo: <http://purl.obolibrary.org/obo/>
PREFIX swrl: <http://www.w3.org/2003/11/swrl#>
PREFIX prov: <http://www.w3.org/ns/prov#>
PREFIX iter: <http://w3id.org/sparql-generate/iter/>

BASE <https://saref.etsi.org/documentation/>

TEMPLATE <ontology/classes.rqg>( ?onto ) { 

  """\n<div id='classes'>
  <h2>{fun:property(<en.properties>, 'classes')}</h2>
  """ 

  BOX { 

    # toc
    TEMPLATE <ontology/toc.rqg>( ?onto,  ?class )
    WHERE {
      {?class a owl:Class} UNION {?class a rdfs:Class}
      FILTER( ISURI(?class) && STRSTARTS( str(?class), str(?onto) ) ) 
    } ORDER BY ?class . 

    # description
    TEMPLATE {
      "\n<div id='{fun:prefixedIRI(?class)}' class='entity'>" BOX {
        "<a name='{?class}'></a>"
        "\n<h3>" 
          TEMPLATE <ontology/label.rqg>( ?onto,  ?class ) .
            TEMPLATE { 
              ' <span class="alert alert-danger" role="alert"> &#9888; { fun:property(<en.properties>, 'deprecated') }</span>'
            } WHERE {
              ?class owl:deprecated true .
            } .
          <ontology/backlink.rqg>( ?onto, "classes", "Class") 
        "</h3>"
        "\n<p><strong>IRI:</strong> { ?class }</p>"
      
        TEMPLATE {
          before = "\n<div class='comment'><p>\n" ;
          TEMPLATE <function/formatText.rqg>( ?comment) .
          ; separator = "<br/>" ; after = "</p></div>"
        }
        WHERE {
          ?class rdfs:comment ?comment  .
        } .

        TEMPLATE <ontology/class.rqg>( ?onto, ?class ) .

      }"\n</div>"

    } DISTINCT WHERE {
      {?class a owl:Class} UNION {?class a rdfs:Class}
      FILTER( ISURI(?class) && STRSTARTS( str(?class), str(?onto) ) ) 
    } ORDER BY ?class .
  }

  "\n</div>"
}