66import io .swagger .v3 .oas .models .media .StringSchema ;
77import io .swagger .v3 .oas .models .media .XML ;
88import org .semanticweb .owlapi .apibinding .OWLManager ;
9- import org .semanticweb .owlapi .formats .RDFXMLDocumentFormat ;
109import org .semanticweb .owlapi .model .*;
1110
1211import static edu .isi .oba .Oba .logger ;
1312
1413import java .io .File ;
1514import java .io .IOException ;
16- import java .io .InputStream ;
1715import java .nio .file .Files ;
1816import java .nio .file .StandardCopyOption ;
1917import java .util .*;
2018import java .util .logging .Level ;
2119import java .util .logging .Logger ;
2220import java .util .stream .Collectors ;
23- import org .semanticweb .owlapi .formats .TurtleDocumentFormat ;
2421
2522class Mapper {
2623 public static final String DEFAULT_DIR_QUERY = "_default_" ;
27- public final Map <IRI , String > schemaNames = new HashMap <>();
24+ public final Map <IRI , String > schemaNames = new HashMap <>(); //URI-names of the schemas
25+ public final Map <IRI , String > schemaDescriptions = new HashMap <>(); //URI-description of the schemas
2826 public Map <String , Schema > schemas = new HashMap <>();
2927 final Paths paths = new Paths ();
3028 List <String > selected_paths ;
@@ -61,6 +59,7 @@ public Mapper(YamlConfig config_data) throws OWLOntologyCreationException {
6159 for (OWLOntology ontology : ontologies ) {
6260 Set <OWLClass > classes = ontology .getClassesInSignature ();
6361 setSchemaNames (classes );
62+ setSchemaDrescriptions (classes ,ontology );
6463 }
6564 if (config_data .getClasses () != null )
6665 this .selected_classes = filter_classes ();
@@ -158,7 +157,7 @@ private List<OWLClass> add_owlclass_to_openapi(Query query, Path pathGenerator,
158157 List <OWLClass > ref = new ArrayList <>();
159158 String classPrefixIRI = cls .getIRI ().getNamespace ();
160159 if (defaultOntologyPrefixIRI .equals (classPrefixIRI )) {
161- MapperSchema mapperSchema = getMapperSchema (query , ontology , cls );
160+ MapperSchema mapperSchema = getMapperSchema (query , ontology , cls , this . schemaDescriptions . get ( cls . getIRI ()) );
162161
163162 for (OWLClass ref_class : mapperSchema .getProperties_range ()) {
164163 if (this .mapped_classes .contains (ref_class )){
@@ -167,7 +166,7 @@ private List<OWLClass> add_owlclass_to_openapi(Query query, Path pathGenerator,
167166 for (OWLOntology temp_ontology : this .ontologies ) {
168167 if ( follow_references ) {
169168 this .mapped_classes .add (ref_class );
170- getMapperSchema (query , temp_ontology , ref_class );
169+ getMapperSchema (query , temp_ontology , ref_class , this . schemaDescriptions . get ( ref_class . getIRI ()) );
171170 OWLDocumentFormat format = ontology .getFormat ();
172171 //String temp_defaultOntologyPrefixIRI = ((RDFXMLDocumentFormat) format).getDefaultPrefix();
173172 String temp_defaultOntologyPrefixIRI = format .asPrefixOWLDocumentFormat ().getDefaultPrefix ();
@@ -184,9 +183,9 @@ private List<OWLClass> add_owlclass_to_openapi(Query query, Path pathGenerator,
184183 return ref ;
185184 }
186185
187- private MapperSchema getMapperSchema (Query query , OWLOntology ontology , OWLClass cls ) {
186+ private MapperSchema getMapperSchema (Query query , OWLOntology ontology , OWLClass cls , String cls_description ) {
188187 //Convert from OWL Class to OpenAPI Schema.
189- MapperSchema mapperSchema = new MapperSchema (this .ontologies , cls , schemaNames , ontology , follow_references );
188+ MapperSchema mapperSchema = new MapperSchema (this .ontologies , cls , cls_description , schemaNames , ontology , follow_references );
190189 //Write queries
191190 query .write_readme (mapperSchema .name );
192191 //Create the OpenAPI schema
@@ -207,21 +206,37 @@ private void setSchemaNames(Set<OWLClass> classes) {
207206 schemaNames .put (cls .getIRI (), cls .getIRI ().getShortForm ());
208207 }
209208 }
209+
210+ /**
211+ * Given a set of classes from an ontology, this method initializes
212+ * schemaDescriptions with the definitions used to describe an ontology (if provided)
213+ * @param classes the classes you want the description for
214+ * @param ontology the ontology from where we will extract the descriptions
215+ */
216+ private void setSchemaDrescriptions (Set <OWLClass > classes ,OWLOntology ontology ){
217+ for (OWLClass cls : classes ) {
218+ System .out .println (cls );
219+ schemaDescriptions .put (cls .getIRI (), ObaUtils .getDescription (cls , ontology ));
220+ }
221+ }
210222
211223 private void add_path (Path pathGenerator , MapperSchema mapperSchema ) {
212224 String singular_name = "/" + mapperSchema .name .toLowerCase () + "s/{id}" ;
213225 String plural_name = "/" + mapperSchema .name .toLowerCase () + "s" ;
214226 //Create the plural paths: for example: /models/
215- this .paths .addPathItem (plural_name , pathGenerator .generate_plural (mapperSchema .name ));
227+ this .paths .addPathItem (plural_name , pathGenerator .generate_plural (mapperSchema .name ,
228+ mapperSchema .getCls ().getIRI ().getIRIString ()));
216229 //Create the plural paths: for example: /models/id
217- this .paths .addPathItem (singular_name , pathGenerator .generate_singular (mapperSchema .name ));
230+ this .paths .addPathItem (singular_name , pathGenerator .generate_singular (mapperSchema .name ,
231+ mapperSchema .getCls ().getIRI ().getIRIString ()));
218232 }
219233
220- private void add_path_relation (Path pathGenerator , String schema_name , String predicate , String path ) {
221- String relation = "/" + schema_name .toLowerCase () + "s/{id}/" + path ;
222- this .paths .addPathItem (relation , pathGenerator .generate_plural (schema_name ));
223-
224- }
234+ // Method not used
235+ // private void add_path_relation(Path pathGenerator, String schema_name, String predicate, String path) {
236+ // String relation = "/" + schema_name.toLowerCase() + "s/{id}/" + path;
237+ // this.paths.addPathItem(relation, pathGenerator.generate_plural(schema_name));
238+ //
239+ // }
225240
226241 public List <OWLClass > filter_classes () {
227242 List <String > selected_classes_iri = this .config_data .getClasses ();
0 commit comments