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#>
 
BASE <https://saref.etsi.org/documentation/>

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

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

  BOX { 

    # toc
    TEMPLATE {
      before = "\n<ul class='hlist'>" ;
      BOX {
        "\n<li>"
          "\n<a href='#{fun:prefixedIRI(?individual)}' title='{fun:prefixedIRI(?individual)}'>"
          TEMPLATE <ontology/label.rqg>( ?onto,  ?individual ) .
          "</a>"
        "\n</li>"
      }
      ; after = "\n</ul>"
    } WHERE {
      ?individual a owl:NamedIndividual
      FILTER( ISURI(?individual) && STRSTARTS( str(?individual), str(?onto) ) ) 
    } ORDER BY ?individual .

    # description
    TEMPLATE {
      "\n<div id='{fun:prefixedIRI(?individual)}' class='entity'>" BOX {
        "<a name='{?individual}'></a>"
          "\n<h3>" 
            TEMPLATE <ontology/label.rqg>( ?onto,  ?individual ) .
            TEMPLATE { 
              ' <span class="alert alert-danger" role="alert">  &#9888; { fun:property(<en.properties>, 'deprecated') }</span>'
            } WHERE {
              ?individual owl:deprecated true .
            } .
            <ontology/backlink.rqg>( ?onto, "namedindividuals", "Named Individuals") 
          "</h3>"
          "\n<p><strong>IRI:</strong> { ?individual }</p>"

          TEMPLATE {
            before = "\n<div class='comment'><p>\n" ;
            TEMPLATE <function/formatText.rqg>( ?comment) .
            ; separator = "<br/>" ; after = "</p></div>"
          }
          WHERE {
            ?individual rdfs:comment ?comment  .
          } .
        
          TEMPLATE <ontology/individual.rqg>( ?onto,  ?individual ) .

      } "\n</div>"

    } WHERE {
      {
        ?individual a owl:NamedIndividual
      } UNION {
        ?individual rdf:type ?class .
        ?class a owl:Class .
      }
      FILTER( ISURI(?individual) && STRSTARTS( str(?individual), str(?onto) ) ) 
    } GROUP BY ?onto ?individual ORDER BY ?individual . 

  }
  "\n</div>"

}