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 xsd: <http://www.w3.org/2001/XMLSchema#>

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

# See https://www.w3.org/TR/owl2-quick-reference/#Individuals_.26_Literals
TEMPLATE  <ontology/individualAndLiteralDescription.rqg>( ?onto,  ?object ) {

  # named individual
  TEMPLATE {
    "<a href='{IF( STRSTARTS( STR(?object), STR(?onto)), "#{fun:prefixedIRI(?object)}", ?object )}' title='{ st:call-template(<ontology/label.rqg>, ?onto,  ?object ) }: {?commentStr}'>{fun:prefixedIRI(?object)}</a>"
    "<sup title='{ fun:property(<en.properties>, 'namedindividual') }' class='type-ni'>ni</sup>"
  } WHERE { 
    FILTER(ISURI(?object))
    OPTIONAL {?object rdfs:comment ?comment }
    BIND( IF(BOUND(?comment), ?comment, "<<no comment>>") AS ?commentStr )
  } LIMIT 1 .

  # anonymous individual
  TEMPLATE {
    "<strong>Anonymous individual. TODO</strong>"
  } WHERE {
    FILTER(ISBLANK(?object))
  } .

  # literal
  TEMPLATE {
    "\"" STR( ?object ) "\"" 
    
    TEMPLATE {
      "^^{ TEMPLATE <ontology/dataRangeDescription.rqg>( ?onto, DATATYPE( ?object ) ) . }"
    } WHERE {
      FILTER( DATATYPE(?object) != rdf:langString 
        && DATATYPE(?object) != xsd:string )
    } .

    TEMPLATE {
      "@{ LANG(?object) }"
    } WHERE {
      FILTER( DATATYPE(?object) = rdf:langString )
    } .

  } WHERE {
    FILTER(ISLITERAL(?object))
  } .

}