From cb1a2c999148032c107ee60463ceb75adf8cb271 Mon Sep 17 00:00:00 2001 From: TimAdams84 Date: Tue, 10 Jan 2023 15:22:22 +0100 Subject: [PATCH] Add gitlab Files & adapt pom --- pom.xml | 108 + .../fraunhofer/scai/bio/owltooling/Label.java | 57 + .../scai/bio/owltooling/OntologyBuilder.java | 281 ++ .../scai/bio/owltooling/OntologyProvider.java | 53 + .../scai/bio/owltooling/OntologyReasoner.java | 829 +++++ .../scai/bio/owltooling/Prefixes.java | 33 + .../scai/bio/owltooling/RDFBuilder.java | 237 ++ .../scai/bio/owltooling/TMOntology.java | 80 + src/main/resources/logback-spring.xml | 7 + .../scai/bio/owltooling/OWLReasonerTest.java | 54 + .../bio/owltooling/OntologBuilderTest.java | 41 + src/test/resources/pizza.owl | 3004 +++++++++++++++++ 12 files changed, 4784 insertions(+) create mode 100644 pom.xml create mode 100644 src/main/java/de/fraunhofer/scai/bio/owltooling/Label.java create mode 100644 src/main/java/de/fraunhofer/scai/bio/owltooling/OntologyBuilder.java create mode 100644 src/main/java/de/fraunhofer/scai/bio/owltooling/OntologyProvider.java create mode 100644 src/main/java/de/fraunhofer/scai/bio/owltooling/OntologyReasoner.java create mode 100644 src/main/java/de/fraunhofer/scai/bio/owltooling/Prefixes.java create mode 100644 src/main/java/de/fraunhofer/scai/bio/owltooling/RDFBuilder.java create mode 100644 src/main/java/de/fraunhofer/scai/bio/owltooling/TMOntology.java create mode 100644 src/main/resources/logback-spring.xml create mode 100644 src/test/java/de/fraunhofer/scai/bio/owltooling/OWLReasonerTest.java create mode 100644 src/test/java/de/fraunhofer/scai/bio/owltooling/OntologBuilderTest.java create mode 100644 src/test/resources/pizza.owl diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..f34f304 --- /dev/null +++ b/pom.xml @@ -0,0 +1,108 @@ + + 4.0.0 + de.fraunhofer.scai.bio + owltooling + 0.0.1-SNAPSHOT + OWL Tooling + some library to work with owl files + + + + github + GitHub SCAI-BIO Apache Maven Packages + https://maven.pkg.github.com/SCAI-BIO/owl-tooling + + + + + true + 1.8 + ${java.version} + ${java.version} + yyyy-MM-dd HH:mm + 1.8 + UTF-8 + -Xdoclint:none + 2020-11-11 13:49 + UTF-8 + 1.8 + 4.13 + + + + + net.sourceforge.owlapi + owlapi-distribution + 5.1.17 + + + org.projectlombok + lombok + 1.18.6 + provided + + + org.apache.commons + commons-csv + 1.8 + + + org.apache.jena + jena-core + 3.16.0 + + + net.sourceforge.owlapi + org.semanticweb.hermit + 1.4.5.519 + + + junit + junit + ${version.junit} + test + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + de.fraunhofer.scai.bio.owltooling.App + + + + + + pl.project13.maven + git-commit-id-plugin + + + get-the-git-infos + + revision + + + + validate-the-git-infos + + validateRevision + + + package + + + + true + + + + + diff --git a/src/main/java/de/fraunhofer/scai/bio/owltooling/Label.java b/src/main/java/de/fraunhofer/scai/bio/owltooling/Label.java new file mode 100644 index 0000000..2f66048 --- /dev/null +++ b/src/main/java/de/fraunhofer/scai/bio/owltooling/Label.java @@ -0,0 +1,57 @@ +package de.fraunhofer.scai.bio.owltooling; + +import java.util.Objects; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import lombok.Getter; +import lombok.Setter; + +/** + * language specific labels + * + * @author Marc Jacobs + * + */ +public class Label { + + @JsonProperty("language") + @Getter @Setter private String language = null; + + @JsonProperty("content") + @Getter @Setter private String content = null; + + public Label(String content, String language) { + setContent(content); + setLanguage(language); + } + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Label label = (Label) o; + return Objects.equals(this.content, label.content) && + Objects.equals(this.language, label.language); + } + + @Override + public int hashCode() { + return Objects.hash(language, content); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("\""); + sb.append(content); + sb.append("\"@"); + sb.append(language); + return sb.toString(); + } + +} diff --git a/src/main/java/de/fraunhofer/scai/bio/owltooling/OntologyBuilder.java b/src/main/java/de/fraunhofer/scai/bio/owltooling/OntologyBuilder.java new file mode 100644 index 0000000..2e51cbc --- /dev/null +++ b/src/main/java/de/fraunhofer/scai/bio/owltooling/OntologyBuilder.java @@ -0,0 +1,281 @@ +package de.fraunhofer.scai.bio.owltooling; + +import java.io.File; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +import org.eclipse.rdf4j.model.vocabulary.RDFS; +import org.eclipse.rdf4j.model.vocabulary.SKOS; +import org.semanticweb.owlapi.apibinding.OWLManager; +import org.semanticweb.owlapi.formats.OWLXMLDocumentFormat; +import org.semanticweb.owlapi.formats.RDFXMLDocumentFormat; +import org.semanticweb.owlapi.formats.TurtleDocumentFormat; +import org.semanticweb.owlapi.io.StringDocumentTarget; +import org.semanticweb.owlapi.model.AddAxiom; +import org.semanticweb.owlapi.model.AddOntologyAnnotation; +import org.semanticweb.owlapi.model.IRI; +import org.semanticweb.owlapi.model.OWLAnnotation; +import org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom; +import org.semanticweb.owlapi.model.OWLAxiom; +import org.semanticweb.owlapi.model.OWLClass; +import org.semanticweb.owlapi.model.OWLClassAssertionAxiom; +import org.semanticweb.owlapi.model.OWLClassExpression; +import org.semanticweb.owlapi.model.OWLDataFactory; +import org.semanticweb.owlapi.model.OWLIndividual; +import org.semanticweb.owlapi.model.OWLObjectSomeValuesFrom; +import org.semanticweb.owlapi.model.OWLOntology; +import org.semanticweb.owlapi.model.OWLOntologyCreationException; +import org.semanticweb.owlapi.model.OWLOntologyManager; +import org.semanticweb.owlapi.model.OWLOntologyStorageException; +import org.semanticweb.owlapi.model.OWLSubClassOfAxiom; +import org.semanticweb.owlapi.model.parameters.ChangeApplied; + +import lombok.Getter; +import lombok.extern.slf4j.Slf4j; + +/** + * creating an OWLOntology using the owlapi + * + * @author Marc Jacobs + * + */ +@Slf4j +public class OntologyBuilder { + + public final static IRI OLS_LABEL = IRI.create("https://bio.scai.fraunhofer.de/ontology/OlsLabel"); + + @Getter public OWLOntology ontology; + @Getter public OWLOntologyManager manager; + private OWLDataFactory df; + @Getter private IRI ontologyIRI; + + public OntologyBuilder(String iri) throws OWLOntologyCreationException { + manager = OWLManager.createOWLOntologyManager(); + df = manager.getOWLDataFactory(); + + ontologyIRI = IRI.create(iri); + ontology = manager.createOntology(ontologyIRI); + } + + public void addConceptLabel(IRI iri1, String label) { + addConceptAnnotation(iri1, getAnnotation(Prefixes.RDFS_LABEL, label)); + } + + public void addConceptAnnotation(IRI iri1, IRI iri2, List