PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX voaf: <http://purl.org/vocommons/voaf#>
PREFIX dc:   <http://purl.org/dc/terms/>
PREFIX vann: <http://purl.org/vocab/vann/>
PREFIX st: <http://ns.inria.fr/sparql-template/>
PREFIX doc: <https://w3id.org/seas/documentation/html/loweringRule#>
TEMPLATE doc:ontology {
        
    st:call-template(doc:title, ?ontology)
    "- **This version:** " str(?versionInfo) " - " str(?versionUri) "\n"
    "- **Latest published version:** " str(?ontology) "\n"        
    st:call-template(doc:priorversion, ?ontology)
    st:call-template(doc:authors, ?ontology, dc:creator, "Authors")
    st:call-template(doc:authors, ?ontology, dc:contributor, "Contributors")
    st:call-template(doc:date, ?ontology, dc:issued, "Issued")
    st:call-template(doc:date, ?ontology, dc:modified, "Modified")
    st:call-template(doc:imports, ?ontology, ?ns)
    "- **Other visualizations:** [VOWL](http://vowl.visualdataweb.org/webvowl/#iri=" str(?versionUri) ".rdf), [Turtle](" str(?versionUri) ".ttl),  [RDF/XML](" str(?versionUri) ".rdf).\n"
    st:call-template(doc:license, ?ontology)
    "\n"
    st:call-template(doc:description, ?ontology)
    st:call-template(doc:classes, ?ontology, ?ns, owl:Class, "### Classes\n")
    st:call-template(doc:classes, ?ontology, ?ns, owl:ObjectProperty, "### Object Properties\n")
    st:call-template(doc:classes, ?ontology, ?ns, owl:DatatypeProperty, "### Data Properties\n")
    st:call-template(doc:instance, ?ontology, ?ns)
} WHERE { 
    ?ontology a owl:Ontology , voaf:Vocabulary ;
      dc:title ?title ;
      vann:preferredNamespacePrefix ?prefix ;
      vann:preferredNamespaceUri ?ns ;  
      owl:versionIRI ?versionUri ;
      owl:versionInfo ?versionInfo .
    
    OPTIONAL { ?ontology  dc:issued ?issued . }
    OPTIONAL { ?ontology  dc:modified ?modified . }
    
    BIND( IF(BOUND(?issued), CONCAT( ", **issued:**", str(?issued), "\n\n"), "") AS ?htmlissued)
    BIND( IF(BOUND(?modified), CONCAT( ", **modified:**", str(?modified), "\n\n"), "") AS ?htmlmodified)
}