Commit d1a1595b authored by Maxime Lefrançois's avatar Maxime Lefrançois

better term documentation

parent 952a67ae
......@@ -34,8 +34,16 @@ import org.apache.jena.query.Dataset;
import org.apache.jena.query.DatasetFactory;
import org.apache.jena.query.QueryExecutionFactory;
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.apache.jena.vocabulary.RDFS;
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;
......@@ -130,10 +138,76 @@ public class TermSiteManager extends SAREFRepositoryErrorLogger {
Dataset dataset = DatasetFactory.create();
dataset.addNamedModel(term.getIRI(), term.getModel());
SAREFVersion lastVersion = term.getRepository().getVersions().lastEntry().getValue();
dataset.addNamedModel(lastVersion.getIRI(), lastVersion.getModel());
term.getIsDefinedBy().forEach(version->{
dataset.addNamedModel(version.getIRI(), version.getModel());
Model lastVersionModel = ModelFactory.createDefaultModel();
lastVersionModel.add(lastVersion.getModel());
OWLOntology ontology = ontologyManager.loadOntology(lastVersion, errorLogger);
ontology.classesInSignature(Imports.INCLUDED).forEach(c->{
if(ontology.isDeclared(c)) {
return;
}
Resource r = lastVersionModel.getResource(c.getIRI().toString());
lastVersionModel.add(r, RDF.type, OWL2.Class);
ontology.annotationAssertionAxioms(c.getIRI(), Imports.INCLUDED).forEach(axiom->{
Property p = lastVersionModel.getProperty(axiom.getProperty().getIRI().toString());
OWLAnnotationValue value = axiom.getValue();
if(value instanceof OWLLiteral) {
OWLLiteral literal = (OWLLiteral) value;
lastVersionModel.add(r, p, literal.getLiteral());
}
});;
});
ontology.objectPropertiesInSignature(Imports.INCLUDED).forEach(op->{
if(ontology.isDeclared(op)) {
return;
}
Resource r = lastVersionModel.getResource(op.getIRI().toString());
lastVersionModel.add(r, RDF.type, OWL2.ObjectProperty);
ontology.annotationAssertionAxioms(op.getIRI(), Imports.INCLUDED).forEach(axiom->{
Property p = lastVersionModel.getProperty(axiom.getProperty().getIRI().toString());
OWLAnnotationValue value = axiom.getValue();
if(value instanceof OWLLiteral) {
OWLLiteral literal = (OWLLiteral) value;
lastVersionModel.add(r, p, literal.getLiteral());
}
});;
});
ontology.dataPropertiesInSignature(Imports.INCLUDED).forEach(dp->{
if(ontology.isDeclared(dp)) {
return;
}
Resource r = lastVersionModel.getResource(dp.getIRI().toString());
lastVersionModel.add(r, RDF.type, OWL2.DatatypeProperty);
ontology.annotationAssertionAxioms(dp.getIRI(), Imports.INCLUDED).forEach(axiom->{
Property p = lastVersionModel.getProperty(axiom.getProperty().getIRI().toString());
OWLAnnotationValue value = axiom.getValue();
if(value instanceof OWLLiteral) {
OWLLiteral literal = (OWLLiteral) value;
lastVersionModel.add(r, p, literal.getLiteral());
}
});;
});
ontology.individualsInSignature(Imports.INCLUDED).forEach(i->{
if(ontology.isDeclared(i)) {
return;
}
Resource r = lastVersionModel.getResource(i.getIRI().toString());
lastVersionModel.add(r, RDF.type, OWL2.NamedIndividual);
ontology.annotationAssertionAxioms(i.getIRI(), Imports.INCLUDED).forEach(axiom->{
Property p = lastVersionModel.getProperty(axiom.getProperty().getIRI().toString());
OWLAnnotationValue value = axiom.getValue();
if(value instanceof OWLLiteral) {
OWLLiteral literal = (OWLLiteral) value;
lastVersionModel.add(r, p, literal.getLiteral());
}
});;
});
dataset.addNamedModel(lastVersion.getIRI(), lastVersionModel);
String htmlFileName = String.format("%s.html", term.getLocalName());
File file = new File(ontoDir, htmlFileName);
try (IndentedWriter writer = new IndentedWriter(new FileOutputStream(file))) {
......
......@@ -59,15 +59,17 @@ TEMPLATE <term/propertyDescription.rqg>( ?property ) {
# named data property
TEMPLATE {
"<a href='{?property}' title='{?property}'>{fun:prefixedIRI(?property)}</a>"
"<a href='{ ?property }' title='{ st:call-template( <ontology/label.rqg>, ?onto, ?property ) }: {?commentStr}'>{fun:prefixedIRI(?property)}</a>"
"<sup title='{ fun:property(<en.properties>, 'dataproperty') }' class='type-dp'>dp</sup>"
}
}
WHERE {
FILTER(ISURI(?property))
?property a owl:DatatypeProperty
OPTIONAL { ?property rdfs:comment ?comment }
FILTER (?property != owl:topDataProperty)
FILTER (?property != owl:bottomDataProperty)
} .
BIND( IF(BOUND(?comment), ?comment, "<<no comment>>") AS ?commentStr )
} LIMIT 1 .
# universal data property
TEMPLATE {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment