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

Fix for #248 #264

Merged
merged 5 commits into from
Jul 22, 2022
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
9 changes: 5 additions & 4 deletions scripts/java/application.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion scripts/java/src/main/java/main/Application.java
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
32 changes: 32 additions & 0 deletions scripts/java/src/main/java/main/CIRunner.java
Original file line number Diff line number Diff line change
@@ -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();
}
}

}
1 change: 1 addition & 0 deletions scripts/java/src/main/java/main/OntologyManager.java
Original file line number Diff line number Diff line change
@@ -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.*;
Expand Down
52 changes: 0 additions & 52 deletions scripts/java/src/main/java/main/VersionInfoAdder.java

This file was deleted.

6 changes: 6 additions & 0 deletions scripts/java/src/main/java/main/ci_runners/CIRunnable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package main.ci_runners;

public interface CIRunnable {

void run() throws Exception;
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
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;
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 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.
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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.
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}
}
}
51 changes: 51 additions & 0 deletions scripts/java/src/main/java/main/ci_runners/VersionInfoAdder.java
Original file line number Diff line number Diff line change
@@ -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());
}


}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main;
package main.config;

import org.semanticweb.owlapi.model.HasOntologyID;
import org.semanticweb.owlapi.model.IRI;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package main;
package main.config;

import org.semanticweb.owlapi.model.OWLDocumentFormat;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.nio.file.Path;
import java.util.Collection;


@ConfigurationProperties(prefix = "ontology")
public record OntologyConfig(Path directory, Collection<CollapseConfig> toCollapse) {
public record OntologyConfig(Path directory, Collection<CollapseConfig> toCollapse, OWLDocumentFormat format) {

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main;
package main.converter;

import org.jetbrains.annotations.NotNull;
import org.semanticweb.owlapi.model.IRI;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, OWLDocumentFormat> {

@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);
};
}
}