From 5d47573bf09f55ff39d6d6402a43c8beb25cd52e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Tr=C3=B3jczak?= Date: Fri, 30 Jun 2023 14:17:46 +0200 Subject: [PATCH] Add new ontology IRI as the default namespace for 'merge' goal in OV Toolkit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rafał Trójczak --- .../toolkit/OntoViewerToolkitCommandLine.java | 11 ++++++++--- .../handlers/OntologyHandlingService.java | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 onto-viewer-toolkit/src/main/java/org/edmcouncil/spec/ontoviewer/toolkit/handlers/OntologyHandlingService.java diff --git a/onto-viewer-toolkit/src/main/java/org/edmcouncil/spec/ontoviewer/toolkit/OntoViewerToolkitCommandLine.java b/onto-viewer-toolkit/src/main/java/org/edmcouncil/spec/ontoviewer/toolkit/OntoViewerToolkitCommandLine.java index aefc22a0..4fa096ec 100644 --- a/onto-viewer-toolkit/src/main/java/org/edmcouncil/spec/ontoviewer/toolkit/OntoViewerToolkitCommandLine.java +++ b/onto-viewer-toolkit/src/main/java/org/edmcouncil/spec/ontoviewer/toolkit/OntoViewerToolkitCommandLine.java @@ -38,6 +38,7 @@ import org.edmcouncil.spec.ontoviewer.toolkit.exception.OntoViewerToolkitException; import org.edmcouncil.spec.ontoviewer.toolkit.exception.OntoViewerToolkitRuntimeException; import org.edmcouncil.spec.ontoviewer.toolkit.handlers.OntologyConsistencyChecker; +import org.edmcouncil.spec.ontoviewer.toolkit.handlers.OntologyHandlingService; import org.edmcouncil.spec.ontoviewer.toolkit.handlers.OntologyImportsMerger; import org.edmcouncil.spec.ontoviewer.toolkit.handlers.OntologyTableDataExtractor; import org.edmcouncil.spec.ontoviewer.toolkit.io.CsvWriter; @@ -47,7 +48,6 @@ import org.edmcouncil.spec.ontoviewer.toolkit.options.CommandLineOptionsHandler; import org.edmcouncil.spec.ontoviewer.toolkit.options.Goal; import org.edmcouncil.spec.ontoviewer.toolkit.options.OptionDefinition; -import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.formats.RDFXMLDocumentFormat; import org.semanticweb.owlapi.model.IRI; import org.semanticweb.owlapi.model.parameters.Imports; @@ -72,6 +72,7 @@ public class OntoViewerToolkitCommandLine implements CommandLineRunner { private final ApplicationConfigProperties applicationConfigProperties; private final FileSystemService fileSystemService; private final ResourcesPopulate resourcesPopulate; + private final OntologyHandlingService ontologyHandlingService; public OntoViewerToolkitCommandLine( ApplicationConfigurationService applicationConfigurationService, @@ -81,7 +82,9 @@ public OntoViewerToolkitCommandLine( OntologyImportsMerger ontologyImportsMerger, StandardEnvironment environment, ApplicationConfigProperties applicationConfigProperties, - FileSystemService fileSystemService, ResourcesPopulate resourcesPopulate) { + FileSystemService fileSystemService, + ResourcesPopulate resourcesPopulate, + OntologyHandlingService ontologyHandlingService) { this.applicationConfigurationService = applicationConfigurationService; this.resourcesPopulate = resourcesPopulate; // We don't need the default paths configuration in OV Toolkit @@ -94,6 +97,7 @@ public OntoViewerToolkitCommandLine( this.environment = environment; this.applicationConfigProperties = applicationConfigProperties; this.fileSystemService = fileSystemService; + this.ontologyHandlingService = ontologyHandlingService; } @Override @@ -185,13 +189,14 @@ public void run(String... args) throws Exception { newOntologyIri, newOntologyVersionIri); - var owlOntologyManager = OWLManager.createOWLOntologyManager(); + var owlOntologyManager = ontologyHandlingService.getOwlOntologyManager(); var outputOption = commandLineOptions.getOption(OUTPUT); if (outputOption.isPresent()) { var output = outputOption.get(); LOGGER.info("Saving merged ontology to '{}'...", output); RDFXMLDocumentFormat outputDocumentFormat = new RDFXMLDocumentFormat(); ontologyManager.getSourceNamespacesMap().forEach(outputDocumentFormat::setPrefix); + outputDocumentFormat.setDefaultPrefix(newOntologyIri); owlOntologyManager.saveOntology( mergedOntology, diff --git a/onto-viewer-toolkit/src/main/java/org/edmcouncil/spec/ontoviewer/toolkit/handlers/OntologyHandlingService.java b/onto-viewer-toolkit/src/main/java/org/edmcouncil/spec/ontoviewer/toolkit/handlers/OntologyHandlingService.java new file mode 100644 index 00000000..202cf018 --- /dev/null +++ b/onto-viewer-toolkit/src/main/java/org/edmcouncil/spec/ontoviewer/toolkit/handlers/OntologyHandlingService.java @@ -0,0 +1,19 @@ +package org.edmcouncil.spec.ontoviewer.toolkit.handlers; + +import org.semanticweb.owlapi.apibinding.OWLManager; +import org.semanticweb.owlapi.model.OWLOntologyManager; +import org.springframework.stereotype.Service; + +@Service +public class OntologyHandlingService { + + private final OWLOntologyManager owlOntologyManager; + + public OntologyHandlingService() { + this.owlOntologyManager = OWLManager.createOWLOntologyManager(); + } + + public OWLOntologyManager getOwlOntologyManager() { + return owlOntologyManager; + } +}