Commit 952a67ae authored by Maxime Lefrançois's avatar Maxime Lefrançois
Browse files

better html documentation

parent 8e62f383
Loading
Loading
Loading
Loading
+81 −1
Original line number Diff line number Diff line
@@ -28,12 +28,23 @@ package fr.emse.gitlab.saref.managers;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.StringWriter;

import org.apache.commons.io.FileUtils;
import org.apache.jena.atlas.io.IndentedWriter;
import org.apache.jena.query.Dataset;
import org.apache.jena.query.DatasetFactory;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.Property;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.vocabulary.OWL2;
import org.apache.jena.vocabulary.RDF;
import org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom;
import org.semanticweb.owlapi.model.OWLAnnotationValue;
import org.semanticweb.owlapi.model.OWLLiteral;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.parameters.Imports;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@@ -127,7 +138,76 @@ public class VersionSiteManager extends SAREFRepositoryVersionErrorLogger {

	private void generateHTMLFile() throws SAREFPipelineException {
		Dataset dataset = DatasetFactory.create();
		dataset.addNamedModel(version.getIRI(), version.getModel());
		Model model = ModelFactory.createDefaultModel();
		model.add(version.getModel());

		OWLOntology ontology = ontologyManager.loadOntology(version, errorLogger);
		ontology.classesInSignature(Imports.INCLUDED).forEach(c->{
			if(ontology.isDeclared(c)) {
				return;
			}
			Resource r = model.getResource(c.getIRI().toString());
			model.add(r, RDF.type, OWL2.Class);
			ontology.annotationAssertionAxioms(c.getIRI(), Imports.INCLUDED).forEach(axiom->{
				Property p = model.getProperty(axiom.getProperty().getIRI().toString());
				OWLAnnotationValue value = axiom.getValue();
				if(value instanceof OWLLiteral) {
					OWLLiteral literal = (OWLLiteral) value;
					model.add(r, p, literal.getLiteral());
				}
				
			});;
		});		
		ontology.objectPropertiesInSignature(Imports.INCLUDED).forEach(op->{
			if(ontology.isDeclared(op)) {
				return;
			}
			Resource r = model.getResource(op.getIRI().toString());
			model.add(r, RDF.type, OWL2.ObjectProperty);
			ontology.annotationAssertionAxioms(op.getIRI(), Imports.INCLUDED).forEach(axiom->{
				Property p = model.getProperty(axiom.getProperty().getIRI().toString());
				OWLAnnotationValue value = axiom.getValue();
				if(value instanceof OWLLiteral) {
					OWLLiteral literal = (OWLLiteral) value;
					model.add(r, p, literal.getLiteral());
				}
				
			});;
		});
		ontology.dataPropertiesInSignature(Imports.INCLUDED).forEach(dp->{
			if(ontology.isDeclared(dp)) {
				return;
			}
			Resource r = model.getResource(dp.getIRI().toString());
			model.add(r, RDF.type, OWL2.DatatypeProperty);
			ontology.annotationAssertionAxioms(dp.getIRI(), Imports.INCLUDED).forEach(axiom->{
				Property p = model.getProperty(axiom.getProperty().getIRI().toString());
				OWLAnnotationValue value = axiom.getValue();
				if(value instanceof OWLLiteral) {
					OWLLiteral literal = (OWLLiteral) value;
					model.add(r, p, literal.getLiteral());
				}
				
			});;
		});
		ontology.individualsInSignature(Imports.INCLUDED).forEach(i->{
			if(ontology.isDeclared(i)) {
				return;
			}
			Resource r = model.getResource(i.getIRI().toString());
			model.add(r, RDF.type, OWL2.NamedIndividual);
			ontology.annotationAssertionAxioms(i.getIRI(), Imports.INCLUDED).forEach(axiom->{
				Property p = model.getProperty(axiom.getProperty().getIRI().toString());
				OWLAnnotationValue value = axiom.getValue();
				if(value instanceof OWLLiteral) {
					OWLLiteral literal = (OWLLiteral) value;
					model.add(r, p, literal.getLiteral());
				}
				
			});;
		});
		
		dataset.addNamedModel(version.getIRI(), model);
		String htmlFileName = String.format("%s.html", repository.getOntologyFileName());
		File file = new File(ontoDir, htmlFileName);
		try (IndentedWriter writer = new IndentedWriter(new FileOutputStream(file))) {
+5 −5
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

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

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

  COALESCE( ?html, fun:markdownToHTML(?md), 
    IF( st:call-template( <function/formatText.rqg>,  ?description_en ) != "" , st:call-template( <function/formatText.rqg>,  ?description_en ) , ?undef ), 
@@ -17,11 +17,11 @@ SOURCE <abstract.html> AS ?html
SOURCE <abstract.md> AS ?md
WHERE {
  OPTIONAL { 
    ?ontology dcterms:abstract ?description_en .
    ?onto dcterms:abstract ?description_en .
    FILTER (LANG(?description_en)="en")
  }
  OPTIONAL { 
    ?ontology dcterms:abstract ?description .
    ?onto dcterms:abstract ?description .
    FILTER ( DATATYPE(?description) = xsd:string )
  }
}
+1 −1
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@ PREFIX schema: <http://schema.org/>

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

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

  IF( ISURI(?affiliation) && BOUND(?name) , " (<a href='{?affiliation}'>{ ?name }</a>)", "" )
  IF( ISURI(?affiliation) && !BOUND(?name), " (<a href='{?affiliation}'>&lt;{ ?affiliation }&gt;</a>)", "" )
+1 −1
Original line number Diff line number Diff line
@@ -2,6 +2,6 @@ BASE <https://saref.etsi.org/documentation/>

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

FUNCTION <ontology/backlink.rqg>(?anchor, ?name ){
FUNCTION <ontology/backlink.rqg>( ?onto, ?anchor, ?name ){
  "<span class='backlink'> back to <a href='#toc'>ToC</a> or <a href='#{?anchor}'>{?name} ToC</a></span>"
}
 No newline at end of file
+9 −9
Original line number Diff line number Diff line
@@ -13,22 +13,22 @@ PREFIX iter: <http://w3id.org/sparql-generate/iter/>

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

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

""" 
<div class='description'><dl>{st:incr()}

{ TEMPLATE <ontology/classDescriptionSubjectObject.rqg>( ?class, "isequivalentto", owl:equivalentClass) . }
{ TEMPLATE <ontology/classDescriptionSubject.rqg>( ?class, 'hassuperclasses', rdfs:subClassOf) . }
{ TEMPLATE <ontology/classDescriptionObject.rqg>( ?class, "hassubclasses", rdfs:subClassOf) . }
{ TEMPLATE <ontology/classDescriptionObject.rqg>( ?class, "isindomainof", rdfs:domain) . }
{ TEMPLATE <ontology/classDescriptionObject.rqg>( ?class, "isinrangeof", rdfs:range)   . }
{ TEMPLATE <ontology/classDescriptionSubjectObject.rqg>( ?class, "isdisjointwith", owl:disjointWith)   . } 
{ TEMPLATE <ontology/classDescriptionSubjectObject.rqg>( ?onto,  ?class, "isequivalentto", owl:equivalentClass) . }
{ TEMPLATE <ontology/classDescriptionSubject.rqg>( ?onto,  ?class, 'hassuperclasses', rdfs:subClassOf) . }
{ TEMPLATE <ontology/classDescriptionObject.rqg>( ?onto,  ?class, "hassubclasses", rdfs:subClassOf) . }
{ TEMPLATE <ontology/classDescriptionObject.rqg>( ?onto,  ?class, "isindomainof", rdfs:domain) . }
{ TEMPLATE <ontology/classDescriptionObject.rqg>( ?onto,  ?class, "isinrangeof", rdfs:range)   . }
{ TEMPLATE <ontology/classDescriptionSubjectObject.rqg>( ?onto,  ?class, "isdisjointwith", owl:disjointWith)   . } 
"""

TEMPLATE { 
  before = "\n<dt>{ fun:property(<en.properties>, "hasmembers") }</dt><dd>" ;
    TEMPLATE <ontology/individualAndLiteralDescription.rqg>( ?member ) . 
    TEMPLATE <ontology/individualAndLiteralDescription.rqg>( ?onto,  ?member ) . 
  ; separator = ", "
  ; after = "</dd>"
} 
@@ -40,7 +40,7 @@ WHERE {
# # keys
# TEMPLATE {
#   before = "\n<dt>{ fun:property(<en.properties>, "haskeys") }</dt><dd>" ;
#     TEMPLATE <ontology/propertyDescription.rqg>( <en.properties> , ?key ) . 
#     TEMPLATE <ontology/propertyDescription.rqg>( ?onto , ?key ) . 
#   ; separator = ", "
#   ; after = "</dd>"
# } WHERE {
Loading