-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #264 from mrnolte/248
Fix for #248
- Loading branch information
Showing
14 changed files
with
152 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 13 additions & 9 deletions
22
...ava/src/main/java/main/OntologySaver.java → ...n/java/main/ci_runners/OntologySaver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
51
scripts/java/src/main/java/main/ci_runners/VersionInfoAdder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...va/src/main/java/main/CollapseConfig.java → ...main/java/main/config/CollapseConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
...va/src/main/java/main/OntologyConfig.java → ...main/java/main/config/OntologyConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...java/src/main/java/main/IRIConverter.java → ...ain/java/main/converter/IRIConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
scripts/java/src/main/java/main/converter/OWLDocumentFormatConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; | ||
} | ||
} |