Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new ontology IRI as the default namespace for 'merge' goal in OV … #368

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}