Skip to content

Commit

Permalink
Merge pull request #368 from edmcouncil/362-fix-wrong-namespaces-for-…
Browse files Browse the repository at this point in the history
…merge-imports

Add new ontology IRI as the default namespace for 'merge' goal in OV …
  • Loading branch information
mereolog authored Sep 22, 2023
2 parents 1c8b413 + 5d47573 commit 72a96f4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -94,6 +97,7 @@ public OntoViewerToolkitCommandLine(
this.environment = environment;
this.applicationConfigProperties = applicationConfigProperties;
this.fileSystemService = fileSystemService;
this.ontologyHandlingService = ontologyHandlingService;
}

@Override
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 72a96f4

Please sign in to comment.