diff --git a/scripts/java/application.yaml b/scripts/java/application.yaml index 63e0e60f..eedf09f2 100644 --- a/scripts/java/application.yaml +++ b/scripts/java/application.yaml @@ -1,10 +1,11 @@ ontology: - directory: ../../owl/ - to-collapse: + directory: ../../owl/ # where to load the ontologies from + format: rdf_xml # which format to use (optional - if not given, the default format will be used). Possible Values: xml, owl_xml, functional, manchester (the latter is not recommended because GCIs will get lost). Parameter is not case sensitive. + to-collapse: # which ontologies to collapse - ontology: SOMA-All out-path: ../../build/owl/current/SOMA.owl - except: DUL - new-iri: https://ease-crc.github.io/soma/owl/current/SOMA.owl + except: DUL # Optional, which ontologies should not be merged but still be imported + new-iri: https://ease-crc.github.io/soma/owl/current/SOMA.owl # Optional, if the IRI of the collapsed version should be different from the original - ontology: SOMA-HOME out-path: ../../build/owl/current/SOMA-HOME.owl except: DUL \ No newline at end of file diff --git a/scripts/java/src/main/java/main/Application.java b/scripts/java/src/main/java/main/Application.java index c3bbcc38..478c733a 100644 --- a/scripts/java/src/main/java/main/Application.java +++ b/scripts/java/src/main/java/main/Application.java @@ -1,11 +1,13 @@ package main; +import main.config.CollapseConfig; +import main.config.OntologyConfig; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.properties.EnableConfigurationProperties; @SpringBootApplication -@EnableConfigurationProperties({CollapseConfig.class,OntologyConfig.class}) +@EnableConfigurationProperties({CollapseConfig.class, OntologyConfig.class}) public class Application { public static void main(final String... args) { diff --git a/scripts/java/src/main/java/main/CIRunner.java b/scripts/java/src/main/java/main/CIRunner.java new file mode 100644 index 00000000..bd419132 --- /dev/null +++ b/scripts/java/src/main/java/main/CIRunner.java @@ -0,0 +1,32 @@ +package main; + +import main.ci_runners.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.stereotype.Component; + +@Component +public class CIRunner implements CommandLineRunner { + + @Autowired + private Collapser collapser; + + @Autowired + private IsDefinedInAdder isDefinedInAdder; + + @Autowired + private VersionInfoAdder versionInfoAdder; + + @Autowired + private OntologySaver ontologySaver; + + + @Override + public void run(final String... args) throws Exception { + final CIRunnable[] toRun = {isDefinedInAdder, versionInfoAdder, collapser, ontologySaver}; + for (final var next : toRun) { + next.run(); + } + } + +} diff --git a/scripts/java/src/main/java/main/OntologyManager.java b/scripts/java/src/main/java/main/OntologyManager.java index cd5a6abf..dd4577d4 100644 --- a/scripts/java/src/main/java/main/OntologyManager.java +++ b/scripts/java/src/main/java/main/OntologyManager.java @@ -1,5 +1,6 @@ package main; +import main.config.OntologyConfig; import org.protege.xmlcatalog.owlapi.XMLCatalogIRIMapper; import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.model.*; diff --git a/scripts/java/src/main/java/main/VersionInfoAdder.java b/scripts/java/src/main/java/main/VersionInfoAdder.java deleted file mode 100644 index ec4ffb04..00000000 --- a/scripts/java/src/main/java/main/VersionInfoAdder.java +++ /dev/null @@ -1,52 +0,0 @@ -package main; - -import org.semanticweb.owlapi.apibinding.OWLManager; -import org.semanticweb.owlapi.model.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.CommandLineRunner; -import org.springframework.stereotype.Component; - -import javax.annotation.Priority; - -@Component -@Priority(1) -public class VersionInfoAdder implements CommandLineRunner { - - - /** - * {@link Logger} of this class. - */ - private static final Logger LOGGER = LoggerFactory.getLogger(VersionInfoAdder.class); - - private final OntologyManager ontologyManager; - - @Value("${versionInfo}") - private String versionInfo; - - @Autowired - public VersionInfoAdder(final OntologyManager ontologyManager) { - this.ontologyManager = ontologyManager; - } - - - @Override - public void run(final String... args) { - for (final OWLOntology ontology : ontologyManager.getOntologyManager().getOntologies()) { - addVersionInfo(ontology, versionInfo); - } - } - - private static void addVersionInfo(final OWLOntology ontology, String version) { - - final var df = OWLManager.getOWLDataFactory(); - final var versionAnnotation = df.getOWLAnnotation(df.getOWLVersionInfo(), df.getOWLLiteral(version)); - ontology.getOWLOntologyManager().applyChange(new AddOntologyAnnotation(ontology, versionAnnotation)); - - LOGGER.info("Added versionInfo {} to {}", version, ontology.getOntologyID().getOntologyIRI()); - } - - -} diff --git a/scripts/java/src/main/java/main/ci_runners/CIRunnable.java b/scripts/java/src/main/java/main/ci_runners/CIRunnable.java new file mode 100644 index 00000000..763828a8 --- /dev/null +++ b/scripts/java/src/main/java/main/ci_runners/CIRunnable.java @@ -0,0 +1,6 @@ +package main.ci_runners; + +public interface CIRunnable { + + void run() throws Exception; +} diff --git a/scripts/java/src/main/java/main/Collapser.java b/scripts/java/src/main/java/main/ci_runners/Collapser.java similarity index 92% rename from scripts/java/src/main/java/main/Collapser.java rename to scripts/java/src/main/java/main/ci_runners/Collapser.java index 88f2d980..c9262aa4 100644 --- a/scripts/java/src/main/java/main/Collapser.java +++ b/scripts/java/src/main/java/main/ci_runners/Collapser.java @@ -1,5 +1,8 @@ -package main; +package main.ci_runners; +import main.OntologyManager; +import main.config.CollapseConfig; +import main.config.OntologyConfig; import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.model.*; import org.semanticweb.owlapi.model.parameters.Imports; @@ -7,19 +10,16 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.CommandLineRunner; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; -import javax.annotation.Priority; import java.io.IOException; import java.util.Collection; import java.util.Optional; import java.util.function.Supplier; @Component -@Priority(Integer.MAX_VALUE - 1) -public class Collapser implements CommandLineRunner { +public class Collapser implements CIRunnable { /** * {@link Logger} of this class. @@ -40,8 +40,7 @@ public Collapser(final OntologyManager ontologyManager, final OntologyConfig ont } @Override - public void run(final String... args) - throws OWLOntologyStorageException, OWLOntologyCreationException, IOException { + public void run() throws OWLOntologyCreationException, IOException, OWLOntologyStorageException { for (final var collapseConfig : ontologyConfig.toCollapse()) { collapse(collapseConfig); } diff --git a/scripts/java/src/main/java/main/IsDefinedInAdder.java b/scripts/java/src/main/java/main/ci_runners/IsDefinedInAdder.java similarity index 90% rename from scripts/java/src/main/java/main/IsDefinedInAdder.java rename to scripts/java/src/main/java/main/ci_runners/IsDefinedInAdder.java index dd18360e..86926080 100644 --- a/scripts/java/src/main/java/main/IsDefinedInAdder.java +++ b/scripts/java/src/main/java/main/ci_runners/IsDefinedInAdder.java @@ -1,5 +1,6 @@ -package main; +package main.ci_runners; +import main.OntologyManager; import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.model.AxiomType; import org.semanticweb.owlapi.model.OWLDeclarationAxiom; @@ -9,16 +10,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.CommandLineRunner; import org.springframework.stereotype.Component; -import javax.annotation.Priority; import java.util.Collection; import java.util.HashSet; @Component -@Priority(0) -public class IsDefinedInAdder implements CommandLineRunner { +public class IsDefinedInAdder implements CIRunnable { /** * {@link Logger} of this class. @@ -34,7 +32,7 @@ public IsDefinedInAdder(final OntologyManager ontologyManager) { @Override - public void run(final String... args) { + public void run() { for (final OWLOntology ontology : ontologyManager.getOntologyManager().getOntologies()) { addIsDefinedIn(ontology); } diff --git a/scripts/java/src/main/java/main/OntologySaver.java b/scripts/java/src/main/java/main/ci_runners/OntologySaver.java similarity index 60% rename from scripts/java/src/main/java/main/OntologySaver.java rename to scripts/java/src/main/java/main/ci_runners/OntologySaver.java index a901b34d..4e6c5380 100644 --- a/scripts/java/src/main/java/main/OntologySaver.java +++ b/scripts/java/src/main/java/main/ci_runners/OntologySaver.java @@ -1,36 +1,40 @@ -package main; +package main.ci_runners; +import main.OntologyManager; +import main.config.OntologyConfig; import org.semanticweb.owlapi.model.OWLOntology; import org.semanticweb.owlapi.model.OWLOntologyStorageException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.CommandLineRunner; import org.springframework.stereotype.Component; -import javax.annotation.Priority; - @Component -@Priority(Integer.MAX_VALUE - 1) -public class OntologySaver implements CommandLineRunner { +public class OntologySaver implements CIRunnable { /** * {@link Logger} of this class. */ private static final Logger LOGGER = LoggerFactory.getLogger(OntologySaver.class); private final OntologyManager ontologyManager; + private final OntologyConfig ontologyConfig; @Autowired - public OntologySaver(final OntologyManager ontologyManager) { + public OntologySaver(final OntologyManager ontologyManager, final OntologyConfig ontologyConfig) { this.ontologyManager = ontologyManager; + this.ontologyConfig = ontologyConfig; } @Override - public void run(final String... args) throws OWLOntologyStorageException { + public void run() throws OWLOntologyStorageException { for (final OWLOntology ontology : ontologyManager.getOntologyManager().getOntologies()) { LOGGER.info("Saving {}", ontology.getOntologyID().getOntologyIRI().map(Object::toString) .orElseGet(() -> "unnamed ontology")); - ontology.saveOntology(); + if (ontologyConfig.format() == null) { + ontology.saveOntology(); + } else { + ontology.saveOntology(ontologyConfig.format()); + } } } } diff --git a/scripts/java/src/main/java/main/ci_runners/VersionInfoAdder.java b/scripts/java/src/main/java/main/ci_runners/VersionInfoAdder.java new file mode 100644 index 00000000..b07840cf --- /dev/null +++ b/scripts/java/src/main/java/main/ci_runners/VersionInfoAdder.java @@ -0,0 +1,51 @@ +package main.ci_runners; + +import main.OntologyManager; +import org.semanticweb.owlapi.apibinding.OWLManager; +import org.semanticweb.owlapi.model.AddOntologyAnnotation; +import org.semanticweb.owlapi.model.OWLOntology; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component +public class VersionInfoAdder implements CIRunnable { + + + /** + * {@link Logger} of this class. + */ + private static final Logger LOGGER = LoggerFactory.getLogger(VersionInfoAdder.class); + + private final OntologyManager ontologyManager; + + + private final String versionInfo; + + @Autowired + public VersionInfoAdder(final OntologyManager ontologyManager, @Value("${versionInfo}") final String versionInfo) { + this.ontologyManager = ontologyManager; + this.versionInfo = versionInfo; + } + + + @Override + public void run() { + for (final OWLOntology ontology : ontologyManager.getOntologyManager().getOntologies()) { + addVersionInfo(ontology, versionInfo); + } + } + + private static void addVersionInfo(final OWLOntology ontology, final String version) { + + final var df = OWLManager.getOWLDataFactory(); + final var versionAnnotation = df.getOWLAnnotation(df.getOWLVersionInfo(), df.getOWLLiteral(version)); + ontology.getOWLOntologyManager().applyChange(new AddOntologyAnnotation(ontology, versionAnnotation)); + + LOGGER.info("Added versionInfo {} to {}", version, ontology.getOntologyID().getOntologyIRI()); + } + + +} diff --git a/scripts/java/src/main/java/main/CollapseConfig.java b/scripts/java/src/main/java/main/config/CollapseConfig.java similarity index 97% rename from scripts/java/src/main/java/main/CollapseConfig.java rename to scripts/java/src/main/java/main/config/CollapseConfig.java index 6e9721cb..be34bf94 100644 --- a/scripts/java/src/main/java/main/CollapseConfig.java +++ b/scripts/java/src/main/java/main/config/CollapseConfig.java @@ -1,4 +1,4 @@ -package main; +package main.config; import org.semanticweb.owlapi.model.HasOntologyID; import org.semanticweb.owlapi.model.IRI; diff --git a/scripts/java/src/main/java/main/OntologyConfig.java b/scripts/java/src/main/java/main/config/OntologyConfig.java similarity index 66% rename from scripts/java/src/main/java/main/OntologyConfig.java rename to scripts/java/src/main/java/main/config/OntologyConfig.java index bcfcef2e..bf304799 100644 --- a/scripts/java/src/main/java/main/OntologyConfig.java +++ b/scripts/java/src/main/java/main/config/OntologyConfig.java @@ -1,5 +1,6 @@ -package main; +package main.config; +import org.semanticweb.owlapi.model.OWLDocumentFormat; import org.springframework.boot.context.properties.ConfigurationProperties; import java.nio.file.Path; @@ -7,6 +8,6 @@ @ConfigurationProperties(prefix = "ontology") -public record OntologyConfig(Path directory, Collection toCollapse) { +public record OntologyConfig(Path directory, Collection toCollapse, OWLDocumentFormat format) { } \ No newline at end of file diff --git a/scripts/java/src/main/java/main/IRIConverter.java b/scripts/java/src/main/java/main/converter/IRIConverter.java similarity index 95% rename from scripts/java/src/main/java/main/IRIConverter.java rename to scripts/java/src/main/java/main/converter/IRIConverter.java index 3c0823db..8f97b9d4 100644 --- a/scripts/java/src/main/java/main/IRIConverter.java +++ b/scripts/java/src/main/java/main/converter/IRIConverter.java @@ -1,4 +1,4 @@ -package main; +package main.converter; import org.jetbrains.annotations.NotNull; import org.semanticweb.owlapi.model.IRI; diff --git a/scripts/java/src/main/java/main/converter/OWLDocumentFormatConverter.java b/scripts/java/src/main/java/main/converter/OWLDocumentFormatConverter.java new file mode 100644 index 00000000..3314b875 --- /dev/null +++ b/scripts/java/src/main/java/main/converter/OWLDocumentFormatConverter.java @@ -0,0 +1,26 @@ +package main.converter; + +import org.semanticweb.owlapi.formats.FunctionalSyntaxDocumentFormat; +import org.semanticweb.owlapi.formats.ManchesterSyntaxDocumentFormat; +import org.semanticweb.owlapi.formats.OWLXMLDocumentFormat; +import org.semanticweb.owlapi.formats.RDFXMLDocumentFormat; +import org.semanticweb.owlapi.model.OWLDocumentFormat; +import org.springframework.boot.context.properties.ConfigurationPropertiesBinding; +import org.springframework.core.convert.converter.Converter; +import org.springframework.stereotype.Component; + +@Component +@ConfigurationPropertiesBinding +public class OWLDocumentFormatConverter implements Converter { + + @Override + public OWLDocumentFormat convert(final String source) { + return switch (source.toUpperCase()) { + case "RDF_XML" -> new RDFXMLDocumentFormat(); + case "OWL_XML" -> new OWLXMLDocumentFormat(); + case "FUNCTIONAL" -> new FunctionalSyntaxDocumentFormat(); + case "MANCHESTER" -> new ManchesterSyntaxDocumentFormat(); + default -> throw new IllegalStateException("Unexpected value: " + source); + }; + } +}