diff --git a/owl-adapter/.project b/.project similarity index 100% rename from owl-adapter/.project rename to .project diff --git a/owl-adapter/.settings/org.eclipse.buildship.core.prefs b/.settings/org.eclipse.buildship.core.prefs similarity index 100% rename from owl-adapter/.settings/org.eclipse.buildship.core.prefs rename to .settings/org.eclipse.buildship.core.prefs diff --git a/.travis.yml b/.travis.yml index 8d8673e..e102a63 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,9 +4,6 @@ install: true jdk: - openjdk11 -before_script: -- cd owl-adapter - script: - ./gradlew build diff --git a/owl-adapter/build.gradle b/build.gradle similarity index 88% rename from owl-adapter/build.gradle rename to build.gradle index 4cacdaf..dedb766 100644 --- a/owl-adapter/build.gradle +++ b/build.gradle @@ -11,13 +11,14 @@ buildscript { } subprojects { - group = 'io.opencaesar.owl' - version = '0.7.11' + group = 'io.opencaesar.adapters' + version = '0.8.0' ext.versions = [ - oml: '0.7.+', + oml: '0.8.+', + oml_tools: '0.8.+', owl: '5.1.+', - owl_tools: '0.7.+', + owl_tools: '+', jcommander: '1.72', log4j: '1.2.17', slf4j: '1.7.30', @@ -27,6 +28,7 @@ subprojects { repositories { mavenLocal() + maven { url 'https://dl.bintray.com/opencaesar/oml-tools' } maven { url 'https://dl.bintray.com/opencaesar/owl-tools' } maven { url 'https://dl.bintray.com/opencaesar/oml' } mavenCentral() diff --git a/owl-adapter/gradle.properties b/gradle.properties similarity index 100% rename from owl-adapter/gradle.properties rename to gradle.properties diff --git a/owl-adapter/gradle/maven-deployment.gradle b/gradle/maven-deployment.gradle similarity index 100% rename from owl-adapter/gradle/maven-deployment.gradle rename to gradle/maven-deployment.gradle diff --git a/owl-adapter/gradle/source-layout.gradle b/gradle/source-layout.gradle similarity index 81% rename from owl-adapter/gradle/source-layout.gradle rename to gradle/source-layout.gradle index abe4f5c..644c475 100644 --- a/owl-adapter/gradle/source-layout.gradle +++ b/gradle/source-layout.gradle @@ -2,19 +2,13 @@ sourceSets { main { java.srcDirs = ['src/main/java'] resources.srcDirs = ['src/main/resources'] - xtendOutputDir = 'src/main/xtend-gen' } test { java.srcDirs = ['src/test/java'] resources.srcDirs = ['src/test/resources'] - xtendOutputDir = 'src/test/xtend-gen' } } -sourceSets.all { - resources.exclude '**/*.xtend', '**/*._trace' -} - task sourcesJar(type: Jar, dependsOn: classes) { classifier = 'sources' from sourceSets.main.allSource diff --git a/owl-adapter/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar similarity index 100% rename from owl-adapter/gradle/wrapper/gradle-wrapper.jar rename to gradle/wrapper/gradle-wrapper.jar diff --git a/owl-adapter/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties similarity index 100% rename from owl-adapter/gradle/wrapper/gradle-wrapper.properties rename to gradle/wrapper/gradle-wrapper.properties diff --git a/owl-adapter/gradlew b/gradlew similarity index 100% rename from owl-adapter/gradlew rename to gradlew diff --git a/owl-adapter/gradlew.bat b/gradlew.bat similarity index 100% rename from owl-adapter/gradlew.bat rename to gradlew.bat diff --git a/owl-adapter/oml2owl-gradle/.classpath b/oml2owl-gradle/.classpath similarity index 87% rename from owl-adapter/oml2owl-gradle/.classpath rename to oml2owl-gradle/.classpath index b82b006..6d924d7 100755 --- a/owl-adapter/oml2owl-gradle/.classpath +++ b/oml2owl-gradle/.classpath @@ -6,7 +6,7 @@ - + diff --git a/owl-adapter/oml2owl-gradle/.project b/oml2owl-gradle/.project similarity index 100% rename from owl-adapter/oml2owl-gradle/.project rename to oml2owl-gradle/.project diff --git a/owl-adapter/oml2owl-gradle/.settings/org.eclipse.buildship.core.prefs b/oml2owl-gradle/.settings/org.eclipse.buildship.core.prefs similarity index 100% rename from owl-adapter/oml2owl-gradle/.settings/org.eclipse.buildship.core.prefs rename to oml2owl-gradle/.settings/org.eclipse.buildship.core.prefs diff --git a/owl-adapter/oml2owl-gradle/.settings/org.eclipse.jdt.core.prefs b/oml2owl-gradle/.settings/org.eclipse.jdt.core.prefs similarity index 100% rename from owl-adapter/oml2owl-gradle/.settings/org.eclipse.jdt.core.prefs rename to oml2owl-gradle/.settings/org.eclipse.jdt.core.prefs diff --git a/owl-adapter/oml2owl-gradle/README.md b/oml2owl-gradle/README.md similarity index 100% rename from owl-adapter/oml2owl-gradle/README.md rename to oml2owl-gradle/README.md diff --git a/owl-adapter/oml2owl-gradle/build.gradle b/oml2owl-gradle/build.gradle similarity index 100% rename from owl-adapter/oml2owl-gradle/build.gradle rename to oml2owl-gradle/build.gradle diff --git a/owl-adapter/oml2owl-gradle/src/main/java/io/opencaesar/oml2owl/Oml2OwlTask.java b/oml2owl-gradle/src/main/java/io/opencaesar/oml2owl/Oml2OwlTask.java similarity index 100% rename from owl-adapter/oml2owl-gradle/src/main/java/io/opencaesar/oml2owl/Oml2OwlTask.java rename to oml2owl-gradle/src/main/java/io/opencaesar/oml2owl/Oml2OwlTask.java diff --git a/oml2owl-gradle/src/main/resources/version.txt b/oml2owl-gradle/src/main/resources/version.txt new file mode 100755 index 0000000..8adc70f --- /dev/null +++ b/oml2owl-gradle/src/main/resources/version.txt @@ -0,0 +1 @@ +0.8.0 \ No newline at end of file diff --git a/owl-adapter/oml2owl/.classpath b/oml2owl/.classpath similarity index 68% rename from owl-adapter/oml2owl/.classpath rename to oml2owl/.classpath index 1eafd61..6d924d7 100644 --- a/owl-adapter/oml2owl/.classpath +++ b/oml2owl/.classpath @@ -6,13 +6,7 @@ - - - - - - - + diff --git a/owl-adapter/oml2owl/.project b/oml2owl/.project similarity index 100% rename from owl-adapter/oml2owl/.project rename to oml2owl/.project diff --git a/owl-adapter/oml2owl/.settings/org.eclipse.buildship.core.prefs b/oml2owl/.settings/org.eclipse.buildship.core.prefs similarity index 100% rename from owl-adapter/oml2owl/.settings/org.eclipse.buildship.core.prefs rename to oml2owl/.settings/org.eclipse.buildship.core.prefs diff --git a/owl-adapter/oml2owl/.settings/org.eclipse.jdt.core.prefs b/oml2owl/.settings/org.eclipse.jdt.core.prefs similarity index 100% rename from owl-adapter/oml2owl/.settings/org.eclipse.jdt.core.prefs rename to oml2owl/.settings/org.eclipse.jdt.core.prefs diff --git a/owl-adapter/oml2owl/README.md b/oml2owl/README.md similarity index 100% rename from owl-adapter/oml2owl/README.md rename to oml2owl/README.md diff --git a/owl-adapter/oml2owl/build.gradle b/oml2owl/build.gradle similarity index 86% rename from owl-adapter/oml2owl/build.gradle rename to oml2owl/build.gradle index d0c596c..b21c49f 100644 --- a/owl-adapter/oml2owl/build.gradle +++ b/oml2owl/build.gradle @@ -7,6 +7,7 @@ applicationName = 'oml2owl' dependencies { implementation "io.opencaesar.oml:io.opencaesar.oml.dsl:${versions.oml}" + implementation "io.opencaesar.oml:oml-validate:${versions.oml_tools}" implementation "io.opencaesar.owl:owl-close-world:${versions.owl_tools}" implementation "net.sourceforge.owlapi:owlapi-distribution:${versions.owl}" implementation "org.jgrapht:jgrapht-core:${versions.jgrapht}" diff --git a/owl-adapter/oml2owl/src/main/java/io/opencaesar/oml2owl/CloseDescriptionBundle.java b/oml2owl/src/main/java/io/opencaesar/oml2owl/CloseDescriptionBundle.java similarity index 98% rename from owl-adapter/oml2owl/src/main/java/io/opencaesar/oml2owl/CloseDescriptionBundle.java rename to oml2owl/src/main/java/io/opencaesar/oml2owl/CloseDescriptionBundle.java index 67607c2..5a1d793 100644 --- a/owl-adapter/oml2owl/src/main/java/io/opencaesar/oml2owl/CloseDescriptionBundle.java +++ b/oml2owl/src/main/java/io/opencaesar/oml2owl/CloseDescriptionBundle.java @@ -286,18 +286,21 @@ private final static HashMap> getRelation toStream(allOntologies.iterator()).forEach(g -> { toStream(g.eAllContents()).filter(e -> e instanceof RelationEntity).map(e -> (RelationEntity) e) .forEach(re -> { - final Relation f = re.getForward(); - final Relation r = re.getReverse(); - graph.addVertex(f); + final Relation f = re.getForwardRelation(); + final Relation r = re.getReverseRelation(); + if (Objects.nonNull(f)) + graph.addVertex(f); if (Objects.nonNull(r)) graph.addVertex(r); OmlRead.getSpecializedTerms(re).forEach(s -> { if (s instanceof RelationEntity) { final RelationEntity sre = (RelationEntity) s; - final Relation sf = sre.getForward(); - final Relation sr = sre.getReverse(); - graph.addVertex(sf); - graph.addEdge(sf, f); + final Relation sf = sre.getForwardRelation(); + final Relation sr = sre.getReverseRelation(); + if (Objects.nonNull(f) && Objects.nonNull(sf)) { + graph.addVertex(sf); + graph.addEdge(sf, f); + } if (Objects.nonNull(r) && Objects.nonNull(sr)) { graph.addVertex(sr); graph.addEdge(sr, r); diff --git a/owl-adapter/oml2owl/src/main/java/io/opencaesar/oml2owl/CloseVocabularyBundle.java b/oml2owl/src/main/java/io/opencaesar/oml2owl/CloseVocabularyBundle.java similarity index 100% rename from owl-adapter/oml2owl/src/main/java/io/opencaesar/oml2owl/CloseVocabularyBundle.java rename to oml2owl/src/main/java/io/opencaesar/oml2owl/CloseVocabularyBundle.java diff --git a/oml2owl/src/main/java/io/opencaesar/oml2owl/Oml2Owl.java b/oml2owl/src/main/java/io/opencaesar/oml2owl/Oml2Owl.java new file mode 100644 index 0000000..c3a98a9 --- /dev/null +++ b/oml2owl/src/main/java/io/opencaesar/oml2owl/Oml2Owl.java @@ -0,0 +1,935 @@ +package io.opencaesar.oml2owl; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.rdf4j.model.vocabulary.RDFS; +import org.semanticweb.owlapi.model.OWLAnnotation; +import org.semanticweb.owlapi.model.OWLAnonymousIndividual; +import org.semanticweb.owlapi.model.OWLFacetRestriction; +import org.semanticweb.owlapi.model.OWLIndividual; +import org.semanticweb.owlapi.model.OWLLiteral; +import org.semanticweb.owlapi.model.OWLNamedIndividual; +import org.semanticweb.owlapi.model.OWLOntology; +import org.semanticweb.owlapi.model.SWRLAtom; +import org.semanticweb.owlapi.model.SWRLObjectPropertyAtom; +import org.semanticweb.owlapi.vocab.OWLFacet; + +import io.opencaesar.oml.Annotation; +import io.opencaesar.oml.AnnotationProperty; +import io.opencaesar.oml.Aspect; +import io.opencaesar.oml.Assertion; +import io.opencaesar.oml.BooleanLiteral; +import io.opencaesar.oml.CardinalityRestrictionKind; +import io.opencaesar.oml.Concept; +import io.opencaesar.oml.ConceptInstance; +import io.opencaesar.oml.ConceptInstanceReference; +import io.opencaesar.oml.ConceptTypeAssertion; +import io.opencaesar.oml.DecimalLiteral; +import io.opencaesar.oml.Description; +import io.opencaesar.oml.DescriptionBundle; +import io.opencaesar.oml.DifferentFromPredicate; +import io.opencaesar.oml.DoubleLiteral; +import io.opencaesar.oml.Element; +import io.opencaesar.oml.EntityPredicate; +import io.opencaesar.oml.EnumeratedScalar; +import io.opencaesar.oml.FacetedScalar; +import io.opencaesar.oml.ForwardRelation; +import io.opencaesar.oml.Import; +import io.opencaesar.oml.IntegerLiteral; +import io.opencaesar.oml.KeyAxiom; +import io.opencaesar.oml.LinkAssertion; +import io.opencaesar.oml.Literal; +import io.opencaesar.oml.Member; +import io.opencaesar.oml.Ontology; +import io.opencaesar.oml.Predicate; +import io.opencaesar.oml.QuotedLiteral; +import io.opencaesar.oml.RangeRestrictionKind; +import io.opencaesar.oml.Reference; +import io.opencaesar.oml.RelationCardinalityRestrictionAxiom; +import io.opencaesar.oml.RelationEntity; +import io.opencaesar.oml.RelationEntityPredicate; +import io.opencaesar.oml.RelationInstance; +import io.opencaesar.oml.RelationInstanceReference; +import io.opencaesar.oml.RelationPredicate; +import io.opencaesar.oml.RelationRangeRestrictionAxiom; +import io.opencaesar.oml.RelationTargetRestrictionAxiom; +import io.opencaesar.oml.RelationTypeAssertion; +import io.opencaesar.oml.ReverseRelation; +import io.opencaesar.oml.Rule; +import io.opencaesar.oml.SameAsPredicate; +import io.opencaesar.oml.ScalarProperty; +import io.opencaesar.oml.ScalarPropertyCardinalityRestrictionAxiom; +import io.opencaesar.oml.ScalarPropertyRangeRestrictionAxiom; +import io.opencaesar.oml.ScalarPropertyValueAssertion; +import io.opencaesar.oml.ScalarPropertyValueRestrictionAxiom; +import io.opencaesar.oml.SpecializationAxiom; +import io.opencaesar.oml.Structure; +import io.opencaesar.oml.StructureInstance; +import io.opencaesar.oml.StructuredProperty; +import io.opencaesar.oml.StructuredPropertyCardinalityRestrictionAxiom; +import io.opencaesar.oml.StructuredPropertyRangeRestrictionAxiom; +import io.opencaesar.oml.StructuredPropertyValueAssertion; +import io.opencaesar.oml.StructuredPropertyValueRestrictionAxiom; +import io.opencaesar.oml.Term; +import io.opencaesar.oml.Vocabulary; +import io.opencaesar.oml.VocabularyBundle; +import io.opencaesar.oml.util.OmlRead; +import io.opencaesar.oml.util.OmlVisitor; + +public class Oml2Owl extends OmlVisitor { + + public static final List BUILT_IN_ONTOLOGIES = Arrays.asList(new String[] { + "http://www.w3.org/2001/XMLSchema", + "http://www.w3.org/1999/02/22-rdf-syntax-ns", + "http://www.w3.org/2000/01/rdf-schema", + "http://www.w3.org/2002/07/owl"}); + + private final Resource inputResource; + private final OwlApi owl; + private OWLOntology ontology; + + public Oml2Owl(final Resource inputResource, final OwlApi owl2) { + this.inputResource = inputResource; + owl = owl2; + } + + public OWLOntology run() { + Iterable iterable = () -> inputResource.getAllContents(); + StreamSupport.stream(iterable.spliterator(), false).forEach(i -> doSwitch(i)); + return ontology; + } + + @Override + public Void caseAnnotation(final Annotation annotation) { + addsAnnotation(OmlRead.getAnnotatedElement(annotation), annotation); + return null; + } + + @Override + public Void caseVocabulary(final Vocabulary vocabulary) { + ontology = owl.createOntology(vocabulary.getIri()); + owl.addOntologyAnnotation(ontology, owl.getAnnotation(OmlConstants.ontologyType, owl.createIri(OmlConstants.Vocabulary))); + return null; + } + + @Override + public Void caseVocabularyBundle(final VocabularyBundle bundle) { + ontology = owl.createOntology(bundle.getIri()); + owl.addOntologyAnnotation(ontology, owl.getAnnotation(OmlConstants.ontologyType, owl.createIri(OmlConstants.VocabularyBundle))); + return null; + } + + @Override + public Void caseDescription(final Description description) { + ontology = owl.createOntology(description.getIri()); + owl.addOntologyAnnotation(ontology, owl.getAnnotation(OmlConstants.ontologyType, owl.createIri(OmlConstants.Description))); + return null; + } + + @Override + public Void caseDescriptionBundle(final DescriptionBundle bundle) { + ontology = owl.createOntology(bundle.getIri()); + owl.addOntologyAnnotation(ontology, owl.getAnnotation(OmlConstants.ontologyType, owl.createIri(OmlConstants.DescriptionBundle))); + return null; + } + + @Override + public Void caseAspect(final Aspect aspect) { + owl.addClass(ontology, OmlRead.getIri(aspect)); + owl.addSubClassOf(ontology, OmlRead.getIri(aspect), OmlConstants.Aspect); + return null; + } + + @Override + public Void caseConcept(final Concept concept) { + owl.addClass(ontology, OmlRead.getIri(concept)); + owl.addSubClassOf(ontology, OmlRead.getIri(concept), OmlConstants.Concept); + return null; + } + + @Override + public Void caseRelationEntity(final RelationEntity entity) { + owl.addClass(ontology, OmlRead.getIri(entity)); + owl.addSubClassOf(ontology, OmlRead.getIri(entity), OmlConstants.RelationEntity); + + // source relation + final String sourceRelationIri = getSourceIri(entity); + owl.addObjectProperty(ontology, sourceRelationIri); + owl.addSubObjectPropertyOf(ontology, sourceRelationIri, OmlConstants.sourceRelation); + owl.addObjectPropertyDomain(ontology, sourceRelationIri, OmlRead.getIri(entity)); + owl.addObjectPropertyRange(ontology, sourceRelationIri, OmlRead.getIri(entity.getSource())); + owl.addFunctionalObjectProperty(ontology, sourceRelationIri); + if (entity.isFunctional()) { + owl.addInverseFunctionalObjectProperty(ontology, sourceRelationIri); + } + if (entity.isInverseFunctional()) { + owl.addFunctionalObjectProperty(ontology, sourceRelationIri); + } + + // inverse source relation + final String inverseSourceRelationIri = getInverseSourceIri(entity); + if (inverseSourceRelationIri != null) { + owl.addObjectProperty(ontology, inverseSourceRelationIri); + owl.addSubObjectPropertyOf(ontology, inverseSourceRelationIri, OmlConstants.inverseSourceRelation); + owl.addInverseProperties(ontology, inverseSourceRelationIri, sourceRelationIri); + } + + // target relation + final String targetRelationIri = getTargetIri(entity); + owl.addObjectProperty(ontology, targetRelationIri); + owl.addSubObjectPropertyOf(ontology, targetRelationIri, OmlConstants.targetRelation); + owl.addObjectPropertyDomain(ontology, targetRelationIri, OmlRead.getIri(entity)); + owl.addObjectPropertyRange(ontology, targetRelationIri, OmlRead.getIri(entity.getTarget())); + owl.addFunctionalObjectProperty(ontology, targetRelationIri); + if (entity.isFunctional()) { + owl.addFunctionalObjectProperty(ontology, targetRelationIri); + } + if (entity.isInverseFunctional()) { + owl.addInverseFunctionalObjectProperty(ontology, targetRelationIri); + } + + // inverse target relation + final String inverseTargetRelationIri = getInverseTargetIri(entity); + if (inverseTargetRelationIri != null) { + owl.addObjectProperty(ontology, inverseTargetRelationIri); + owl.addSubObjectPropertyOf(ontology, inverseTargetRelationIri, OmlConstants.inverseTargetRelation); + owl.addInverseProperties(ontology, inverseTargetRelationIri, targetRelationIri); + } + + return null; + } + + @Override + public Void caseStructure(final Structure structure) { + owl.addClass(ontology, OmlRead.getIri(structure)); + owl.addSubClassOf(ontology, OmlRead.getIri(structure), OmlConstants.Structure); + return null; + } + + @Override + public Void caseFacetedScalar(final FacetedScalar scalar) { + owl.addDatatype(ontology, OmlRead.getIri(scalar)); + return null; + } + + @Override + public Void caseEnumeratedScalar(final EnumeratedScalar scalar) { + owl.addDataOneOf(ontology, OmlRead.getIri(scalar), scalar.getLiterals().stream().map(i -> getLiteral(i)).toArray(OWLLiteral[]::new)); + return null; + } + + @Override + public Void caseAnnotationProperty(final AnnotationProperty property) { + owl.addAnnotationProperty(ontology, OmlRead.getIri(property)); + return null; + } + + @Override + public Void caseScalarProperty(final ScalarProperty property) { + final String propertyIri = OmlRead.getIri(property); + owl.addDataProperty(ontology, propertyIri); + owl.addSubDataPropertyOf(ontology, propertyIri, OmlConstants.scalarProperty); + owl.addDataPropertyDomain(ontology, propertyIri, OmlRead.getIri(property.getDomain())); + owl.addDataPropertyRange(ontology, propertyIri, OmlRead.getIri(property.getRange())); + if (property.isFunctional()) { + owl.addFunctionalDataProperty(ontology, propertyIri); + } + return null; + } + + @Override + public Void caseStructuredProperty(final StructuredProperty property) { + final String propertyIri = OmlRead.getIri(property); + owl.addObjectProperty(ontology, propertyIri); + owl.addSubObjectPropertyOf(ontology, propertyIri, OmlConstants.structuredProperty); + owl.addObjectPropertyDomain(ontology, propertyIri, OmlRead.getIri(property.getDomain())); + owl.addObjectPropertyRange(ontology, propertyIri, OmlRead.getIri(property.getRange())); + if (property.isFunctional()) { + owl.addFunctionalObjectProperty(ontology, propertyIri); + } + return null; + } + + @Override + public Void caseForwardRelation(final ForwardRelation forward) { + final RelationEntity entity = forward.getRelationEntity(); + + // forward relation + final String forwardIri = OmlRead.getIri(forward); + owl.addObjectProperty(ontology, forwardIri); + owl.addSubObjectPropertyOf(ontology, forwardIri, OmlConstants.forwardRelation); + owl.addObjectPropertyDomain(ontology, forwardIri, OmlRead.getIri(forward.getDomain())); + owl.addObjectPropertyRange(ontology, forwardIri, OmlRead.getIri(forward.getRange())); + if (entity.isFunctional()) { + owl.addFunctionalObjectProperty(ontology, forwardIri); + } + if (entity.isInverseFunctional()) { + owl.addInverseFunctionalObjectProperty(ontology, forwardIri); + } + if (entity.isSymmetric()) { + owl.addSymmetricObjectProperty(ontology, forwardIri); + } + if (entity.isAsymmetric()) { + owl.addAsymmetricObjectProperty(ontology, forwardIri); + } + if (entity.isReflexive()) { + owl.addReflexiveObjectProperty(ontology, forwardIri); + } + if (entity.isIrreflexive()) { + owl.addIrreflexiveObjectProperty(ontology, forwardIri); + } + if (entity.isTransitive()) { + owl.addTransitiveObjectProperty(ontology, forwardIri); + } + + // derivation rule for forward relation + final ArrayList antedecents = new ArrayList(); + antedecents.add(owl.getObjectPropertyAtom(getSourceIri(entity), getSwrlIri("r"), getSwrlIri("s"))); + antedecents.add(owl.getObjectPropertyAtom(getTargetIri(entity), getSwrlIri("r"), getSwrlIri("t"))); + final SWRLObjectPropertyAtom consequent = owl.getObjectPropertyAtom(forwardIri, getSwrlIri("s"), getSwrlIri("t")); + final OWLAnnotation annotation = owl.getAnnotation(RDFS.LABEL.toString(), owl.getLiteral(forward.getName()+" derivation")); + owl.addRule(ontology, Collections.singletonList(consequent), antedecents, annotation); + return null; + } + + @Override + public Void caseReverseRelation(final ReverseRelation reverse) { + // reverse relation + final String reverseIri = OmlRead.getIri(reverse); + owl.addObjectProperty(ontology, reverseIri); + owl.addSubObjectPropertyOf(ontology, reverseIri, OmlConstants.reverseRelation); + owl.addInverseProperties(ontology, reverseIri, OmlRead.getIri(reverse.getInverse())); + return null; + } + + @Override + public Void caseRule(final Rule rule) { + List annotations = rule.getOwnedAnnotations().stream().map(it -> createAnnotation(it)).collect(Collectors.toList()); + if (annotations.stream().filter(a -> a.getProperty().getIRI().toString().equals(RDFS.LABEL.toString())).count() == 0) { + annotations = Collections.singletonList(owl.getAnnotation(RDFS.LABEL.toString(), owl.getLiteral(rule.getName()))); + } + owl.addRule(ontology, + rule.getConsequent().stream().flatMap(p -> getAtom(p).stream()).collect(Collectors.toList()), + rule.getAntecedent().stream().flatMap(p -> getAtom(p).stream()).collect(Collectors.toList()), + toArray(annotations)); + return null; + } + + @Override + public Void caseConceptInstance(final ConceptInstance instance) { + final String instanceIri = OmlRead.getIri(instance); + final OWLIndividual individual = owl.addNamedIndividual(ontology, instanceIri); + instance.getOwnedPropertyValues().forEach(it -> appliesTo(it, individual)); + instance.getOwnedLinks().forEach(it -> appliesTo(it, individual)); + return null; + } + + @Override + public Void caseConceptInstanceReference(final ConceptInstanceReference reference) { + final String instanceIri = OmlRead.getIri(OmlRead.resolve(reference)); + final OWLNamedIndividual individual = owl.getNamedIndividual(instanceIri); + reference.getOwnedPropertyValues().forEach(it -> appliesTo(it, individual)); + reference.getOwnedLinks().forEach(it -> appliesTo(it, individual)); + return null; + } + + @Override + public Void caseRelationInstance(final RelationInstance instance) { + final String instanceIri = OmlRead.getIri(instance); + final OWLNamedIndividual individual = owl.addNamedIndividual(ontology, instanceIri); + instance.getOwnedPropertyValues().forEach(it -> appliesTo(it, individual)); + instance.getOwnedLinks().forEach(it -> appliesTo(it, individual)); + return null; + } + + @Override + public Void caseRelationInstanceReference(final RelationInstanceReference reference) { + final String instanceIri = OmlRead.getIri(OmlRead.resolve(reference)); + final OWLNamedIndividual individual = owl.getNamedIndividual(instanceIri); + reference.getOwnedPropertyValues().forEach(it -> appliesTo(it, individual)); + reference.getOwnedLinks().forEach(it -> appliesTo(it, individual)); + return null; + } + + @Override + public Void caseImport(final Import import_) { + Ontology importedOntology = OmlRead.getImportedOntology(import_); + if (importedOntology != null) { + final String iri = importedOntology.getIri(); + if (Oml2Owl.isBuiltInOntology(iri)) { + final List indirectImports = OmlRead.closure(import_, it -> OmlRead.getImportsWithSource(OmlRead.getImportedOntology(it))); + indirectImports.forEach(i2 -> { + final String iri2 = OmlRead.getImportedOntology(i2).getIri(); + if (!Oml2Owl.isBuiltInOntology(iri2)) { + owl.addImportsDeclaration(ontology, iri2); + } + }); + } else { + owl.addImportsDeclaration(ontology, iri); + } + } else { + throw new RuntimeException("Could not resolve IRI '"+ import_.getUri()+ "'"); + } + return null; + } + + @Override + public Void caseSpecializationAxiom(final SpecializationAxiom axiom) { + final List annotations = axiom.getOwnedAnnotations().stream().map(it -> createAnnotation(it)).collect(Collectors.toList()); + specializes(OmlRead.getSpecializingTerm(axiom), axiom.getSpecializedTerm(), axiom.getOwningReference(), toArray(annotations)); + return null; + } + + @Override + public Void caseScalarPropertyRangeRestrictionAxiom(final ScalarPropertyRangeRestrictionAxiom axiom) { + final List annotations = axiom.getOwnedAnnotations().stream().map(it -> createAnnotation(it)).collect(Collectors.toList()); + if (axiom.getKind() == RangeRestrictionKind.ALL) { + owl.addDataAllValuesFrom(ontology, OmlRead.getIri(OmlRead.getRestrictingType(axiom)), + OmlRead.getIri(axiom.getProperty()), OmlRead.getIri(axiom.getRange()), + toArray(annotations)); + } else { + owl.addDataSomeValuesFrom(ontology, OmlRead.getIri(OmlRead.getRestrictingType(axiom)), + OmlRead.getIri(axiom.getProperty()), OmlRead.getIri(axiom.getRange()), + toArray(annotations)); + } + return null; + } + + @Override + public Void caseScalarPropertyValueRestrictionAxiom(final ScalarPropertyValueRestrictionAxiom axiom) { + final List annotations = axiom.getOwnedAnnotations().stream().map(it -> createAnnotation(it)).collect(Collectors.toList()); + owl.addDataHasValue(ontology, OmlRead.getIri(OmlRead.getRestrictingType(axiom)), + OmlRead.getIri(axiom.getProperty()), getLiteral(axiom.getValue()), + toArray(annotations)); + return null; + } + + @Override + public Void caseScalarPropertyCardinalityRestrictionAxiom(final ScalarPropertyCardinalityRestrictionAxiom axiom) { + final List annotations = axiom.getOwnedAnnotations().stream().map(it -> createAnnotation(it)).collect(Collectors.toList()); + if (axiom.getKind() == CardinalityRestrictionKind.MIN) { + owl.addDataMinCardinality(ontology, + OmlRead.getIri(OmlRead.getRestrictingType(axiom)), + OmlRead.getIri(axiom.getProperty()), (int) axiom.getCardinality(), + (axiom.getRange() != null) ? OmlRead.getIri(axiom.getRange()) : null, + toArray(annotations)); + } else if (axiom.getKind() == CardinalityRestrictionKind.MAX) { + owl.addDataMaxCardinality(ontology, + OmlRead.getIri(OmlRead.getRestrictingType(axiom)), + OmlRead.getIri(axiom.getProperty()), (int) axiom.getCardinality(), + (axiom.getRange() != null) ? OmlRead.getIri(axiom.getRange()) : null, + toArray(annotations)); + } else { + owl.addDataExactCardinality(ontology, + OmlRead.getIri(OmlRead.getRestrictingType(axiom)), + OmlRead.getIri(axiom.getProperty()), (int) axiom.getCardinality(), + (axiom.getRange() != null) ? OmlRead.getIri(axiom.getRange()) : null, + toArray(annotations)); + } + return null; + } + + @Override + public Void caseStructuredPropertyRangeRestrictionAxiom(final StructuredPropertyRangeRestrictionAxiom axiom) { + final List annotations = axiom.getOwnedAnnotations().stream().map(it -> createAnnotation(it)).collect(Collectors.toList()); + if (axiom.getKind() == RangeRestrictionKind.ALL) { + owl.addObjectAllValuesFrom(ontology, + OmlRead.getIri(OmlRead.getRestrictingType(axiom)), + OmlRead.getIri(axiom.getProperty()), + OmlRead.getIri(axiom.getRange()), + toArray(annotations)); + } else { + owl.addObjectSomeValuesFrom(ontology, + OmlRead.getIri(OmlRead.getRestrictingType(axiom)), + OmlRead.getIri(axiom.getProperty()), + OmlRead.getIri(axiom.getRange()), + toArray(annotations)); + } + return null; + } + + @Override + public Void caseStructuredPropertyValueRestrictionAxiom(final StructuredPropertyValueRestrictionAxiom axiom) { + final List annotations = axiom.getOwnedAnnotations().stream().map(it -> createAnnotation(it)).collect(Collectors.toList()); + owl.addObjectHasValue(ontology, + OmlRead.getIri(OmlRead.getRestrictingType(axiom)), + OmlRead.getIri(axiom.getProperty()), + createIndividual(axiom.getValue()), + toArray(annotations)); + return null; + } + + @Override + public Void caseStructuredPropertyCardinalityRestrictionAxiom(final StructuredPropertyCardinalityRestrictionAxiom axiom) { + final List annotations = axiom.getOwnedAnnotations().stream().map(it -> createAnnotation(it)).collect(Collectors.toList()); + if (axiom.getKind() == CardinalityRestrictionKind.MIN) { + owl.addObjectMinCardinality(ontology, + OmlRead.getIri(OmlRead.getRestrictingType(axiom)), + OmlRead.getIri(axiom.getProperty()), (int) axiom.getCardinality(), + (axiom.getRange() != null) ? OmlRead.getIri(axiom.getRange()) : null, + toArray(annotations)); + } else if (axiom.getKind() == CardinalityRestrictionKind.MAX) { + owl.addObjectMaxCardinality(ontology, + OmlRead.getIri(OmlRead.getRestrictingType(axiom)), + OmlRead.getIri(axiom.getProperty()), (int) axiom.getCardinality(), + (axiom.getRange() != null) ? OmlRead.getIri(axiom.getRange()) : null, + toArray(annotations)); + } else { + owl.addObjectExactCardinality(ontology, + OmlRead.getIri(OmlRead.getRestrictingType(axiom)), + OmlRead.getIri(axiom.getProperty()), (int) axiom.getCardinality(), + (axiom.getRange() != null) ? OmlRead.getIri(axiom.getRange()) : null, + toArray(annotations)); + } + return null; + } + + @Override + public Void caseRelationRangeRestrictionAxiom(final RelationRangeRestrictionAxiom axiom) { + final List annotations = axiom.getOwnedAnnotations().stream().map(it -> createAnnotation(it)).collect(Collectors.toList()); + if (axiom.getKind() == RangeRestrictionKind.ALL) { + owl.addObjectAllValuesFrom(ontology, + OmlRead.getIri(OmlRead.getRestrictingType(axiom)), + OmlRead.getIri(axiom.getRelation()), + OmlRead.getIri(axiom.getRange()), + toArray(annotations)); + } else { + owl.addObjectSomeValuesFrom(ontology, + OmlRead.getIri(OmlRead.getRestrictingType(axiom)), + OmlRead.getIri(axiom.getRelation()), + OmlRead.getIri(axiom.getRange()), + toArray(annotations)); + } + return null; + } + + @Override + public Void caseRelationTargetRestrictionAxiom(final RelationTargetRestrictionAxiom axiom) { + final List annotations = axiom.getOwnedAnnotations().stream().map(it -> createAnnotation(it)).collect(Collectors.toList()); + owl.addObjectHasValue(ontology, + OmlRead.getIri(OmlRead.getRestrictingType(axiom)), + OmlRead.getIri(axiom.getRelation()), + OmlRead.getIri(axiom.getTarget()), + toArray(annotations)); + return null; + } + + @Override + public Void caseRelationCardinalityRestrictionAxiom(final RelationCardinalityRestrictionAxiom axiom) { + final List annotations = axiom.getOwnedAnnotations().stream().map(it -> createAnnotation(it)).collect(Collectors.toList()); + if (axiom.getKind() == CardinalityRestrictionKind.MIN) { + owl.addObjectMinCardinality(ontology, + OmlRead.getIri(OmlRead.getRestrictingType(axiom)), + OmlRead.getIri(axiom.getRelation()), + (int) axiom.getCardinality(), + (axiom.getRange() != null) ? OmlRead.getIri(axiom.getRange()) : null, + toArray(annotations)); + } else if (axiom.getKind() == CardinalityRestrictionKind.MAX) { + owl.addObjectMaxCardinality(ontology, + OmlRead.getIri(OmlRead.getRestrictingType(axiom)), + OmlRead.getIri(axiom.getRelation()), + (int) axiom.getCardinality(), + (axiom.getRange() != null) ? OmlRead.getIri(axiom.getRange()) : null, + toArray(annotations)); + } else { + owl.addObjectExactCardinality(ontology, + OmlRead.getIri(OmlRead.getRestrictingType(axiom)), + OmlRead.getIri(axiom.getRelation()), + (int) axiom.getCardinality(), + (axiom.getRange() != null) ? OmlRead.getIri(axiom.getRange()) : null, + toArray(annotations)); + } + return null; + } + + @Override + public Void caseKeyAxiom(final KeyAxiom axiom) { + final List annotations = axiom.getOwnedAnnotations().stream().map(it -> createAnnotation(it)).collect(Collectors.toList()); + owl.addHasKey(ontology, + OmlRead.getIri(OmlRead.getRestrictingType(axiom)), + axiom.getProperties().stream().map(i -> OmlRead.getIri(i)).collect(Collectors.toList()), + toArray(annotations)); + return null; + } + + @Override + public Void caseConceptTypeAssertion(final ConceptTypeAssertion assertion) { + final List annotations = assertion.getOwnedAnnotations().stream().map(it -> createAnnotation(it)).collect(Collectors.toList()); + owl.addClassAssertion(ontology, + OmlRead.getIri(OmlRead.getConceptInstance(assertion)), + OmlRead.getIri(assertion.getType()), + toArray(annotations)); + return null; + } + + @Override + public Void caseRelationTypeAssertion(final RelationTypeAssertion assertion) { + final List annotations = assertion.getOwnedAnnotations().stream().map(it -> createAnnotation(it)).collect(Collectors.toList()); + final RelationInstance instance = OmlRead.getRelationInstance(assertion); + final String instanceIri = OmlRead.getIri(instance); + owl.addClassAssertion(ontology, + instanceIri, + OmlRead.getIri(assertion.getType()), + toArray(annotations)); + instance.getSources().forEach(s -> + owl.addObjectPropertyAssertion(ontology, + instanceIri, + getSourceIri(assertion.getType()), + OmlRead.getIri(s))); + instance.getTargets().forEach(t -> + owl.addObjectPropertyAssertion(ontology, + instanceIri, + getTargetIri(assertion.getType()), + OmlRead.getIri(t))); + return null; + } + + protected OWLAnnotation createAnnotation(final Annotation annotation) { + final OWLLiteral literal; + if (annotation.getValue() != null) { + literal = getLiteral(annotation.getValue()); + } else { + literal = owl.getLiteral("true"); + } + return owl.getAnnotation(OmlRead.getIri(annotation.getProperty()), literal); + } + + protected void addsAnnotation(final Element element, final Annotation annotation) { + if (element instanceof Ontology) { + owl.addOntologyAnnotation(ontology, createAnnotation(annotation)); + } else if (element instanceof Member) { + owl.addAnnotationAssertion(ontology, OmlRead.getIri((Member)element), createAnnotation(annotation)); + } else if (element instanceof Reference) { + addsAnnotation(OmlRead.resolve((Reference)element), annotation); + } + } + + protected void specializes(final Term specific, final Term general, final Reference owningReference, final OWLAnnotation[] annotations) { + if (specific instanceof Aspect && general instanceof Aspect) { + specializes((Aspect) specific, (Aspect) general, owningReference, annotations); + return; + } else if (specific instanceof Concept && general instanceof Aspect) { + specializes((Concept) specific, (Aspect) general, owningReference, annotations); + return; + } else if (specific instanceof Concept && general instanceof Concept) { + specializes((Concept) specific, (Concept) general, owningReference, annotations); + return; + } else if (specific instanceof RelationEntity && general instanceof Aspect) { + specializes((RelationEntity) specific, (Aspect) general, owningReference, annotations); + return; + } else if (specific instanceof RelationEntity && general instanceof RelationEntity) { + specializes((RelationEntity) specific, (RelationEntity) general, owningReference, annotations); + return; + } else if (specific instanceof EnumeratedScalar && general instanceof EnumeratedScalar) { + specializes((EnumeratedScalar) specific, (EnumeratedScalar) general, owningReference, annotations); + return; + } else if (specific instanceof FacetedScalar && general instanceof FacetedScalar) { + specializes((FacetedScalar) specific, (FacetedScalar) general, owningReference, annotations); + return; + } else if (specific instanceof ScalarProperty && general instanceof ScalarProperty) { + specializes((ScalarProperty) specific, (ScalarProperty) general, owningReference, annotations); + return; + } else if (specific instanceof Structure && general instanceof Structure) { + specializes((Structure) specific, (Structure) general, owningReference, annotations); + return; + } else if (specific instanceof StructuredProperty && general instanceof StructuredProperty) { + specializes((StructuredProperty) specific, (StructuredProperty) general, owningReference, annotations); + return; + } + } + + protected void specializes(final Concept specific, final Concept general, final Reference owningReference, final OWLAnnotation... annotations) { + owl.addSubClassOf(ontology, OmlRead.getIri(specific), OmlRead.getIri(general), annotations); + } + + protected void specializes(final Concept specific, final Aspect general, final Reference owningReference, final OWLAnnotation... annotations) { + owl.addSubClassOf(ontology, OmlRead.getIri(specific), OmlRead.getIri(general), annotations); + } + + protected void specializes(final Aspect specific, final Aspect general, final Reference owningReference, final OWLAnnotation... annotations) { + owl.addSubClassOf(ontology, OmlRead.getIri(specific), OmlRead.getIri(general), annotations); + } + + protected void specializes(final RelationEntity specific, final RelationEntity general, final Reference owningReference, final OWLAnnotation... annotations) { + owl.addSubClassOf(ontology, OmlRead.getIri(specific), OmlRead.getIri(general), annotations); + owl.addSubObjectPropertyOf(ontology, getSourceIri(specific), getSourceIri(general), annotations); + owl.addSubObjectPropertyOf(ontology, getTargetIri(specific), getTargetIri(general), annotations); + } + + protected void specializes(final RelationEntity specific, final Aspect general, final Reference owningReference, final OWLAnnotation... annotations) { + owl.addSubClassOf(ontology, OmlRead.getIri(specific), OmlRead.getIri(general), annotations); + } + + protected void specializes(final Structure specific, final Structure general, final Reference owningReference, final OWLAnnotation... annotations) { + owl.addSubClassOf(ontology, OmlRead.getIri(specific), OmlRead.getIri(general), annotations); + } + + protected void specializes(final EnumeratedScalar specific, final EnumeratedScalar general, final Reference owningReference, final OWLAnnotation... annotations) { + owl.addDatatypeDefinition(ontology, OmlRead.getIri(specific), OmlRead.getIri(general), annotations); + } + + protected void specializes(final FacetedScalar specific, final FacetedScalar general, final Reference owningReference, final OWLAnnotation... annotations) { + if ((owningReference != null)) { + owl.addDatatypeDefinition(ontology, OmlRead.getIri(specific), OmlRead.getIri(general), annotations); + } else { + final ArrayList restrictions = new ArrayList<>(); + if (specific.getLength() != null) { + restrictions.add(owl.getFacetRestriction(OWLFacet.LENGTH, owl.getLiteral((specific.getLength()).longValue()))); + } + if (specific.getMaxLength() != null) { + restrictions.add(owl.getFacetRestriction(OWLFacet.MAX_LENGTH, owl.getLiteral((specific.getLength()).longValue()))); + } + if (specific.getMinLength() != null) { + restrictions.add(owl.getFacetRestriction(OWLFacet.MIN_LENGTH, owl.getLiteral((specific.getLength()).longValue()))); + } + if (specific.getPattern() != null) { + restrictions.add(owl.getFacetRestriction(OWLFacet.PATTERN, owl.getLiteral(specific.getPattern()))); + } + if (specific.getLanguage() != null) { + restrictions.add(owl.getFacetRestriction(OWLFacet.LANG_RANGE, owl.getLiteral(specific.getLanguage()))); + } + if (specific.getMinInclusive() != null) { + restrictions.add(owl.getFacetRestriction(OWLFacet.MIN_INCLUSIVE, getLiteral(specific.getMinInclusive()))); + } + if (specific.getMaxInclusive() != null) { + restrictions.add(owl.getFacetRestriction(OWLFacet.MAX_INCLUSIVE, getLiteral(specific.getMaxInclusive()))); + } + if (specific.getMinExclusive() != null) { + restrictions.add(owl.getFacetRestriction(OWLFacet.MIN_EXCLUSIVE, getLiteral(specific.getMinExclusive()))); + } + if (specific.getMaxExclusive() != null) { + restrictions.add(owl.getFacetRestriction(OWLFacet.MAX_EXCLUSIVE, getLiteral(specific.getMaxExclusive()))); + } + if (!restrictions.isEmpty()) { + owl.addDatatypeDefinition(ontology, + OmlRead.getIri(specific), + OmlRead.getIri(general), + restrictions.toArray(new OWLFacetRestriction[0]), + annotations); + } else { + owl.addDatatypeDefinition(ontology, + OmlRead.getIri(specific), + OmlRead.getIri(general), + annotations); + } + } + } + + protected void specializes(final ScalarProperty specific, final ScalarProperty general, final Reference owningReference, final OWLAnnotation... annotations) { + owl.addSubDataPropertyOf(ontology, OmlRead.getIri(specific), OmlRead.getIri(general), annotations); + } + + protected void specializes(final StructuredProperty specific, final StructuredProperty general, final Reference owningReference, final OWLAnnotation... annotations) { + owl.addSubObjectPropertyOf(ontology, OmlRead.getIri(specific), OmlRead.getIri(general), annotations); + } + + protected void appliesTo(final Assertion assertion, final OWLIndividual individual) { + if (assertion instanceof ScalarPropertyValueAssertion && individual != null) { + appliesTo((ScalarPropertyValueAssertion) assertion, individual); + } else if (assertion instanceof StructuredPropertyValueAssertion && individual != null) { + appliesTo((StructuredPropertyValueAssertion) assertion, individual); + } else if (assertion instanceof LinkAssertion && individual instanceof OWLNamedIndividual) { + appliesTo((LinkAssertion) assertion, (OWLNamedIndividual) individual); + } + } + + protected void appliesTo(final ScalarPropertyValueAssertion assertion, final OWLIndividual individual) { + final List annotations = assertion.getOwnedAnnotations().stream().map(it -> createAnnotation(it)).collect(Collectors.toList()); + owl.addDataPropertyAssertion(ontology, + individual, + OmlRead.getIri(assertion.getProperty()), + getLiteral(assertion.getValue()), + toArray(annotations)); + } + + protected void appliesTo(final StructuredPropertyValueAssertion assertion, final OWLIndividual individual) { + final List annotations = assertion.getOwnedAnnotations().stream().map(it -> createAnnotation(it)).collect(Collectors.toList()); + owl.addObjectPropertyAssertion(ontology, + individual, + OmlRead.getIri(assertion.getProperty()), + createIndividual(assertion.getValue()), + toArray(annotations)); + } + + protected void appliesTo(final LinkAssertion assertion, final OWLNamedIndividual individual) { + final List annotations = assertion.getOwnedAnnotations().stream().map(it -> createAnnotation(it)).collect(Collectors.toList()); + owl.addObjectPropertyAssertion(ontology, + individual.getIRI().getIRIString(), + OmlRead.getIri(assertion.getRelation()), + OmlRead.getIri(assertion.getTarget()), + toArray(annotations)); + } + + protected List getAtom(final Predicate predicate) { + if (predicate instanceof DifferentFromPredicate) { + return getAtom((DifferentFromPredicate) predicate); + } else if (predicate instanceof EntityPredicate) { + return getAtom((EntityPredicate) predicate); + } else if (predicate instanceof RelationEntityPredicate) { + return getAtom((RelationEntityPredicate) predicate); + } else if (predicate instanceof RelationPredicate) { + return getAtom((RelationPredicate) predicate); + } else if (predicate instanceof SameAsPredicate) { + return getAtom((SameAsPredicate) predicate); + } + return Collections.emptyList(); + } + + protected List getAtom(final EntityPredicate predicate) { + final List atoms = new ArrayList<>(); + atoms.add(owl.getClassAtom(OmlRead.getIri(predicate.getEntity()), getSwrlIri(predicate.getVariable()))); + return atoms; + } + + protected List getAtom(final RelationEntityPredicate predicate) { + final List atoms = new ArrayList<>(); + atoms.add(owl.getObjectPropertyAtom(getSourceIri(predicate.getEntity()), getSwrlIri(predicate.getEntityVariable()), getSwrlIri(predicate.getVariable1()))); + atoms.add(owl.getObjectPropertyAtom(getTargetIri(predicate.getEntity()), getSwrlIri(predicate.getEntityVariable()), getSwrlIri(predicate.getVariable2()))); + return atoms; + } + + protected List getAtom(final RelationPredicate predicate) { + final List atoms = new ArrayList<>(); + atoms.add(owl.getObjectPropertyAtom(OmlRead.getIri(predicate.getRelation()), getSwrlIri(predicate.getVariable1()), getSwrlIri(predicate.getVariable2()))); + return atoms; + } + + protected List getAtom(final SameAsPredicate predicate) { + final List atoms = new ArrayList<>(); + atoms.add(owl.getSameIndividualAtom(getSwrlIri(predicate.getVariable1()), getSwrlIri(predicate.getVariable2()))); + return atoms; + } + + protected List getAtom(final DifferentFromPredicate predicate) { + final List atoms = new ArrayList<>(); + atoms.add(owl.getDifferentIndividualsAtom(getSwrlIri(predicate.getVariable1()), getSwrlIri(predicate.getVariable2()))); + return atoms; + } + + protected OWLLiteral getLiteral(final Literal literal) { + if (literal instanceof BooleanLiteral) { + return getLiteral((BooleanLiteral) literal); + } else if (literal instanceof DecimalLiteral) { + return getLiteral((DecimalLiteral) literal); + } else if (literal instanceof DoubleLiteral) { + return getLiteral((DoubleLiteral) literal); + } else if (literal instanceof IntegerLiteral) { + return getLiteral((IntegerLiteral) literal); + } else if (literal instanceof QuotedLiteral) { + return getLiteral((QuotedLiteral) literal); + } + return null; + } + + protected OWLLiteral getLiteral(final QuotedLiteral literal) { + if (literal.getType() != null) { + return owl.getLiteralWithDatatype(literal.getValue().toString(), OmlRead.getIri(literal.getType())); + } else if (literal.getLangTag() != null) { + return owl.getLiteralWithLangTag(literal.getValue().toString(), literal.getLangTag()); + } else { + return owl.getLiteral(literal.getValue()); + } + } + + protected OWLLiteral getLiteral(final BooleanLiteral literal) { + if (literal.getType() != null) { + return owl.getLiteralWithDatatype(String.valueOf(literal.isValue()), OmlRead.getIri(literal.getType())); + } else { + return owl.getLiteral(literal.isValue()); + } + } + + protected OWLLiteral getLiteral(final IntegerLiteral literal) { + if (literal.getType() != null) { + return owl.getLiteralWithDatatype(String.valueOf(literal.getValue()), OmlRead.getIri(literal.getType())); + } else { + return owl.getLiteral(literal.getValue()); + } + } + + protected OWLLiteral getLiteral(final DecimalLiteral literal) { + if (literal.getType() != null) { + return owl.getLiteralWithDatatype(literal.getValue().toString(), OmlRead.getIri(literal.getType())); + } else { + return owl.getLiteral(literal.getValue()); + } + } + + protected OWLLiteral getLiteral(final DoubleLiteral literal) { + if (literal.getType() != null) { + return owl.getLiteralWithDatatype(String.valueOf(literal.getValue()), OmlRead.getIri(literal.getType())); + } else { + return owl.getLiteral(literal.getValue()); + } + } + + protected OWLAnonymousIndividual createIndividual(final StructureInstance instance) { + final OWLAnonymousIndividual individual = owl.getAnonymousIndividual(OmlRead.getId(instance)); + instance.getOwnedPropertyValues().forEach(it -> appliesTo(it, individual)); + return individual; + } + + protected String getSourceIri(final RelationEntity entity) { + if (entity.getSourceRelation() != null) { + return OmlRead.getIri(entity.getSourceRelation()); + } else { + String namespace = OmlRead.getNamespace(OmlRead.getOntology(entity)); + String name = toFirstUpper(entity.getName()); + return namespace+"has"+name+"Source"; + } + } + + protected String getTargetIri(final RelationEntity entity) { + if (entity.getTargetRelation() != null) { + return OmlRead.getIri(entity.getTargetRelation()); + } else { + String namespace = OmlRead.getNamespace(OmlRead.getOntology(entity)); + String name = toFirstUpper(entity.getName()); + return namespace+"has"+name+"Target"; + } + } + + protected String getInverseSourceIri(final RelationEntity entity) { + if (entity.getInverseSourceRelation() != null) { + return OmlRead.getIri(entity.getInverseSourceRelation()); + } + return null; + } + + protected String getInverseTargetIri(final RelationEntity entity) { + if (entity.getInverseTargetRelation() != null) { + return OmlRead.getIri(entity.getInverseTargetRelation()); + } + return null; + } + + protected String getSwrlIri(final String variableName) { + return "urn:swrl#" + variableName; + } + + static boolean isBuiltInOntology(final String iri) { + return Oml2Owl.BUILT_IN_ONTOLOGIES.contains(iri); + } + + private static String toFirstUpper(String s) { + if (s == null || s.length() == 0) + return s; + if (Character.isUpperCase(s.charAt(0))) + return s; + if (s.length() == 1) + return s.toUpperCase(); + return s.substring(0, 1).toUpperCase() + s.substring(1); + } + + private OWLAnnotation[] toArray(List annotations) { + return annotations.toArray(new OWLAnnotation[0]); + } + +} diff --git a/oml2owl/src/main/java/io/opencaesar/oml2owl/Oml2OwlApp.java b/oml2owl/src/main/java/io/opencaesar/oml2owl/Oml2OwlApp.java new file mode 100644 index 0000000..5ed7a1d --- /dev/null +++ b/oml2owl/src/main/java/io/opencaesar/oml2owl/Oml2OwlApp.java @@ -0,0 +1,282 @@ +package io.opencaesar.oml2owl; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.ForkJoinPool; + +import org.apache.log4j.Appender; +import org.apache.log4j.AppenderSkeleton; +import org.apache.log4j.Level; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.xtext.resource.XtextResourceSet; +import org.semanticweb.owlapi.apibinding.OWLManager; +import org.semanticweb.owlapi.model.IRI; +import org.semanticweb.owlapi.model.OWLOntology; +import org.semanticweb.owlapi.model.OWLOntologyManager; + +import com.beust.jcommander.IParameterValidator; +import com.beust.jcommander.JCommander; +import com.beust.jcommander.Parameter; +import com.beust.jcommander.ParameterException; +import com.google.common.io.CharStreams; + +import io.opencaesar.oml.DescriptionBundle; +import io.opencaesar.oml.VocabularyBundle; +import io.opencaesar.oml.dsl.OmlStandaloneSetup; +import io.opencaesar.oml.util.OmlCatalog; +import io.opencaesar.oml.util.OmlRead; +import io.opencaesar.oml.util.OmlXMIResourceFactory; +import io.opencaesar.oml.validate.OmlValidator; +import io.opencaesar.oml2owl.CloseDescriptionBundle.CloseDescriptionBundleToOwl; +import io.opencaesar.oml2owl.CloseVocabularyBundle.CloseVocabularyBundleToOwl; + +public class Oml2OwlApp { + + static final String OML = "oml"; + static final String OMLXMI = "omlxmi"; + + @Parameter( + names = { "--input-catalog-path", "-i" }, + description = "Path of the input OML catalog (Required)", + validateWith = Oml2OwlApp.InputCatalogPath.class, + required = true, + order = 1) + private String inputCatalogPath; + + @Parameter( + names = { "--output-catalog-path", "-o" }, + description = "Path of the output OWL catalog (Required)", + validateWith = Oml2OwlApp.OutputCatalogPath.class, + required = true, + order = 2) + private String outputCatalogPath; + + @Parameter( + names = { "--disjoint-unions", "-u" }, + description = "Create disjoint union axioms", + order = 3) + private boolean disjointUnions = false; + + @Parameter( + names = { "--annotations-on-axioms", "-a" }, + description = "Emit annotations on axioms", + order = 4) + private boolean annotationsOnAxioms = false; + + @Parameter( + names = { "--debug", "-d" }, + description = "Shows debug logging statements", + order = 5) + private boolean debug; + + @Parameter( + names = { "--help", "-h" }, + description = "Displays summary of options", + help = true, + order = 6) + private boolean help; + + private final Logger LOGGER = LogManager.getLogger(Oml2OwlApp.class); + + public static void main(final String... args) throws Exception { + final Oml2OwlApp app = new Oml2OwlApp(); + final JCommander builder = JCommander.newBuilder().addObject(app).build(); + builder.parse(args); + if (app.help) { + builder.usage(); + return; + } + if (app.debug) { + final Appender appender = LogManager.getRootLogger().getAppender("stdout"); + ((AppenderSkeleton) appender).setThreshold(Level.DEBUG); + } + app.run(); + } + + public void run() throws Exception { + LOGGER.info("================================================================="); + LOGGER.info(" S T A R T"); + LOGGER.info(" OML to Owl "+getAppVersion()); + LOGGER.info("================================================================="); + LOGGER.info("Input catalog path= " + inputCatalogPath); + LOGGER.info("Output catalog path= " + outputCatalogPath); + + OmlStandaloneSetup.doSetup(); + OmlXMIResourceFactory.register(); + final XtextResourceSet inputResourceSet = new XtextResourceSet(); + + // collect OML files + final File inputCatalogFile = new File(inputCatalogPath); + final File inputFolder = inputCatalogFile.getParentFile(); + final Collection inputFiles = collectOMLFiles(inputFolder); + + // load the OML otologies + for (final File inputFile : inputFiles) { + final URI inputURI = URI.createFileURI(inputFile.getAbsolutePath()); + LOGGER.info(("Reading: " + inputURI)); + Resource r = inputResourceSet.getResource(inputURI, true); + OmlValidator.validate(OmlRead.getOntology(r)); + } + + // create OWL manager + final OWLOntologyManager ontologyManager = OWLManager.createOWLOntologyManager(); + final OwlApi owl2api = new OwlApi(ontologyManager, annotationsOnAxioms); + final Map outputFiles = new LinkedHashMap<>(); + final Map oml2owl = new LinkedHashMap<>(); + + // get the output OWL folder + final File outputCatalogFile = new File(outputCatalogPath); + final String outputFolderPath = outputCatalogFile.getParent(); + + // create the equivalent OWL ontologies + final ArrayList> callables = new ArrayList<>(); + for (final File inputFile : inputFiles) { + final URI inputURI = URI.createFileURI(inputFile.getAbsolutePath()); + final Resource inputResource = inputResourceSet.getResource(inputURI, true); + final boolean builtin = Oml2Owl.isBuiltInOntology(OmlRead.getOntology(inputResource).getIri()); + if (inputResource != null && !builtin) { + String relativePath = outputFolderPath+File.separator+inputFolder.toURI().relativize(inputFile.toURI()).getPath(); + final File outputFile = new File(relativePath.substring(0, relativePath.lastIndexOf('.')+1)+"owl"); + callables.add(new Callable() { + @Override + public Void call() throws Exception { + LOGGER.info(("Creating: " + outputFile)); + final OWLOntology owlOntology = new Oml2Owl(inputResource, owl2api).run(); + outputFiles.put(outputFile, owlOntology); + oml2owl.put(inputResource, owlOntology); + LOGGER.info(("Created: " + outputFile)); + return null; + } + }); + } + } + + ForkJoinPool forkJoinPool = new ForkJoinPool(); + forkJoinPool.invokeAll(callables); + + // run the vocabulary bundle closure algorithm + oml2owl.entrySet().stream().filter(e -> OmlRead.getOntology(e.getKey()) instanceof VocabularyBundle).forEach(entry -> { + LOGGER.info("Closing vocabulary bundle: "+entry.getKey().getURI()); + new CloseVocabularyBundleToOwl(entry.getKey(), entry.getValue(), disjointUnions, owl2api).run(); + }); + + // run the description bundle closure algorithm + oml2owl.entrySet().stream().filter(e -> OmlRead.getOntology(e.getKey()) instanceof DescriptionBundle).forEach(entry -> { + LOGGER.info("Closing description bundle: "+entry.getKey().getURI()); + new CloseDescriptionBundleToOwl(entry.getKey(), entry.getValue(), owl2api).run(); + }); + + // save the output resources + final ArrayList> callables2 = new ArrayList<>(); + outputFiles.forEach((file, owlOntology) -> { + callables2.add(new Callable() { + @Override + public Void call() throws Exception { + LOGGER.info("Saving: "+file); + ontologyManager.saveOntology(owlOntology, /*new TurtleDocumentFormat,*/ IRI.create(file)); + return null; + } + }); + }); + forkJoinPool.invokeAll(callables2); + + // create the equivalent OWL catalog + copyCatalog(inputCatalogFile, outputCatalogFile); + + LOGGER.info("================================================================="); + LOGGER.info(" E N D"); + LOGGER.info("================================================================="); + } + + private Collection collectOMLFiles(final File directory) { + final ArrayList omlFiles = new ArrayList(); + for (final File file : directory.listFiles()) { + if (file.isFile()) { + if (OML.equals(getFileExtension(file)) || OMLXMI.equals(getFileExtension(file))) { + omlFiles.add(file); + } + } else if (file.isDirectory()) { + omlFiles.addAll(collectOMLFiles(file)); + } + } + return omlFiles; + } + + private void copyCatalog(final File inputCatalogFile, final File outputCatalogFile) throws Exception { + LOGGER.info(("Saving: " + inputCatalogFile)); + Files.copy(Paths.get(inputCatalogFile.getPath()), Paths.get(outputCatalogFile.getPath()), StandardCopyOption.REPLACE_EXISTING); + final OmlCatalog inputCatalog = OmlCatalog.create(inputCatalogFile.toURI().toURL()); + List _nestedCatalogs = inputCatalog.getNestedCatalogs(); + for (final String c : _nestedCatalogs) { + final java.net.URI uri = new URL(c).toURI(); + final File nestedInputCatalogFile = new File(uri); + String relativePath = inputCatalogFile.getParentFile().toURI().relativize(uri).getPath(); + final File nestedOutputCatalogFile = new File(outputCatalogFile.getParent()+File.separator+relativePath); + copyCatalog(nestedInputCatalogFile, nestedOutputCatalogFile); + } + } + + private String getFileExtension(final File file) { + final String fileName = file.getName(); + if(fileName.lastIndexOf(".") != -1) + return fileName.substring(fileName.lastIndexOf(".")+1); + else + return ""; + } + + /** + * Get application version id from properties file. + * + * @return version string from build.properties or UNKNOWN + */ + private String getAppVersion() { + String version = "UNKNOWN"; + try { + InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream("version.txt"); + InputStreamReader reader = new InputStreamReader(input); + version = CharStreams.toString(reader); + } catch (IOException e) { + String errorMsg = "Could not read version.txt file." + e; + LOGGER.error(errorMsg, e); + } + return version; + } + + public static class InputCatalogPath implements IParameterValidator { + @Override + public void validate(final String name, final String value) throws ParameterException { + final File file = new File(value); + if (!file.getName().endsWith("catalog.xml")) { + throw new ParameterException((("Parameter " + name) + " should be a valid OWL catalog path")); + } + } + } + + public static class OutputCatalogPath implements IParameterValidator { + @Override + public void validate(final String name, final String value) throws ParameterException { + final File file = new File(value); + if (!file.getName().endsWith("catalog.xml")) { + throw new ParameterException((("Parameter " + name) + " should be a valid OWL catalog path")); + } + final File folder = file.getParentFile(); + folder.mkdirs(); + } + } + +} diff --git a/oml2owl/src/main/java/io/opencaesar/oml2owl/OmlConstants.java b/oml2owl/src/main/java/io/opencaesar/oml2owl/OmlConstants.java new file mode 100644 index 0000000..ea3c3df --- /dev/null +++ b/oml2owl/src/main/java/io/opencaesar/oml2owl/OmlConstants.java @@ -0,0 +1,44 @@ +package io.opencaesar.oml2owl; + +public interface OmlConstants { + + static final String omlPath = "opencaesar.io/oml"; + + static final String omlIRI = "http://" + OmlConstants.omlPath; + + static final String omlNS = OmlConstants.omlIRI + "#"; + + static final String ontologyType = OmlConstants.omlNS + "ontologyType"; + + static final String Vocabulary = OmlConstants.omlNS + "Vocabulary"; + + static final String VocabularyBundle = OmlConstants.omlNS + "VocabularyBundle"; + + static final String Description = OmlConstants.omlNS + "Description"; + + static final String DescriptionBundle = OmlConstants.omlNS + "DescriptionBundle"; + + static final String Aspect = OmlConstants.omlNS + "Aspect"; + + static final String Concept = OmlConstants.omlNS + "Concept"; + + static final String RelationEntity = OmlConstants.omlNS + "RelationEntity"; + + static final String Structure = OmlConstants.omlNS + "Structure"; + + static final String forwardRelation = OmlConstants.omlNS + "forwardRelation"; + + static final String reverseRelation = OmlConstants.omlNS + "reverseRelation"; + + static final String sourceRelation = OmlConstants.omlNS + "sourceRelation"; + + static final String targetRelation = OmlConstants.omlNS + "targetRelation"; + + static final String inverseSourceRelation = OmlConstants.omlNS + "inverseSourceRelation"; + + static final String inverseTargetRelation = OmlConstants.omlNS + "inverseTargetRelation"; + + static final String structuredProperty = OmlConstants.omlNS + "structuredProperty"; + + static final String scalarProperty = OmlConstants.omlNS + "scalarProperty"; +} diff --git a/oml2owl/src/main/java/io/opencaesar/oml2owl/OwlApi.java b/oml2owl/src/main/java/io/opencaesar/oml2owl/OwlApi.java new file mode 100644 index 0000000..51be527 --- /dev/null +++ b/oml2owl/src/main/java/io/opencaesar/oml2owl/OwlApi.java @@ -0,0 +1,580 @@ +package io.opencaesar.oml2owl; + +import java.math.BigDecimal; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +import org.semanticweb.owlapi.model.AddImport; +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.OWLAnnotationProperty; +import org.semanticweb.owlapi.model.OWLAnnotationValue; +import org.semanticweb.owlapi.model.OWLAnonymousIndividual; +import org.semanticweb.owlapi.model.OWLAsymmetricObjectPropertyAxiom; +import org.semanticweb.owlapi.model.OWLClass; +import org.semanticweb.owlapi.model.OWLClassAssertionAxiom; +import org.semanticweb.owlapi.model.OWLDataAllValuesFrom; +import org.semanticweb.owlapi.model.OWLDataExactCardinality; +import org.semanticweb.owlapi.model.OWLDataHasValue; +import org.semanticweb.owlapi.model.OWLDataMaxCardinality; +import org.semanticweb.owlapi.model.OWLDataMinCardinality; +import org.semanticweb.owlapi.model.OWLDataOneOf; +import org.semanticweb.owlapi.model.OWLDataProperty; +import org.semanticweb.owlapi.model.OWLDataPropertyAssertionAxiom; +import org.semanticweb.owlapi.model.OWLDataPropertyDomainAxiom; +import org.semanticweb.owlapi.model.OWLDataPropertyRangeAxiom; +import org.semanticweb.owlapi.model.OWLDataSomeValuesFrom; +import org.semanticweb.owlapi.model.OWLDatatype; +import org.semanticweb.owlapi.model.OWLDatatypeDefinitionAxiom; +import org.semanticweb.owlapi.model.OWLDatatypeRestriction; +import org.semanticweb.owlapi.model.OWLDeclarationAxiom; +import org.semanticweb.owlapi.model.OWLFacetRestriction; +import org.semanticweb.owlapi.model.OWLFunctionalDataPropertyAxiom; +import org.semanticweb.owlapi.model.OWLFunctionalObjectPropertyAxiom; +import org.semanticweb.owlapi.model.OWLHasKeyAxiom; +import org.semanticweb.owlapi.model.OWLImportsDeclaration; +import org.semanticweb.owlapi.model.OWLIndividual; +import org.semanticweb.owlapi.model.OWLInverseFunctionalObjectPropertyAxiom; +import org.semanticweb.owlapi.model.OWLInverseObjectPropertiesAxiom; +import org.semanticweb.owlapi.model.OWLIrreflexiveObjectPropertyAxiom; +import org.semanticweb.owlapi.model.OWLLiteral; +import org.semanticweb.owlapi.model.OWLNamedIndividual; +import org.semanticweb.owlapi.model.OWLObjectAllValuesFrom; +import org.semanticweb.owlapi.model.OWLObjectExactCardinality; +import org.semanticweb.owlapi.model.OWLObjectHasValue; +import org.semanticweb.owlapi.model.OWLObjectMaxCardinality; +import org.semanticweb.owlapi.model.OWLObjectMinCardinality; +import org.semanticweb.owlapi.model.OWLObjectProperty; +import org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom; +import org.semanticweb.owlapi.model.OWLObjectPropertyDomainAxiom; +import org.semanticweb.owlapi.model.OWLObjectPropertyRangeAxiom; +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.OWLReflexiveObjectPropertyAxiom; +import org.semanticweb.owlapi.model.OWLSubClassOfAxiom; +import org.semanticweb.owlapi.model.OWLSubDataPropertyOfAxiom; +import org.semanticweb.owlapi.model.OWLSubObjectPropertyOfAxiom; +import org.semanticweb.owlapi.model.OWLSymmetricObjectPropertyAxiom; +import org.semanticweb.owlapi.model.OWLTransitiveObjectPropertyAxiom; +import org.semanticweb.owlapi.model.SWRLAtom; +import org.semanticweb.owlapi.model.SWRLClassAtom; +import org.semanticweb.owlapi.model.SWRLDifferentIndividualsAtom; +import org.semanticweb.owlapi.model.SWRLObjectPropertyAtom; +import org.semanticweb.owlapi.model.SWRLRule; +import org.semanticweb.owlapi.model.SWRLSameIndividualAtom; +import org.semanticweb.owlapi.model.SWRLVariable; +import org.semanticweb.owlapi.vocab.OWLFacet; + +public class OwlApi extends io.opencaesar.closeworld.OwlApi { + + private final String XSD = "http://www.w3.org/2001/XMLSchema#"; + + protected final boolean annotationsOnAxioms; + + public OwlApi(final OWLOntologyManager manager, final boolean annotationsOnAxioms) { + super(manager); + this.annotationsOnAxioms = annotationsOnAxioms; + } + + public IRI createIri(final String iri) { + return IRI.create(iri); + } + + public OWLOntology createOntology(final String iri) { + try { + return manager.createOntology(IRI.create(iri)); + } catch (OWLOntologyCreationException e) { + e.printStackTrace(); + return null; + } + } + + public OWLImportsDeclaration addImportsDeclaration(final OWLOntology ontology, final String iri) { + final OWLImportsDeclaration import_ = factory.getOWLImportsDeclaration(IRI.create(iri)); + manager.applyChanges(new AddImport(ontology, import_)); + return import_; + } + + public OWLClass addClass(final OWLOntology ontology, final String iri) { + final OWLClass class_ = factory.getOWLClass(iri); + final OWLDeclarationAxiom axiom = factory.getOWLDeclarationAxiom(class_); + manager.addAxiom(ontology, axiom); + return class_; + } + + public OWLDatatype addDatatype(final OWLOntology ontology, final String iri) { + final OWLDatatype datatype = factory.getOWLDatatype(iri); + final OWLDeclarationAxiom axiom = factory.getOWLDeclarationAxiom(datatype); + manager.addAxiom(ontology, axiom); + return datatype; + } + + public OWLDatatypeDefinitionAxiom addDatatypeDefinition(final OWLOntology ontology, final String datatypeIri, final String restrictedIri, final OWLFacetRestriction[] restrictions, final OWLAnnotation... annotations) { + final OWLDatatype datatype = factory.getOWLDatatype(datatypeIri); + final OWLDatatype restrictedDatatype = factory.getOWLDatatype(restrictedIri); + final OWLDatatypeRestriction restriction = factory.getOWLDatatypeRestriction(restrictedDatatype, restrictions); + final OWLDatatypeDefinitionAxiom axiom = factory.getOWLDatatypeDefinitionAxiom(datatype, restriction, checkIfNeeded(annotations)); + manager.addAxiom(ontology, axiom); + return axiom; + } + + public OWLDatatypeDefinitionAxiom addDatatypeDefinition(final OWLOntology ontology, final String datatypeIri, final String synonymIri, final OWLAnnotation... annotations) { + final OWLDatatype datatype = factory.getOWLDatatype(datatypeIri); + final OWLDatatype synonymDatatype = factory.getOWLDatatype(synonymIri); + final OWLDatatypeDefinitionAxiom axiom = factory.getOWLDatatypeDefinitionAxiom(datatype, synonymDatatype, checkIfNeeded(annotations)); + manager.addAxiom(ontology, axiom); + return axiom; + } + + public OWLDataOneOf addDataOneOf(final OWLOntology ontology, final String subIri, final OWLLiteral... literals) { + final OWLDatatype datatype = factory.getOWLDatatype(subIri); + final OWLDataOneOf dataOneOf = factory.getOWLDataOneOf(literals); + final OWLDatatypeDefinitionAxiom axiom = factory.getOWLDatatypeDefinitionAxiom(datatype, dataOneOf); + manager.addAxiom(ontology, axiom); + return dataOneOf; + } + + public OWLObjectProperty addObjectProperty(final OWLOntology ontology, final String iri) { + final OWLObjectProperty property = factory.getOWLObjectProperty(iri); + final OWLDeclarationAxiom axiom = factory.getOWLDeclarationAxiom(property); + manager.addAxiom(ontology, axiom); + return property; + } + + public OWLObjectProperty addFunctionalObjectProperty(final OWLOntology ontology, final String iri) { + final OWLObjectProperty property = factory.getOWLObjectProperty(iri); + final OWLFunctionalObjectPropertyAxiom axiom = factory.getOWLFunctionalObjectPropertyAxiom(property); + manager.addAxiom(ontology, axiom); + return property; + } + + public OWLObjectProperty addInverseFunctionalObjectProperty(final OWLOntology ontology, final String iri) { + final OWLObjectProperty property = factory.getOWLObjectProperty(iri); + final OWLInverseFunctionalObjectPropertyAxiom axiom = factory.getOWLInverseFunctionalObjectPropertyAxiom(property); + manager.addAxiom(ontology, axiom); + return property; + } + + public OWLObjectProperty addSymmetricObjectProperty(final OWLOntology ontology, final String iri) { + final OWLObjectProperty property = factory.getOWLObjectProperty(iri); + final OWLSymmetricObjectPropertyAxiom axiom = factory.getOWLSymmetricObjectPropertyAxiom(property); + manager.addAxiom(ontology, axiom); + return property; + } + + public OWLObjectProperty addAsymmetricObjectProperty(final OWLOntology ontology, final String iri) { + final OWLObjectProperty property = factory.getOWLObjectProperty(iri); + final OWLAsymmetricObjectPropertyAxiom axiom = factory.getOWLAsymmetricObjectPropertyAxiom(property); + manager.addAxiom(ontology, axiom); + return property; + } + + public OWLObjectProperty addReflexiveObjectProperty(final OWLOntology ontology, final String iri) { + final OWLObjectProperty property = factory.getOWLObjectProperty(iri); + final OWLReflexiveObjectPropertyAxiom axiom = factory.getOWLReflexiveObjectPropertyAxiom(property); + manager.addAxiom(ontology, axiom); + return property; + } + + public OWLObjectProperty addIrreflexiveObjectProperty(final OWLOntology ontology, final String iri) { + final OWLObjectProperty property = factory.getOWLObjectProperty(iri); + final OWLIrreflexiveObjectPropertyAxiom axiom = factory.getOWLIrreflexiveObjectPropertyAxiom(property); + manager.addAxiom(ontology, axiom); + return property; + } + + public OWLObjectProperty addTransitiveObjectProperty(final OWLOntology ontology, final String iri) { + final OWLObjectProperty property = factory.getOWLObjectProperty(iri); + final OWLTransitiveObjectPropertyAxiom axiom = factory.getOWLTransitiveObjectPropertyAxiom(property); + manager.addAxiom(ontology, axiom); + return property; + } + + public OWLDataProperty addDataProperty(final OWLOntology ontology, final String iri) { + final OWLDataProperty property = factory.getOWLDataProperty(iri); + final OWLDeclarationAxiom axiom = factory.getOWLDeclarationAxiom(property); + manager.addAxiom(ontology, axiom); + return property; + } + + public OWLDataProperty addFunctionalDataProperty(final OWLOntology ontology, final String iri) { + final OWLDataProperty property = factory.getOWLDataProperty(iri); + final OWLFunctionalDataPropertyAxiom axiom = factory.getOWLFunctionalDataPropertyAxiom(property); + manager.addAxiom(ontology, axiom); + return property; + } + + public OWLAnnotationProperty addAnnotationProperty(final OWLOntology ontology, final String iri) { + final OWLAnnotationProperty property = factory.getOWLAnnotationProperty(iri); + final OWLDeclarationAxiom axiom = factory.getOWLDeclarationAxiom(property); + manager.addAxiom(ontology, axiom); + return property; + } + + public OWLNamedIndividual addNamedIndividual(final OWLOntology ontology, final String iri) { + final OWLNamedIndividual individual = factory.getOWLNamedIndividual(iri); + final OWLDeclarationAxiom axiom = factory.getOWLDeclarationAxiom(individual); + manager.addAxiom(ontology, axiom); + return individual; + } + + public OWLNamedIndividual getNamedIndividual(final String nodeId) { + return factory.getOWLNamedIndividual(nodeId); + } + + public OWLAnonymousIndividual getAnonymousIndividual(final String nodeId) { + return factory.getOWLAnonymousIndividual(nodeId); + } + + public SWRLRule addRule(final OWLOntology ontology, final List head, final List body, final OWLAnnotation... annotations) { + final SWRLRule axiom = factory.getSWRLRule(body, head, Arrays.asList(annotations)); + manager.addAxiom(ontology, axiom); + return axiom; + } + + public SWRLClassAtom getClassAtom(final String classIri, final String variableIri) { + final OWLClass class_ = factory.getOWLClass(classIri); + final SWRLVariable variable = factory.getSWRLVariable(variableIri); + return factory.getSWRLClassAtom(class_, variable); + } + + public SWRLObjectPropertyAtom getObjectPropertyAtom(final String propertyIri, final String variable1Iri, final String variable2Iri) { + final OWLObjectProperty property = factory.getOWLObjectProperty(propertyIri); + final SWRLVariable variable1 = factory.getSWRLVariable(variable1Iri); + final SWRLVariable variable2 = factory.getSWRLVariable(variable2Iri); + return factory.getSWRLObjectPropertyAtom(property, variable1, variable2); + } + + public SWRLSameIndividualAtom getSameIndividualAtom(final String variable1Iri, final String variable2Iri) { + final SWRLVariable variable1 = factory.getSWRLVariable(variable1Iri); + final SWRLVariable variable2 = factory.getSWRLVariable(variable2Iri); + return factory.getSWRLSameIndividualAtom(variable1, variable2); + } + + public SWRLDifferentIndividualsAtom getDifferentIndividualsAtom(final String variable1Iri, final String variable2Iri) { + final SWRLVariable variable1 = factory.getSWRLVariable(variable1Iri); + final SWRLVariable variable2 = factory.getSWRLVariable(variable2Iri); + return factory.getSWRLDifferentIndividualsAtom(variable1, variable2); + } + + public OWLSubClassOfAxiom addSubClassOf(final OWLOntology ontology, final String subIri, final String superIri, final OWLAnnotation... annotations) { + final OWLClass subClass = factory.getOWLClass(subIri); + final OWLClass supClass = factory.getOWLClass(superIri); + final OWLSubClassOfAxiom axiom = factory.getOWLSubClassOfAxiom(subClass, supClass, checkIfNeeded(annotations)); + manager.addAxiom(ontology, axiom); + return axiom; + } + + public OWLHasKeyAxiom addHasKey(final OWLOntology ontology, final String classIri, final List keyPropertyIris, final OWLAnnotation... annotations) { + final OWLClass aClass = factory.getOWLClass(classIri); + final List keyProperties = keyPropertyIris.stream().map(iri -> factory.getOWLDataProperty(iri)).collect(Collectors.toList()); + final OWLHasKeyAxiom axiom = factory.getOWLHasKeyAxiom(aClass, keyProperties, checkIfNeeded(annotations)); + manager.addAxiom(ontology, axiom); + return axiom; + } + + public OWLSubClassOfAxiom addObjectSomeValuesFrom(final OWLOntology ontology, final String classIri, final String propertyIri, final String typeIri, final OWLAnnotation... annotations) { + final OWLClass class_ = factory.getOWLClass(classIri); + final OWLObjectProperty property = factory.getOWLObjectProperty(propertyIri); + final OWLClass type = factory.getOWLClass(typeIri); + final OWLObjectSomeValuesFrom restriction = factory.getOWLObjectSomeValuesFrom(property, type); + final OWLSubClassOfAxiom axiom = factory.getOWLSubClassOfAxiom(class_, restriction, checkIfNeeded(annotations)); + manager.addAxiom(ontology, axiom); + return axiom; + } + + public OWLSubClassOfAxiom addObjectAllValuesFrom(final OWLOntology ontology, final String classIri, final String propertyIri, final String typeIri, final OWLAnnotation... annotations) { + final OWLClass class_ = factory.getOWLClass(classIri); + final OWLObjectProperty property = factory.getOWLObjectProperty(propertyIri); + final OWLClass type = factory.getOWLClass(typeIri); + final OWLObjectAllValuesFrom restriction = factory.getOWLObjectAllValuesFrom(property, type); + final OWLSubClassOfAxiom axiom = factory.getOWLSubClassOfAxiom(class_, restriction, checkIfNeeded(annotations)); + manager.addAxiom(ontology, axiom); + return axiom; + } + + public OWLSubClassOfAxiom addObjectHasValue(final OWLOntology ontology, final String classIri, final String propertyIri, final OWLIndividual individual, final OWLAnnotation... annotations) { + final OWLClass class_ = factory.getOWLClass(classIri); + final OWLObjectProperty property = factory.getOWLObjectProperty(propertyIri); + final OWLObjectHasValue restriction = factory.getOWLObjectHasValue(property, individual); + final OWLSubClassOfAxiom axiom = factory.getOWLSubClassOfAxiom(class_, restriction, checkIfNeeded(annotations)); + manager.addAxiom(ontology, axiom); + return axiom; + } + + public OWLSubClassOfAxiom addObjectHasValue(final OWLOntology ontology, final String classIri, final String propertyIri, final String individualIri, final OWLAnnotation... annotations) { + final OWLClass class_ = factory.getOWLClass(classIri); + final OWLObjectProperty property = factory.getOWLObjectProperty(propertyIri); + final OWLNamedIndividual individual = factory.getOWLNamedIndividual(individualIri); + final OWLObjectHasValue restriction = factory.getOWLObjectHasValue(property, individual); + final OWLSubClassOfAxiom axiom = factory.getOWLSubClassOfAxiom(class_, restriction, checkIfNeeded(annotations)); + manager.addAxiom(ontology, axiom); + return axiom; + } + + public OWLSubClassOfAxiom addObjectExactCardinality(final OWLOntology ontology, final String classIri, final String propertyIri, final int cardinality, final String rangeIri, final OWLAnnotation... annotations) { + final OWLClass class_ = factory.getOWLClass(classIri); + final OWLObjectProperty property = factory.getOWLObjectProperty(propertyIri); + final OWLObjectExactCardinality restriction; + if (rangeIri != null) { + restriction = factory.getOWLObjectExactCardinality(cardinality, property, factory.getOWLClass(rangeIri)); + } else { + restriction = factory.getOWLObjectExactCardinality(cardinality, property); + } + final OWLSubClassOfAxiom axiom = factory.getOWLSubClassOfAxiom(class_, restriction, checkIfNeeded(annotations)); + manager.addAxiom(ontology, axiom); + return axiom; + } + + public OWLSubClassOfAxiom addObjectMinCardinality(final OWLOntology ontology, final String classIri, final String propertyIri, final int cardinality, final String rangeIri, final OWLAnnotation... annotations) { + final OWLClass class_ = factory.getOWLClass(classIri); + final OWLObjectProperty property = factory.getOWLObjectProperty(propertyIri); + final OWLObjectMinCardinality restriction; + if (rangeIri != null) { + restriction = factory.getOWLObjectMinCardinality(cardinality, property, factory.getOWLClass(rangeIri)); + } else { + restriction = factory.getOWLObjectMinCardinality(cardinality, property); + } + final OWLSubClassOfAxiom axiom = factory.getOWLSubClassOfAxiom(class_, restriction, checkIfNeeded(annotations)); + manager.addAxiom(ontology, axiom); + return axiom; + } + + public OWLSubClassOfAxiom addObjectMaxCardinality(final OWLOntology ontology, final String classIri, final String propertyIri, final int cardinality, final String rangeIri, final OWLAnnotation... annotations) { + final OWLClass class_ = factory.getOWLClass(classIri); + final OWLObjectProperty property = factory.getOWLObjectProperty(propertyIri); + final OWLObjectMaxCardinality restriction; + if (rangeIri != null) { + restriction = factory.getOWLObjectMaxCardinality(cardinality, property, factory.getOWLClass(rangeIri)); + } else { + restriction = factory.getOWLObjectMaxCardinality(cardinality, property); + } + final OWLSubClassOfAxiom axiom = factory.getOWLSubClassOfAxiom(class_, restriction, checkIfNeeded(annotations)); + manager.addAxiom(ontology, axiom); + return axiom; + } + + public OWLSubClassOfAxiom addDataExactCardinality(final OWLOntology ontology, final String classIri, final String propertyIri, final int cardinality, final String rangeIri, final OWLAnnotation... annotations) { + final OWLClass class_ = factory.getOWLClass(classIri); + final OWLDataProperty property = factory.getOWLDataProperty(propertyIri); + final OWLDataExactCardinality restriction; + if (rangeIri != null) { + restriction = factory.getOWLDataExactCardinality(cardinality, property, factory.getOWLDatatype(rangeIri)); + } else { + restriction = factory.getOWLDataExactCardinality(cardinality, property); + } + final OWLSubClassOfAxiom axiom = factory.getOWLSubClassOfAxiom(class_, restriction, checkIfNeeded(annotations)); + manager.addAxiom(ontology, axiom); + return axiom; + } + + public OWLSubClassOfAxiom addDataMinCardinality(final OWLOntology ontology, final String classIri, final String propertyIri, final int cardinality, final String rangeIri, final OWLAnnotation... annotations) { + final OWLClass class_ = factory.getOWLClass(classIri); + final OWLDataProperty property = factory.getOWLDataProperty(propertyIri); + final OWLDataMinCardinality restriction; + if (rangeIri != null) { + restriction = factory.getOWLDataMinCardinality(cardinality, property, factory.getOWLDatatype(rangeIri)); + } else { + restriction = factory.getOWLDataMinCardinality(cardinality, property); + } + final OWLSubClassOfAxiom axiom = factory.getOWLSubClassOfAxiom(class_, restriction, checkIfNeeded(annotations)); + manager.addAxiom(ontology, axiom); + return axiom; + } + + public OWLSubClassOfAxiom addDataMaxCardinality(final OWLOntology ontology, final String classIri, final String propertyIri, final int cardinality, final String rangeIri, final OWLAnnotation... annotations) { + final OWLClass class_ = factory.getOWLClass(classIri); + final OWLDataProperty property = factory.getOWLDataProperty(propertyIri); + final OWLDataMaxCardinality restriction; + if (rangeIri != null) { + restriction = factory.getOWLDataMaxCardinality(cardinality, property, factory.getOWLDatatype(rangeIri)); + } else { + restriction = factory.getOWLDataMaxCardinality(cardinality, property); + } + final OWLSubClassOfAxiom axiom = factory.getOWLSubClassOfAxiom(class_, restriction, checkIfNeeded(annotations)); + manager.addAxiom(ontology, axiom); + return axiom; + } + + public OWLSubClassOfAxiom addDataSomeValuesFrom(final OWLOntology ontology, final String classIri, final String propertyIri, final String typeIri, final OWLAnnotation... annotations) { + final OWLClass class_ = factory.getOWLClass(classIri); + final OWLDataProperty property = factory.getOWLDataProperty(propertyIri); + final OWLDatatype type = factory.getOWLDatatype(typeIri); + final OWLDataSomeValuesFrom restriction = factory.getOWLDataSomeValuesFrom(property, type); + final OWLSubClassOfAxiom axiom = factory.getOWLSubClassOfAxiom(class_, restriction, checkIfNeeded(annotations)); + manager.addAxiom(ontology, axiom); + return axiom; + } + + public OWLSubClassOfAxiom addDataAllValuesFrom(final OWLOntology ontology, final String classIri, final String propertyIri, final String typeIri, final OWLAnnotation... annotations) { + final OWLClass class_ = factory.getOWLClass(classIri); + final OWLDataProperty property = factory.getOWLDataProperty(propertyIri); + final OWLDatatype type = factory.getOWLDatatype(typeIri); + final OWLDataAllValuesFrom restriction = factory.getOWLDataAllValuesFrom(property, type); + final OWLSubClassOfAxiom axiom = factory.getOWLSubClassOfAxiom(class_, restriction, checkIfNeeded(annotations)); + manager.addAxiom(ontology, axiom); + return axiom; + } + + public OWLSubClassOfAxiom addDataHasValue(final OWLOntology ontology, final String classIri, final String propertyIri, final OWLLiteral literal, final OWLAnnotation... annotations) { + final OWLClass class_ = factory.getOWLClass(classIri); + final OWLDataProperty property = factory.getOWLDataProperty(propertyIri); + final OWLDataHasValue restriction = factory.getOWLDataHasValue(property, literal); + final OWLSubClassOfAxiom axiom = factory.getOWLSubClassOfAxiom(class_, restriction, checkIfNeeded(annotations)); + manager.addAxiom(ontology, axiom); + return axiom; + } + + public OWLSubObjectPropertyOfAxiom addSubObjectPropertyOf(final OWLOntology ontology, final String subPropertyIri, final String superPropertyIri, final OWLAnnotation... annotations) { + final OWLObjectProperty subProperty = factory.getOWLObjectProperty(subPropertyIri); + final OWLObjectProperty supProperty = factory.getOWLObjectProperty(superPropertyIri); + final OWLSubObjectPropertyOfAxiom axiom = factory.getOWLSubObjectPropertyOfAxiom(subProperty, supProperty, checkIfNeeded(annotations)); + manager.addAxiom(ontology, axiom); + return axiom; + } + + public OWLObjectPropertyDomainAxiom addObjectPropertyDomain(final OWLOntology ontology, final String propertyIri, final String domainIri) { + final OWLObjectProperty property = factory.getOWLObjectProperty(propertyIri); + final OWLClass domain = factory.getOWLClass(domainIri); + final OWLObjectPropertyDomainAxiom axiom = factory.getOWLObjectPropertyDomainAxiom(property, domain); + manager.addAxiom(ontology, axiom); + return axiom; + } + + public OWLObjectPropertyRangeAxiom addObjectPropertyRange(final OWLOntology ontology, final String propertyIri, final String rangeIri) { + final OWLObjectProperty property = factory.getOWLObjectProperty(propertyIri); + final OWLClass range = factory.getOWLClass(rangeIri); + final OWLObjectPropertyRangeAxiom axiom = factory.getOWLObjectPropertyRangeAxiom(property, range); + manager.addAxiom(ontology, axiom); + return axiom; + } + + public OWLSubDataPropertyOfAxiom addSubDataPropertyOf(final OWLOntology ontology, final String subPropertyIri, final String superPropertyIri, final OWLAnnotation... annotations) { + final OWLDataProperty subProperty = factory.getOWLDataProperty(subPropertyIri); + final OWLDataProperty supProperty = factory.getOWLDataProperty(superPropertyIri); + final OWLSubDataPropertyOfAxiom axiom = factory.getOWLSubDataPropertyOfAxiom(subProperty, supProperty, checkIfNeeded(annotations)); + manager.addAxiom(ontology, axiom); + return axiom; + } + + public OWLDataPropertyDomainAxiom addDataPropertyDomain(final OWLOntology ontology, final String propertyIri, final String domainIri) { + final OWLDataProperty property = factory.getOWLDataProperty(propertyIri); + final OWLClass domain = factory.getOWLClass(domainIri); + final OWLDataPropertyDomainAxiom axiom = factory.getOWLDataPropertyDomainAxiom(property, domain); + manager.addAxiom(ontology, axiom); + return axiom; + } + + public OWLDataPropertyRangeAxiom addDataPropertyRange(final OWLOntology ontology, final String propertyIri, final String rangeIri) { + final OWLDataProperty property = factory.getOWLDataProperty(propertyIri); + final OWLDatatype range = factory.getOWLDatatype(rangeIri); + final OWLDataPropertyRangeAxiom axiom = factory.getOWLDataPropertyRangeAxiom(property, range); + manager.addAxiom(ontology, axiom); + return axiom; + } + + public OWLInverseObjectPropertiesAxiom addInverseProperties(final OWLOntology ontology, final String forwardPropertyIri, final String reversePropertyIri) { + final OWLObjectProperty forwardproperty = factory.getOWLObjectProperty(forwardPropertyIri); + final OWLObjectProperty reverseProperty = factory.getOWLObjectProperty(reversePropertyIri); + final OWLInverseObjectPropertiesAxiom axiom = factory.getOWLInverseObjectPropertiesAxiom(forwardproperty, reverseProperty); + manager.addAxiom(ontology, axiom); + return axiom; + } + + public OWLClassAssertionAxiom addClassAssertion(final OWLOntology ontology, final String individualIri, final String classIri, final OWLAnnotation... annotations) { + final OWLNamedIndividual individual = factory.getOWLNamedIndividual(individualIri); + final OWLClass class_ = factory.getOWLClass(classIri); + final OWLClassAssertionAxiom axiom = factory.getOWLClassAssertionAxiom(class_, individual, checkIfNeeded(annotations)); + manager.addAxiom(ontology, axiom); + return axiom; + } + + public OWLObjectPropertyAssertionAxiom addObjectPropertyAssertion(final OWLOntology ontology, final String individualIri, final String propertyIri, final String objectIri, final OWLAnnotation... annotations) { + final OWLNamedIndividual object = factory.getOWLNamedIndividual(objectIri); + final OWLNamedIndividual individual = factory.getOWLNamedIndividual(individualIri); + return addObjectPropertyAssertion(ontology, individual, propertyIri, object, annotations); + } + + public OWLObjectPropertyAssertionAxiom addObjectPropertyAssertion(final OWLOntology ontology, final OWLIndividual individual, final String propertyIri, final OWLIndividual object, final OWLAnnotation... annotations) { + final OWLObjectProperty property = factory.getOWLObjectProperty(propertyIri); + final OWLObjectPropertyAssertionAxiom axiom = factory.getOWLObjectPropertyAssertionAxiom(property, individual, object, checkIfNeeded(annotations)); + manager.addAxiom(ontology, axiom); + return axiom; + } + + public OWLDataPropertyAssertionAxiom addDataPropertyAssertion(final OWLOntology ontology, final String individualIri, final String propertyIri, final OWLLiteral literal, final OWLAnnotation... annotations) { + final OWLNamedIndividual individual = factory.getOWLNamedIndividual(individualIri); + return addDataPropertyAssertion(ontology, individual, propertyIri, literal, annotations); + } + + public OWLDataPropertyAssertionAxiom addDataPropertyAssertion(final OWLOntology ontology, final OWLIndividual individual, final String propertyIri, final OWLLiteral literal, final OWLAnnotation... annotations) { + final OWLDataProperty property = factory.getOWLDataProperty(propertyIri); + final OWLDataPropertyAssertionAxiom axiom = factory.getOWLDataPropertyAssertionAxiom(property, individual, literal, checkIfNeeded(annotations)); + manager.addAxiom(ontology, axiom); + return axiom; + } + + public OWLAnnotation getAnnotation(final String propertyIri, final OWLAnnotationValue value) { + final OWLAnnotationProperty property = factory.getOWLAnnotationProperty(propertyIri); + return factory.getOWLAnnotation(property, value); + } + + public OWLAnnotation addOntologyAnnotation(final OWLOntology ontology, final OWLAnnotation annotation) { + AddOntologyAnnotation _addOntologyAnnotation = new AddOntologyAnnotation(ontology, annotation); + manager.applyChange(_addOntologyAnnotation); + return annotation; + } + + public OWLAnnotationAssertionAxiom addAnnotationAssertion(final OWLOntology ontology, final String subjectIri, final OWLAnnotation annotation) { + final OWLAnnotationAssertionAxiom axiom = factory.getOWLAnnotationAssertionAxiom(IRI.create(subjectIri), annotation); + manager.addAxiom(ontology, axiom); + return axiom; + } + + public OWLFacetRestriction getFacetRestriction(final OWLFacet facet, final OWLLiteral value) { + return factory.getOWLFacetRestriction(facet, value); + } + + public OWLLiteral getLiteral(final boolean value) { + return factory.getOWLLiteral(value); + } + + public OWLLiteral getLiteral(final int value) { + return factory.getOWLLiteral(value); + } + + public OWLLiteral getLiteral(final double value) { + return factory.getOWLLiteral(value); + } + + public OWLLiteral getLiteral(final String value) { + return factory.getOWLLiteral(value); + } + + public OWLLiteral getLiteral(final BigDecimal value) { + return getLiteralWithDatatype(value.toString(), (XSD + "decimal")); + } + + public OWLLiteral getLiteralWithDatatype(final String value, final String datatypeIri) { + final OWLDatatype datatype = factory.getOWLDatatype(datatypeIri); + return factory.getOWLLiteral(value, datatype); + } + + public OWLLiteral getLiteralWithLangTag(final String value, final String langTag) { + return factory.getOWLLiteral(value, langTag); + } + + public List checkIfNeeded(final OWLAnnotation... annotations) { + if (annotationsOnAxioms) { + return Arrays.asList(annotations); + } else { + return Collections.emptyList(); + } + } +} diff --git a/oml2owl/src/main/resources/version.txt b/oml2owl/src/main/resources/version.txt new file mode 100644 index 0000000..8adc70f --- /dev/null +++ b/oml2owl/src/main/resources/version.txt @@ -0,0 +1 @@ +0.8.0 \ No newline at end of file diff --git a/owl-adapter/oml2owl-gradle/src/main/resources/version.txt b/owl-adapter/oml2owl-gradle/src/main/resources/version.txt deleted file mode 100755 index 8fd9b8c..0000000 --- a/owl-adapter/oml2owl-gradle/src/main/resources/version.txt +++ /dev/null @@ -1 +0,0 @@ -0.7.11 \ No newline at end of file diff --git a/owl-adapter/oml2owl/src/main/java/io/opencaesar/oml2owl/Oml2Owl.xtend b/owl-adapter/oml2owl/src/main/java/io/opencaesar/oml2owl/Oml2Owl.xtend deleted file mode 100644 index 8d5d39d..0000000 --- a/owl-adapter/oml2owl/src/main/java/io/opencaesar/oml2owl/Oml2Owl.xtend +++ /dev/null @@ -1,649 +0,0 @@ -package io.opencaesar.oml2owl - -import io.opencaesar.oml.AnnotatedElement -import io.opencaesar.oml.Annotation -import io.opencaesar.oml.AnnotationProperty -import io.opencaesar.oml.Aspect -import io.opencaesar.oml.BooleanLiteral -import io.opencaesar.oml.CardinalityRestrictionKind -import io.opencaesar.oml.Concept -import io.opencaesar.oml.ConceptInstance -import io.opencaesar.oml.ConceptInstanceReference -import io.opencaesar.oml.ConceptTypeAssertion -import io.opencaesar.oml.DecimalLiteral -import io.opencaesar.oml.Description -import io.opencaesar.oml.DescriptionBundle -import io.opencaesar.oml.DifferentFromPredicate -import io.opencaesar.oml.DoubleLiteral -import io.opencaesar.oml.EntityPredicate -import io.opencaesar.oml.EnumeratedScalar -import io.opencaesar.oml.FacetedScalar -import io.opencaesar.oml.ForwardRelation -import io.opencaesar.oml.Import -import io.opencaesar.oml.IntegerLiteral -import io.opencaesar.oml.KeyAxiom -import io.opencaesar.oml.LinkAssertion -import io.opencaesar.oml.Member -import io.opencaesar.oml.Ontology -import io.opencaesar.oml.QuotedLiteral -import io.opencaesar.oml.RangeRestrictionKind -import io.opencaesar.oml.Reference -import io.opencaesar.oml.RelationCardinalityRestrictionAxiom -import io.opencaesar.oml.RelationEntity -import io.opencaesar.oml.RelationEntityPredicate -import io.opencaesar.oml.RelationInstance -import io.opencaesar.oml.RelationInstanceReference -import io.opencaesar.oml.RelationPredicate -import io.opencaesar.oml.RelationRangeRestrictionAxiom -import io.opencaesar.oml.RelationTargetRestrictionAxiom -import io.opencaesar.oml.RelationTypeAssertion -import io.opencaesar.oml.ReverseRelation -import io.opencaesar.oml.Rule -import io.opencaesar.oml.SameAsPredicate -import io.opencaesar.oml.ScalarProperty -import io.opencaesar.oml.ScalarPropertyCardinalityRestrictionAxiom -import io.opencaesar.oml.ScalarPropertyRangeRestrictionAxiom -import io.opencaesar.oml.ScalarPropertyValueAssertion -import io.opencaesar.oml.ScalarPropertyValueRestrictionAxiom -import io.opencaesar.oml.SpecializationAxiom -import io.opencaesar.oml.Structure -import io.opencaesar.oml.StructureInstance -import io.opencaesar.oml.StructuredProperty -import io.opencaesar.oml.StructuredPropertyCardinalityRestrictionAxiom -import io.opencaesar.oml.StructuredPropertyRangeRestrictionAxiom -import io.opencaesar.oml.StructuredPropertyValueAssertion -import io.opencaesar.oml.StructuredPropertyValueRestrictionAxiom -import io.opencaesar.oml.Term -import io.opencaesar.oml.Vocabulary -import io.opencaesar.oml.VocabularyBundle -import io.opencaesar.oml.util.OmlVisitor -import java.util.ArrayList -import org.eclipse.emf.ecore.resource.Resource -import org.eclipse.rdf4j.model.vocabulary.RDFS -import org.semanticweb.owlapi.model.OWLAnnotation -import org.semanticweb.owlapi.model.OWLIndividual -import org.semanticweb.owlapi.model.OWLNamedIndividual -import org.semanticweb.owlapi.model.OWLOntology -import org.semanticweb.owlapi.model.SWRLAtom -import org.semanticweb.owlapi.vocab.OWLFacet - -import static extension io.opencaesar.oml.util.OmlRead.* - -class Oml2Owl extends OmlVisitor { - - public static val BUILT_IN_ONTOLOGIES = #[ - 'http://www.w3.org/2001/XMLSchema', - 'http://www.w3.org/1999/02/22-rdf-syntax-ns', - 'http://www.w3.org/2000/01/rdf-schema', - 'http://www.w3.org/2002/07/owl' - ] - - val Resource inputResource - val OwlApi owl - var OWLOntology ontology - - new(Resource inputResource, OwlApi owl2) { - this.inputResource = inputResource - this.owl = owl2 - } - - def OWLOntology run() { - inputResource.allContents.forEach[doSwitch] - return ontology - } - - override caseAnnotation(Annotation annotation) { - annotation.annotatedElement.addsAnnotation(annotation) - return null - } - - override caseVocabulary(Vocabulary vocabulary) { - ontology = owl.createOntology(vocabulary.iri) - owl.addOntologyAnnotation(ontology, owl.getAnnotation(OmlConstants.ontologyType, owl.createIri(OmlConstants.Vocabulary))) - return null - } - - override caseVocabularyBundle(VocabularyBundle bundle) { - ontology = owl.createOntology(bundle.iri) - owl.addOntologyAnnotation(ontology, owl.getAnnotation(OmlConstants.ontologyType, owl.createIri(OmlConstants.VocabularyBundle))) - return null - } - - override caseDescription(Description description) { - ontology = owl.createOntology(description.iri) - owl.addOntologyAnnotation(ontology, owl.getAnnotation(OmlConstants.ontologyType, owl.createIri(OmlConstants.Description))) - return null - } - - override caseDescriptionBundle(DescriptionBundle bundle) { - ontology = owl.createOntology(bundle.iri) - owl.addOntologyAnnotation(ontology, owl.getAnnotation(OmlConstants.ontologyType, owl.createIri(OmlConstants.DescriptionBundle))) - return null - } - - override caseAspect(Aspect aspect) { - owl.addClass(ontology, aspect.iri) - owl.addSubClassOf(ontology, aspect.iri, OmlConstants.Aspect) - return null - } - - override caseConcept(Concept concept) { - owl.addClass(ontology, concept.iri) - owl.addSubClassOf(ontology, concept.iri, OmlConstants.Concept) - return null - } - - override caseRelationEntity(RelationEntity entity) { - owl.addClass(ontology, entity.iri) - owl.addSubClassOf(ontology, entity.iri, OmlConstants.RelationEntity) - - // source relation - val sourceIri = entity.sourceIri - owl.addObjectProperty(ontology, sourceIri) - owl.addSubObjectPropertyOf(ontology, sourceIri, OmlConstants.sourceRelation) - owl.addObjectPropertyDomain(ontology, sourceIri, entity.iri) - owl.addObjectPropertyRange(ontology, sourceIri, entity.source.iri) - owl.addFunctionalObjectProperty(ontology, sourceIri) - if (entity.functional) { - owl.addInverseFunctionalObjectProperty(ontology, sourceIri) - } - - // target relation - val targetIri = entity.targetIri - owl.addObjectProperty(ontology, targetIri) - owl.addSubObjectPropertyOf(ontology, targetIri, OmlConstants.targetRelation) - owl.addObjectPropertyDomain(ontology, targetIri, entity.iri) - owl.addObjectPropertyRange(ontology, targetIri, entity.target.iri) - owl.addFunctionalObjectProperty(ontology, targetIri) - if (entity.inverseFunctional) { - owl.addInverseFunctionalObjectProperty(ontology, targetIri) - } - - return null - } - - override caseStructure(Structure structure) { - owl.addClass(ontology, structure.iri) - owl.addSubClassOf(ontology, structure.iri, OmlConstants.Structure) - return null - } - - override caseFacetedScalar(FacetedScalar scalar) { - owl.addDatatype(ontology, scalar.iri) - return null - } - - override caseEnumeratedScalar(EnumeratedScalar scalar) { - owl.addDataOneOf(ontology, scalar.iri, scalar.literals.map[literal]) - return null - } - - override caseAnnotationProperty(AnnotationProperty property) { - owl.addAnnotationProperty(ontology, property.iri) - return null - } - - override caseScalarProperty(ScalarProperty property) { - val propertyIri = property.iri - owl.addDataProperty(ontology, propertyIri) - owl.addSubDataPropertyOf(ontology, propertyIri, OmlConstants.scalarProperty) - owl.addDataPropertyDomain(ontology, propertyIri, property.domain.iri) - owl.addDataPropertyRange(ontology, propertyIri, property.range.iri) - if (property.functional) { - owl.addFunctionalDataProperty(ontology, propertyIri) - } - return null - } - - override caseStructuredProperty(StructuredProperty property) { - val propertyIri = property.iri - owl.addObjectProperty(ontology, propertyIri) - owl.addSubObjectPropertyOf(ontology, propertyIri, OmlConstants.structuredProperty) - owl.addObjectPropertyDomain(ontology, propertyIri, property.domain.iri) - owl.addObjectPropertyRange(ontology, propertyIri, property.range.iri) - if (property.functional) { - owl.addFunctionalObjectProperty(ontology, propertyIri) - } - return null - } - - override caseForwardRelation(ForwardRelation forward) { - val entity = forward.entity - - // forward relation - val forwardIri = forward.iri - owl.addObjectProperty(ontology, forwardIri) - owl.addSubObjectPropertyOf(ontology, forwardIri, OmlConstants.forwardRelation) - owl.addObjectPropertyDomain(ontology, forwardIri, forward.domain.iri) - owl.addObjectPropertyRange(ontology, forwardIri, forward.range.iri) - if (entity.functional) { - owl.addFunctionalObjectProperty(ontology, forwardIri) - } - if (entity.inverseFunctional) { - owl.addInverseFunctionalObjectProperty(ontology, forwardIri) - } - if (entity.symmetric) { - owl.addSymmetricObjectProperty(ontology, forwardIri) - } - if (entity.asymmetric) { - owl.addAsymmetricObjectProperty(ontology, forwardIri) - } - if (entity.reflexive) { - owl.addReflexiveObjectProperty(ontology, forwardIri) - } - if (entity.irreflexive) { - owl.addIrreflexiveObjectProperty(ontology, forwardIri) - } - if (entity.transitive) { - owl.addTransitiveObjectProperty(ontology, forwardIri) - } - - // derivation rule for forward relation - val antedecents = new ArrayList - antedecents += owl.getObjectPropertyAtom(entity.sourceIri, 'r'.swrlIri, 's'.swrlIri) - antedecents += owl.getObjectPropertyAtom(entity.targetIri, 'r'.swrlIri, 't'.swrlIri) - val consequent = owl.getObjectPropertyAtom(forwardIri, 's'.swrlIri, 't'.swrlIri) - val annotation = owl.getAnnotation(RDFS.LABEL.toString, owl.getLiteral(forward.name+' derivation')) - owl.addNRule(ontology, #[consequent], antedecents, annotation) - return null - } - - override caseReverseRelation(ReverseRelation reverse) { - // reverse relation - val reverseIri = reverse.iri - owl.addObjectProperty(ontology, reverseIri) - owl.addSubObjectPropertyOf(ontology, reverseIri, OmlConstants.reverseRelation) - owl.addInverseProperties(ontology, reverseIri, reverse.inverse.iri) - return null - } - - override caseRule(Rule rule) { - var annotations = rule.ownedAnnotations.map[createAnnotation(it)] - if (annotations.filter[property.getIRI == RDFS.LABEL].isEmpty) { - annotations = new ArrayList(annotations) - annotations += owl.getAnnotation(RDFS.LABEL.toString, owl.getLiteral(rule.name)) - } - owl.addNRule(ontology, rule.consequent.flatMap[atom], rule.antecedent.flatMap[atom], annotations) - return null - } - - protected def createIndividual(StructureInstance instance) { - val individual = owl.getAnonymousIndividual(instance.getId) - instance.ownedPropertyValues.forEach[it.appliesTo(individual)] - individual - } - - override caseConceptInstance(ConceptInstance instance) { - val instanceIri = instance.iri - val individual = owl.addNamedIndividual(ontology, instanceIri) - instance.ownedPropertyValues.forEach[it.appliesTo(individual)] - instance.ownedLinks.forEach[it.appliesTo(individual)] - return null - } - - override caseConceptInstanceReference(ConceptInstanceReference reference) { - val instanceIri = reference.resolve.iri - val individual = owl.getNamedIndividual(instanceIri) - reference.ownedPropertyValues.forEach[it.appliesTo(individual)] - reference.ownedLinks.forEach[it.appliesTo(individual)] - return null - } - - override caseRelationInstance(RelationInstance instance) { - val instanceIri = instance.iri - val individual = owl.addNamedIndividual(ontology, instanceIri) - instance.ownedPropertyValues.forEach[it.appliesTo(individual)] - instance.ownedLinks.forEach[it.appliesTo(individual)] - return null - } - - override caseRelationInstanceReference(RelationInstanceReference reference) { - val instanceIri = reference.resolve.iri - val individual = owl.getNamedIndividual(instanceIri) - reference.ownedPropertyValues.forEach[it.appliesTo(individual)] - reference.ownedLinks.forEach[it.appliesTo(individual)] - return null - } - - override caseImport(Import ^import) { - val iri = ^import.importedOntology.iri - if (isBuiltInOntology(iri)) { - val indirectImports = ^import.closure[it.importedOntology.importsWithSource] - indirectImports.forEach[i2| - val iri2 = i2.importedOntology.iri - if (!isBuiltInOntology(iri2)) { - owl.addImportsDeclaration(ontology, iri2) - } - ] - } else { - owl.addImportsDeclaration(ontology, iri) - } - return null - } - - override caseSpecializationAxiom(SpecializationAxiom axiom) { - val annotations = axiom.ownedAnnotations.map[createAnnotation(it)] - axiom.specializingTerm.specializes(axiom.specializedTerm, axiom.owningReference, annotations) - return null - } - - override caseScalarPropertyRangeRestrictionAxiom(ScalarPropertyRangeRestrictionAxiom axiom) { - val annotations = axiom.ownedAnnotations.map[createAnnotation(it)] - if (axiom.kind == RangeRestrictionKind.ALL) { - owl.addDataAllValuesFrom(ontology, axiom.restrictingType.iri, axiom.property.iri, axiom.range.iri, annotations) - } else { - owl.addDataSomeValuesFrom(ontology, axiom.restrictingType.iri, axiom.property.iri, axiom.range.iri, annotations) - } - return null - } - - override caseScalarPropertyValueRestrictionAxiom(ScalarPropertyValueRestrictionAxiom axiom) { - val annotations = axiom.ownedAnnotations.map[createAnnotation(it)] - owl.addDataHasValue(ontology, axiom.restrictingType.iri, axiom.property.iri, axiom.value.literal, annotations) - return null - } - - override caseScalarPropertyCardinalityRestrictionAxiom(ScalarPropertyCardinalityRestrictionAxiom axiom) { - val annotations = axiom.ownedAnnotations.map[createAnnotation(it)] - if (axiom.kind == CardinalityRestrictionKind.MIN) { - owl.addDataMinCardinality(ontology, axiom.restrictingType.iri, axiom.property.iri, axiom.cardinality as int, axiom.range?.iri, annotations) - } else if (axiom.kind == CardinalityRestrictionKind.MAX) { - owl.addDataMaxCardinality(ontology, axiom.restrictingType.iri, axiom.property.iri, axiom.cardinality as int, axiom.range?.iri, annotations) - } else { - owl.addDataExactCardinality(ontology, axiom.restrictingType.iri, axiom.property.iri, axiom.cardinality as int, axiom.range?.iri, annotations) - } - return null - } - - override caseStructuredPropertyRangeRestrictionAxiom(StructuredPropertyRangeRestrictionAxiom axiom) { - val annotations = axiom.ownedAnnotations.map[createAnnotation(it)] - if (axiom.kind == RangeRestrictionKind.ALL) { - owl.addObjectAllValuesFrom(ontology, axiom.restrictingType.iri, axiom.property.iri, axiom.range.iri, annotations) - } else { - owl.addObjectSomeValuesFrom(ontology, axiom.restrictingType.iri, axiom.property.iri, axiom.range.iri, annotations) - } - return null - } - - override caseStructuredPropertyValueRestrictionAxiom(StructuredPropertyValueRestrictionAxiom axiom) { - val annotations = axiom.ownedAnnotations.map[createAnnotation(it)] - owl.addObjectHasValue(ontology, axiom.restrictingType.iri, axiom.property.iri, axiom.value.createIndividual, annotations) - return null - } - - override caseStructuredPropertyCardinalityRestrictionAxiom(StructuredPropertyCardinalityRestrictionAxiom axiom) { - val annotations = axiom.ownedAnnotations.map[createAnnotation(it)] - if (axiom.kind == CardinalityRestrictionKind.MIN) { - owl.addObjectMinCardinality(ontology, axiom.restrictingType.iri, axiom.property.iri, axiom.cardinality as int, axiom.range?.iri, annotations) - } else if (axiom.kind == CardinalityRestrictionKind.MAX) { - owl.addObjectMaxCardinality(ontology, axiom.restrictingType.iri, axiom.property.iri, axiom.cardinality as int, axiom.range?.iri, annotations) - } else { - owl.addObjectExactCardinality(ontology, axiom.restrictingType.iri, axiom.property.iri, axiom.cardinality as int, axiom.range?.iri, annotations) - } - return null - } - - override caseRelationRangeRestrictionAxiom(RelationRangeRestrictionAxiom axiom) { - val annotations = axiom.ownedAnnotations.map[createAnnotation(it)] - if (axiom.kind == RangeRestrictionKind.ALL) { - owl.addObjectAllValuesFrom(ontology, axiom.restrictingType.iri, axiom.relation.iri, axiom.range.iri, annotations) - } else { - owl.addObjectSomeValuesFrom(ontology, axiom.restrictingType.iri, axiom.relation.iri, axiom.range.iri, annotations) - } - return null - } - - override caseRelationTargetRestrictionAxiom(RelationTargetRestrictionAxiom axiom) { - val annotations = axiom.ownedAnnotations.map[createAnnotation(it)] - owl.addObjectHasValue(ontology, axiom.restrictingType.iri, axiom.relation.iri, axiom.target.iri, annotations) - return null - } - - override caseRelationCardinalityRestrictionAxiom(RelationCardinalityRestrictionAxiom axiom) { - val annotations = axiom.ownedAnnotations.map[createAnnotation(it)] - if (axiom.kind == CardinalityRestrictionKind.MIN) { - owl.addObjectMinCardinality(ontology, axiom.restrictingType.iri, axiom.relation.iri, axiom.cardinality as int, axiom.range?.iri, annotations) - } else if (axiom.kind == CardinalityRestrictionKind.MAX) { - owl.addObjectMaxCardinality(ontology, axiom.restrictingType.iri, axiom.relation.iri, axiom.cardinality as int, axiom.range?.iri, annotations) - } else { - owl.addObjectExactCardinality(ontology, axiom.restrictingType.iri, axiom.relation.iri, axiom.cardinality as int, axiom.range?.iri, annotations) - } - return null - } - - override caseKeyAxiom(KeyAxiom axiom) { - val annotations = axiom.ownedAnnotations.map[createAnnotation(it)] - owl.addHasKey(ontology, axiom.restrictingType.iri, axiom.properties.map[iri], annotations) - return null - } - - override caseConceptTypeAssertion(ConceptTypeAssertion assertion) { - val annotations = assertion.ownedAnnotations.map[createAnnotation(it)] - owl.addClassAssertion(ontology, assertion.conceptInstance.iri, assertion.type.iri, annotations) - return null - } - - override caseRelationTypeAssertion(RelationTypeAssertion assertion) { - val instance = assertion.relationInstance - val instanceIri = instance.iri - val annotations = assertion.ownedAnnotations.map[createAnnotation(it)] - owl.addClassAssertion(ontology, instanceIri, assertion.type.iri, annotations) - owl.addObjectPropertyAssertion(ontology, instanceIri, assertion.type.sourceIri, instance.source.iri) - owl.addObjectPropertyAssertion(ontology, instanceIri, assertion.type.targetIri, instance.target.iri) - return null - } - -/* ------------------------- */ - - protected def OWLAnnotation createAnnotation(Annotation annotation) { - owl.getAnnotation(annotation.property.iri, annotation.value?.literal ?: owl.getLiteral("true")) - } - - protected dispatch def void addsAnnotation(AnnotatedElement element, Annotation annotation) { - // all other cases are not mapped or mapped differently - } - - protected dispatch def void addsAnnotation(Ontology omlOntology, Annotation annotation) { - owl.addOntologyAnnotation(ontology, createAnnotation(annotation)) - } - - protected dispatch def void addsAnnotation(Member member, Annotation annotation) { - owl.addAnnotationAssertion(ontology, member.iri, createAnnotation(annotation)) - } - - protected dispatch def void addsAnnotation(Reference reference, Annotation annotation) { - reference.resolve.addsAnnotation(annotation) - } - - protected dispatch def void specializes(Term specific, Term general, Reference owningReference, OWLAnnotation...annotations) { - // all other cases are not mapped or mapped differently - } - - protected dispatch def void specializes(Concept specific, Concept general, Reference owningReference, OWLAnnotation...annotations) { - owl.addSubClassOf(ontology, specific.iri, general.iri, annotations) - } - - protected dispatch def void specializes(Concept specific, Aspect general, Reference owningReference, OWLAnnotation...annotations) { - owl.addSubClassOf(ontology, specific.iri, general.iri, annotations) - } - - protected dispatch def void specializes(Aspect specific, Aspect general, Reference owningReference, OWLAnnotation...annotations) { - owl.addSubClassOf(ontology, specific.iri, general.iri, annotations) - } - - protected dispatch def void specializes(RelationEntity specific, RelationEntity general, Reference owningReference, OWLAnnotation...annotations) { - owl.addSubClassOf(ontology, specific.iri, general.iri, annotations) - owl.addSubObjectPropertyOf(ontology, specific.sourceIri, general.sourceIri, annotations) - owl.addSubObjectPropertyOf(ontology, specific.targetIri, general.targetIri, annotations) - owl.addSubObjectPropertyOf(ontology, specific.forward.iri, general.forward.iri, annotations) - if (specific.reverse !== null && general.reverse !== null) { - owl.addSubObjectPropertyOf(ontology, specific.reverse.iri, general.reverse.iri, annotations) - } else { - // it's not obvious yet how to handle the other reverse relation cases - } - } - - protected dispatch def void specializes(RelationEntity specific, Aspect general, Reference owningReference, OWLAnnotation...annotations) { - owl.addSubClassOf(ontology, specific.iri, general.iri, annotations) - } - - protected dispatch def void specializes(Structure specific, Structure general, Reference owningReference, OWLAnnotation...annotations) { - owl.addSubClassOf(ontology, specific.iri, general.iri, annotations) - } - - protected dispatch def void specializes(EnumeratedScalar specific, EnumeratedScalar general, Reference owningReference, OWLAnnotation...annotations) { - owl.addDatatypeDefinition(ontology, specific.iri, general.iri, annotations) - } - - protected dispatch def void specializes(FacetedScalar specific, FacetedScalar general, Reference owningReference, OWLAnnotation...annotations) { - if (owningReference !== null) { - owl.addDatatypeDefinition(ontology, specific.iri, general.iri, annotations) - } else { - val restrictions = new ArrayList - if (specific.length !== null) { - restrictions += owl.getFacetRestriction(OWLFacet.LENGTH, owl.getLiteral(specific.length)) - } - if (specific.maxLength !== null) { - restrictions += owl.getFacetRestriction(OWLFacet.MAX_LENGTH, owl.getLiteral(specific.length)) - } - if (specific.minLength !== null) { - restrictions += owl.getFacetRestriction(OWLFacet.MIN_LENGTH, owl.getLiteral(specific.length)) - } - if (specific.pattern !== null) { - restrictions += owl.getFacetRestriction(OWLFacet.PATTERN, owl.getLiteral(specific.pattern)) - } - if (specific.language !== null) { - restrictions += owl.getFacetRestriction(OWLFacet.LANG_RANGE, owl.getLiteral(specific.language)) - } - if (specific.minInclusive !== null) { - restrictions += owl.getFacetRestriction(OWLFacet.MIN_INCLUSIVE, getLiteral(specific.minInclusive)) - } - if (specific.maxInclusive !== null) { - restrictions += owl.getFacetRestriction(OWLFacet.MAX_INCLUSIVE, getLiteral(specific.maxInclusive)) - } - if (specific.minExclusive !== null) { - restrictions += owl.getFacetRestriction(OWLFacet.MIN_EXCLUSIVE, getLiteral(specific.minExclusive)) - } - if (specific.maxExclusive !== null) { - restrictions += owl.getFacetRestriction(OWLFacet.MAX_EXCLUSIVE, getLiteral(specific.maxExclusive)) - } - if (!restrictions.isEmpty) { - owl.addDatatypeDefinition(ontology, specific.iri, general.iri, restrictions, annotations) - } else { - owl.addDatatypeDefinition(ontology, specific.iri, general.iri, annotations) - } - } - } - - protected dispatch def void specializes(ScalarProperty specific, ScalarProperty general, Reference owningReference, OWLAnnotation...annotations) { - owl.addSubDataPropertyOf(ontology, specific.iri, general.iri, annotations) - } - - protected dispatch def void specializes(StructuredProperty specific, StructuredProperty general, Reference owningReference, OWLAnnotation...annotations) { - owl.addSubObjectPropertyOf(ontology, specific.iri, general.iri, annotations) - } - - protected dispatch def void appliesTo(ScalarPropertyValueAssertion assertion, OWLIndividual individual) { - val annotations = assertion.ownedAnnotations.map[createAnnotation(it)] - owl.addDataPropertyAssertion(ontology, individual, assertion.property.iri, assertion.value.literal, annotations) - } - - protected dispatch def void appliesTo(StructuredPropertyValueAssertion assertion, OWLIndividual individual) { - val annotations = assertion.ownedAnnotations.map[createAnnotation(it)] - owl.addObjectPropertyAssertion(ontology, individual, assertion.property.iri, assertion.value.createIndividual, annotations) - } - - protected dispatch def void appliesTo(LinkAssertion assertion, OWLNamedIndividual individual) { - val annotations = assertion.ownedAnnotations.map[createAnnotation(it)] - owl.addObjectPropertyAssertion(ontology, individual.getIRI.IRIString, assertion.relation.iri, assertion.target.iri, annotations) - } - - protected dispatch def getAtom(EntityPredicate predicate) { - val atoms = new ArrayList - atoms += owl.getClassAtom(predicate.entity.iri, predicate.variable.swrlIri) - atoms - } - - protected dispatch def getAtom(RelationEntityPredicate predicate) { - val atoms = new ArrayList - atoms += owl.getObjectPropertyAtom(predicate.entity.sourceIri, predicate.entityVariable.swrlIri, predicate.variable1.swrlIri) - atoms += owl.getObjectPropertyAtom(predicate.entity.targetIri, predicate.entityVariable.swrlIri, predicate.variable2.swrlIri) - atoms - } - - protected dispatch def getAtom(RelationPredicate predicate) { - val atoms = new ArrayList - atoms += owl.getObjectPropertyAtom(predicate.relation.iri, predicate.variable1.swrlIri, predicate.variable2.swrlIri) - atoms - } - - protected dispatch def getAtom(SameAsPredicate predicate) { - val atoms = new ArrayList - atoms += owl.getSameIndividualAtom(predicate.variable1.swrlIri, predicate.variable2.swrlIri) - atoms - } - - protected dispatch def getAtom(DifferentFromPredicate predicate) { - val atoms = new ArrayList - atoms += owl.getDifferentIndividualsAtom(predicate.variable1.swrlIri, predicate.variable2.swrlIri) - atoms - } - - protected dispatch def getLiteral(QuotedLiteral literal) { - if (literal.type !== null) { - owl.getLiteralWithDatatype(literal.value.toString, literal.type.iri) - } else if (literal.langTag !== null) { - owl.getLiteralWithLangTag(literal.value.toString, literal.langTag) - } else { - owl.getLiteral(literal.value) - } - } - - protected dispatch def getLiteral(BooleanLiteral literal) { - if (literal.type !== null) { - owl.getLiteralWithDatatype(literal.value.toString, literal.type.iri) - } else { - owl.getLiteral(literal.value) - } - } - - protected dispatch def getLiteral(IntegerLiteral literal) { - if (literal.type !== null) { - owl.getLiteralWithDatatype(literal.value.toString, literal.type.iri) - } else { - owl.getLiteral(literal.value) - } - } - - protected dispatch def getLiteral(DecimalLiteral literal) { - if (literal.type !== null) { - owl.getLiteralWithDatatype(literal.value.toString, literal.type.iri) - } else { - owl.getLiteral(literal.value) - } - } - - protected dispatch def getLiteral(DoubleLiteral literal) { - if (literal.type !== null) { - owl.getLiteralWithDatatype(literal.value.toString, literal.type.iri) - } else { - owl.getLiteral(literal.value) - } - } - - protected def String getSourceIri(RelationEntity entity) { - entity.ontology?.namespace+'has'+entity.name.toFirstUpper+'Source' - } - - protected def String getTargetIri(RelationEntity entity) { - entity.ontology?.namespace+'has'+entity.name.toFirstUpper+'Target' - } - - protected def getSwrlIri(String variableName) { - "urn:swrl#"+variableName - } - - static def isBuiltInOntology(String iri) { - BUILT_IN_ONTOLOGIES.contains(iri) - } -} \ No newline at end of file diff --git a/owl-adapter/oml2owl/src/main/java/io/opencaesar/oml2owl/Oml2OwlApp.xtend b/owl-adapter/oml2owl/src/main/java/io/opencaesar/oml2owl/Oml2OwlApp.xtend deleted file mode 100644 index b3b0ada..0000000 --- a/owl-adapter/oml2owl/src/main/java/io/opencaesar/oml2owl/Oml2OwlApp.xtend +++ /dev/null @@ -1,277 +0,0 @@ -package io.opencaesar.oml2owl - -import com.beust.jcommander.IParameterValidator -import com.beust.jcommander.JCommander -import com.beust.jcommander.Parameter -import com.beust.jcommander.ParameterException -import com.google.common.io.CharStreams -import io.opencaesar.oml.DescriptionBundle -import io.opencaesar.oml.VocabularyBundle -import io.opencaesar.oml.dsl.OmlStandaloneSetup -import io.opencaesar.oml.util.OmlCatalog -import io.opencaesar.oml.util.OmlXMIResourceFactory -import io.opencaesar.oml2owl.CloseDescriptionBundle.CloseDescriptionBundleToOwl -import io.opencaesar.oml2owl.CloseVocabularyBundle.CloseVocabularyBundleToOwl -import java.io.File -import java.io.IOException -import java.io.InputStreamReader -import java.net.URL -import java.nio.file.Files -import java.nio.file.Paths -import java.nio.file.StandardCopyOption -import java.util.ArrayList -import java.util.Collection -import java.util.LinkedHashMap -import org.apache.log4j.AppenderSkeleton -import org.apache.log4j.Level -import org.apache.log4j.LogManager -import org.eclipse.emf.common.util.URI -import org.eclipse.emf.ecore.resource.Resource -import org.eclipse.xtext.resource.XtextResourceSet -import org.semanticweb.owlapi.apibinding.OWLManager -import org.semanticweb.owlapi.model.IRI -import org.semanticweb.owlapi.model.OWLOntology - -import static extension io.opencaesar.oml.util.OmlRead.* - -class Oml2OwlApp { - - package static val OML = 'oml' - package static val OMLXMI = "omlxmi" - - @Parameter( - names=#["--input-catalog-path","-i"], - description="Path of the input OML catalog (Required)", - validateWith=InputCatalogPath, - required=true, - order=1) - String inputCatalogPath - - @Parameter( - names=#["--output-catalog-path", "-o"], - description="Path of the output OWL catalog (Required)", - validateWith=OutputCatalogPath, - required=true, - order=2 - ) - String outputCatalogPath - - @Parameter( - names=#["--disjoint-unions", "-u"], - description="Create disjoint union axioms", - order=3 - ) - boolean disjointUnions = false - - @Parameter( - names=#["--annotations-on-axioms", "-a"], - description="Emit annotations on axioms", - order=4 - ) - boolean annotationsOnAxioms = false - - @Parameter( - names=#["--debug", "-d"], - description="Shows debug logging statements", - order=5 - ) - boolean debug - - @Parameter( - names=#["--help","-h"], - description="Displays summary of options", - help=true, - order=6) - boolean help - - val LOGGER = LogManager.getLogger(Oml2OwlApp) - - def static void main(String ... args) { - val app = new Oml2OwlApp - val builder = JCommander.newBuilder().addObject(app).build() - builder.parse(args) - if (app.help) { - builder.usage() - return - } - if (app.debug) { - val appender = LogManager.getRootLogger.getAppender("stdout") - (appender as AppenderSkeleton).setThreshold(Level.DEBUG) - } - app.run() - } - - def void run() { - LOGGER.info("=================================================================") - LOGGER.info(" S T A R T") - LOGGER.info(" OML to Owl "+getAppVersion) - LOGGER.info("=================================================================") - LOGGER.info("Input catalog path= " + inputCatalogPath) - LOGGER.info("Output catalog path= " + outputCatalogPath) - - OmlStandaloneSetup.doSetup() - OmlXMIResourceFactory.register - val inputResourceSet = new XtextResourceSet - - // collect OML files - val inputCatalogFile = new File(inputCatalogPath) - val inputFolder = inputCatalogFile.parentFile - val inputFiles = collectOMLFiles(inputFolder) - - // load the OML otologies - for (inputFile : inputFiles) { - val inputURI = URI.createFileURI(inputFile.absolutePath) - LOGGER.info("Reading: "+inputURI) - inputResourceSet.getResource(inputURI, true) - } - - // create OWL manager - val ontologyManager = OWLManager.createOWLOntologyManager() - val owl2api = new OwlApi(ontologyManager, annotationsOnAxioms) - val outputFiles = new LinkedHashMap - val oml2owl = new LinkedHashMap - - // get the output OWL folder - val outputCatalogFile = new File(outputCatalogPath); - val outputFolderPath = outputCatalogFile.parent - - // create the equivalent OWL ontologies - val throwables = new ArrayList - val threads = new ArrayList - for (inputFile : inputFiles) { - val inputURI = URI.createFileURI(inputFile.absolutePath) - val inputResource = inputResourceSet.getResource(inputURI, true) - val builtin = Oml2Owl.isBuiltInOntology(inputResource.ontology?.iri) - if (inputResource !== null && !builtin) { - var relativePath = outputFolderPath+File.separator+inputFolder.toURI().relativize(inputFile.toURI()).getPath() - val outputFile = new File(relativePath.substring(0, relativePath.lastIndexOf('.')+1)+'owl') - val thread = new Thread() { - override run() { - LOGGER.info("Creating: "+outputFile) - val owlOntology = new Oml2Owl(inputResource, owl2api).run - outputFiles.put(outputFile, owlOntology) - oml2owl.put(inputResource, owlOntology) - LOGGER.info("Created: "+outputFile) - } - } - threads.add(thread) - thread.uncaughtExceptionHandler = [th, ex | - System.out.println(ex) - throwables.add(ex) - ] - thread.start - } - } - threads.forEach[join] - if (!throwables.isEmpty) { - throw new RuntimeException("Exception(s) thrown by one or more threads") - } - - // run the vocabulary bundle closure algorithm - oml2owl.entrySet.filter[e|e.key.ontology instanceof VocabularyBundle].forEach[entry| - LOGGER.info("Closing vocabulary bundle: "+entry.key.URI) - new CloseVocabularyBundleToOwl(entry.key, entry.value, disjointUnions, owl2api).run - ] - - // run the description bundle closure algorithm - oml2owl.entrySet.filter[e|e.key.ontology instanceof DescriptionBundle].forEach[entry| - LOGGER.info("Closing description bundle: "+entry.key.URI) - new CloseDescriptionBundleToOwl(entry.key, entry.value, owl2api).run - ] - - // save the output resources - val threads2 = new ArrayList - outputFiles.forEach[file, owlOntology | - val thread = new Thread() { - override run() { - LOGGER.info("Saving: "+file) - ontologyManager.saveOntology(owlOntology, /*new TurtleDocumentFormat,*/ IRI.create(file)) - } - } - threads2.add(thread) - thread.start - ] - threads2.forEach[join] - - // create the equivalent OWL catalog - copyCatalog(inputCatalogFile, outputCatalogFile) - - LOGGER.info("=================================================================") - LOGGER.info(" E N D") - LOGGER.info("=================================================================") - } - - private def Collection collectOMLFiles(File directory) { - val omlFiles = new ArrayList - for (file : directory.listFiles()) { - if (file.isFile) { - if ((getFileExtension(file) == OML || - getFileExtension(file) == OMLXMI)) { - omlFiles.add(file) - } - } else if (file.isDirectory) { - omlFiles.addAll(collectOMLFiles(file)) - } - } - return omlFiles - } - - private def void copyCatalog(File inputCatalogFile, File outputCatalogFile) { - LOGGER.info("Saving: "+inputCatalogFile) - Files.copy(Paths.get(inputCatalogFile.path), Paths.get(outputCatalogFile.path), StandardCopyOption.REPLACE_EXISTING) - val inputCatalog = OmlCatalog.create(inputCatalogFile.toURI.toURL) - for (c : inputCatalog.nestedCatalogs) { - val uri = new URL(c).toURI - val nestedInputCatalogFile = new File(uri); - var relativePath = inputCatalogFile.parentFile.toURI().relativize(uri).getPath() - val nestedOutputCatalogFile = new File(outputCatalogFile.parent+File.separator+relativePath) - copyCatalog(nestedInputCatalogFile, nestedOutputCatalogFile) - } - } - - private def String getFileExtension(File file) { - val fileName = file.getName() - if(fileName.lastIndexOf(".") != -1) - return fileName.substring(fileName.lastIndexOf(".")+1) - else - return "" - } - - /** - * Get application version id from properties file. - * @return version string from build.properties or UNKNOWN - */ - private def String getAppVersion() { - var version = "UNKNOWN" - try { - val input = Thread.currentThread().getContextClassLoader().getResourceAsStream("version.txt") - val reader = new InputStreamReader(input) - version = CharStreams.toString(reader); - } catch (IOException e) { - val errorMsg = "Could not read version.txt file." + e - LOGGER.error(errorMsg, e) - } - version - } - - static class InputCatalogPath implements IParameterValidator { - override validate(String name, String value) throws ParameterException { - val file = new File(value) - if (!file.getName().endsWith("catalog.xml")) { - throw new ParameterException("Parameter " + name + " should be a valid OWL catalog path") - } - } - } - - static class OutputCatalogPath implements IParameterValidator { - override validate(String name, String value) throws ParameterException { - val file = new File(value) - if (!file.getName().endsWith("catalog.xml")) { - throw new ParameterException("Parameter " + name + " should be a valid OWL catalog path") - } - val folder = file.parentFile - folder.mkdirs - } - } - -} diff --git a/owl-adapter/oml2owl/src/main/java/io/opencaesar/oml2owl/OmlConstants.xtend b/owl-adapter/oml2owl/src/main/java/io/opencaesar/oml2owl/OmlConstants.xtend deleted file mode 100644 index c51e762..0000000 --- a/owl-adapter/oml2owl/src/main/java/io/opencaesar/oml2owl/OmlConstants.xtend +++ /dev/null @@ -1,48 +0,0 @@ -package io.opencaesar.oml2owl - -interface OmlConstants { - - static val omlPath = "opencaesar.io/oml" - - static val omlIRI = "http://"+omlPath - - static val omlNS = omlIRI+ '#' - - // oml:ontologyType annotation - - static val ontologyType = omlNS+'ontologyType' - - // owl:Ontology oml:ontologyType ?x - - static val Vocabulary = omlNS+'Vocabulary' - - static val VocabularyBundle = omlNS+'VocabularyBundle' - - static val Description = omlNS+'Description' - - static val DescriptionBundle = omlNS+'DescriptionBundle' - - // owl:Class rdfs:subClassOf x? - - static val Aspect = omlNS+'Aspect' - - static val Concept = omlNS+'Concept' - - static val RelationEntity = omlNS+'RelationEntity' - - static val Structure = omlNS+'Structure' - - // owl:ObjectProperty rdfs:subPropertyOf x? - - static val forwardRelation = omlNS+'forwardRelation' - - static val reverseRelation = omlNS+'reverseRelation' - - static val sourceRelation = omlNS+'sourceRelation' - - static val targetRelation = omlNS+'targetRelation' - - static val structuredProperty = omlNS+'structuredProperty' - - static val scalarProperty = omlNS+'scalarProperty' -} \ No newline at end of file diff --git a/owl-adapter/oml2owl/src/main/java/io/opencaesar/oml2owl/OwlApi.xtend b/owl-adapter/oml2owl/src/main/java/io/opencaesar/oml2owl/OwlApi.xtend deleted file mode 100644 index 023eb08..0000000 --- a/owl-adapter/oml2owl/src/main/java/io/opencaesar/oml2owl/OwlApi.xtend +++ /dev/null @@ -1,507 +0,0 @@ -package io.opencaesar.oml2owl - -import java.math.BigDecimal -import java.util.Arrays -import java.util.Collection -import java.util.Collections -import org.semanticweb.owlapi.model.AddImport -import org.semanticweb.owlapi.model.AddOntologyAnnotation -import org.semanticweb.owlapi.model.IRI -import org.semanticweb.owlapi.model.OWLAnnotation -import org.semanticweb.owlapi.model.OWLAnnotationValue -import org.semanticweb.owlapi.model.OWLFacetRestriction -import org.semanticweb.owlapi.model.OWLIndividual -import org.semanticweb.owlapi.model.OWLLiteral -import org.semanticweb.owlapi.model.OWLOntology -import org.semanticweb.owlapi.model.OWLOntologyManager -import org.semanticweb.owlapi.model.SWRLAtom -import org.semanticweb.owlapi.vocab.OWLFacet - -class OwlApi extends io.opencaesar.closeworld.OwlApi { - - val XSD = "http://www.w3.org/2001/XMLSchema#" - protected final boolean annotationsOnAxioms; - - new(OWLOntologyManager manager, boolean annotationsOnAxioms) { - super(manager) - this.annotationsOnAxioms = annotationsOnAxioms; - } - - def createIri(String iri) { - IRI.create(iri) - } - - def createOntology(String iri) { - return manager.createOntology(IRI.create(iri)) - } - - def addImportsDeclaration(OWLOntology ontology, String iri) { - val import = factory.getOWLImportsDeclaration(IRI.create(iri)) - manager.applyChanges(new AddImport(ontology, import)) - return import - } - - def addClass(OWLOntology ontology, String iri) { - val class = factory.getOWLClass(iri) - val axiom = factory.getOWLDeclarationAxiom(class) - manager.addAxiom(ontology, axiom) - return class - } - - def addDatatype(OWLOntology ontology, String iri) { - val datatype = factory.getOWLDatatype(iri) - val axiom = factory.getOWLDeclarationAxiom(datatype) - manager.addAxiom(ontology, axiom) - return datatype - } - - def addDatatypeDefinition(OWLOntology ontology, String datatypeIri, String restrictedIri, OWLFacetRestriction[] restrictions, OWLAnnotation...annotations) { - val datatype = factory.getOWLDatatype(datatypeIri) - val restrictedDatatype = factory.getOWLDatatype(restrictedIri) - val restriction = factory.getOWLDatatypeRestriction(restrictedDatatype, restrictions) - val axiom = factory.getOWLDatatypeDefinitionAxiom(datatype, restriction, annotations.checkIfNeeded) - manager.addAxiom(ontology, axiom) - return axiom - } - - def addDatatypeDefinition(OWLOntology ontology, String datatypeIri, String synonymIri, OWLAnnotation...annotations) { - val datatype = factory.getOWLDatatype(datatypeIri) - val synonymDatatype = factory.getOWLDatatype(synonymIri) - val axiom = factory.getOWLDatatypeDefinitionAxiom(datatype, synonymDatatype, annotations.checkIfNeeded) - manager.addAxiom(ontology, axiom) - return axiom - } - - def addDataOneOf(OWLOntology ontology, String subIri, OWLLiteral...literals) { - val datatype = factory.getOWLDatatype(subIri) - val dataOneOf = factory.getOWLDataOneOf(literals) - val axiom = factory.getOWLDatatypeDefinitionAxiom(datatype, dataOneOf) - manager.addAxiom(ontology, axiom) - return dataOneOf - } - - def addObjectProperty(OWLOntology ontology, String iri) { - val property = factory.getOWLObjectProperty(iri) - val axiom = factory.getOWLDeclarationAxiom(property) - manager.addAxiom(ontology, axiom) - return property - } - - def addFunctionalObjectProperty(OWLOntology ontology, String iri) { - val property = factory.getOWLObjectProperty(iri) - val axiom = factory.getOWLFunctionalObjectPropertyAxiom(property) - manager.addAxiom(ontology, axiom) - return property - } - - def addInverseFunctionalObjectProperty(OWLOntology ontology, String iri) { - val property = factory.getOWLObjectProperty(iri) - val axiom = factory.getOWLInverseFunctionalObjectPropertyAxiom(property) - manager.addAxiom(ontology, axiom) - return property - } - - def addSymmetricObjectProperty(OWLOntology ontology, String iri) { - val property = factory.getOWLObjectProperty(iri) - val axiom = factory.getOWLSymmetricObjectPropertyAxiom(property) - manager.addAxiom(ontology, axiom) - return property - } - - def addAsymmetricObjectProperty(OWLOntology ontology, String iri) { - val property = factory.getOWLObjectProperty(iri) - val axiom = factory.getOWLAsymmetricObjectPropertyAxiom(property) - manager.addAxiom(ontology, axiom) - return property - } - - def addReflexiveObjectProperty(OWLOntology ontology, String iri) { - val property = factory.getOWLObjectProperty(iri) - val axiom = factory.getOWLReflexiveObjectPropertyAxiom(property) - manager.addAxiom(ontology, axiom) - return property - } - - def addIrreflexiveObjectProperty(OWLOntology ontology, String iri) { - val property = factory.getOWLObjectProperty(iri) - val axiom = factory.getOWLIrreflexiveObjectPropertyAxiom(property) - manager.addAxiom(ontology, axiom) - return property - } - - def addTransitiveObjectProperty(OWLOntology ontology, String iri) { - val property = factory.getOWLObjectProperty(iri) - val axiom = factory.getOWLTransitiveObjectPropertyAxiom(property) - manager.addAxiom(ontology, axiom) - return property - } - - def addDataProperty(OWLOntology ontology, String iri) { - val property = factory.getOWLDataProperty(iri) - val axiom = factory.getOWLDeclarationAxiom(property) - manager.addAxiom(ontology, axiom) - return property - } - - def addFunctionalDataProperty(OWLOntology ontology, String iri) { - val property = factory.getOWLDataProperty(iri) - val axiom = factory.getOWLFunctionalDataPropertyAxiom(property) - manager.addAxiom(ontology, axiom) - return property - } - - def addAnnotationProperty(OWLOntology ontology, String iri) { - val property = factory.getOWLAnnotationProperty(iri) - val axiom = factory.getOWLDeclarationAxiom(property) - manager.addAxiom(ontology, axiom) - return property - } - - def addNamedIndividual(OWLOntology ontology, String iri) { - val individual = factory.getOWLNamedIndividual(iri) - val axiom = factory.getOWLDeclarationAxiom(individual) - manager.addAxiom(ontology, axiom) - return individual - } - - def getNamedIndividual(String nodeId) { - return factory.getOWLNamedIndividual(nodeId) - } - - def getAnonymousIndividual(String nodeId) { - return factory.getOWLAnonymousIndividual(nodeId) - } - - def addNRule(OWLOntology ontology, SWRLAtom[] head, SWRLAtom[] body, OWLAnnotation...annotations) { - val axiom = factory.getSWRLRule(body, head, annotations) - manager.addAxiom(ontology, axiom) - return axiom - } - - def getClassAtom(String classIri, String variableIri) { - val class = factory.getOWLClass(classIri) - val variable = factory.getSWRLVariable(variableIri) - return factory.getSWRLClassAtom(class, variable) - } - - def getObjectPropertyAtom(String propertyIri, String variable1Iri, String variable2Iri) { - val property = factory.getOWLObjectProperty(propertyIri) - val variable1 = factory.getSWRLVariable(variable1Iri) - val variable2 = factory.getSWRLVariable(variable2Iri) - return factory.getSWRLObjectPropertyAtom(property, variable1, variable2) - } - - def getSameIndividualAtom(String variable1Iri, String variable2Iri) { - val variable1 = factory.getSWRLVariable(variable1Iri) - val variable2 = factory.getSWRLVariable(variable2Iri) - return factory.getSWRLSameIndividualAtom(variable1, variable2) - } - - def getDifferentIndividualsAtom(String variable1Iri, String variable2Iri) { - val variable1 = factory.getSWRLVariable(variable1Iri) - val variable2 = factory.getSWRLVariable(variable2Iri) - return factory.getSWRLDifferentIndividualsAtom(variable1, variable2) - } - - def addSubClassOf(OWLOntology ontology, String subIri, String superIri, OWLAnnotation...annotations) { - val subClass = factory.getOWLClass(subIri) - val supClass = factory.getOWLClass(superIri) - val axiom = factory.getOWLSubClassOfAxiom(subClass, supClass, annotations.checkIfNeeded) - manager.addAxiom(ontology, axiom) - return axiom - } - - def addHasKey(OWLOntology ontology, String classIri, Collection keyPropertyIris, OWLAnnotation...annotations) { - val aClass = factory.getOWLClass(classIri) - val keyProperties = keyPropertyIris.map[iri|factory.getOWLDataProperty(iri)].toList - val axiom = factory.getOWLHasKeyAxiom(aClass, keyProperties, annotations.checkIfNeeded) - manager.addAxiom(ontology, axiom) - return axiom - } - - def addObjectSomeValuesFrom(OWLOntology ontology, String classIri, String propertyIri, String typeIri, OWLAnnotation...annotations) { - val class = factory.getOWLClass(classIri) - val property = factory.getOWLObjectProperty(propertyIri) - val type = factory.getOWLClass(typeIri) - val restriction = factory.getOWLObjectSomeValuesFrom(property, type) - val axiom = factory.getOWLSubClassOfAxiom(class, restriction, annotations.checkIfNeeded) - manager.addAxiom(ontology, axiom) - return axiom - } - - def addObjectAllValuesFrom(OWLOntology ontology, String classIri, String propertyIri, String typeIri, OWLAnnotation...annotations) { - val class = factory.getOWLClass(classIri) - val property = factory.getOWLObjectProperty(propertyIri) - val type = factory.getOWLClass(typeIri) - val restriction = factory.getOWLObjectAllValuesFrom(property, type) - val axiom = factory.getOWLSubClassOfAxiom(class, restriction, annotations.checkIfNeeded) - manager.addAxiom(ontology, axiom) - return axiom - } - - def addObjectHasValue(OWLOntology ontology, String classIri, String propertyIri, OWLIndividual individual, OWLAnnotation...annotations) { - val class = factory.getOWLClass(classIri) - val property = factory.getOWLObjectProperty(propertyIri) - val restriction = factory.getOWLObjectHasValue(property, individual) - val axiom = factory.getOWLSubClassOfAxiom(class, restriction, annotations.checkIfNeeded) - manager.addAxiom(ontology, axiom) - return axiom - } - - def addObjectHasValue(OWLOntology ontology, String classIri, String propertyIri, String individualIri, OWLAnnotation...annotations) { - val class = factory.getOWLClass(classIri) - val property = factory.getOWLObjectProperty(propertyIri) - val individual = factory.getOWLNamedIndividual(individualIri) - val restriction = factory.getOWLObjectHasValue(property, individual) - val axiom = factory.getOWLSubClassOfAxiom(class, restriction, annotations.checkIfNeeded) - manager.addAxiom(ontology, axiom) - return axiom - } - - def addObjectExactCardinality(OWLOntology ontology, String classIri, String propertyIri, int cardinality, String rangeIri, OWLAnnotation...annotations) { - val class = factory.getOWLClass(classIri) - val property = factory.getOWLObjectProperty(propertyIri) - val restriction = if (rangeIri !== null) - factory.getOWLObjectExactCardinality(cardinality, property, factory.getOWLClass(rangeIri)) - else - factory.getOWLObjectExactCardinality(cardinality, property) - val axiom = factory.getOWLSubClassOfAxiom(class, restriction, annotations.checkIfNeeded) - manager.addAxiom(ontology, axiom) - return axiom - } - - def addObjectMinCardinality(OWLOntology ontology, String classIri, String propertyIri, int cardinality, String rangeIri, OWLAnnotation...annotations) { - val class = factory.getOWLClass(classIri) - val property = factory.getOWLObjectProperty(propertyIri) - val restriction = if (rangeIri !== null) - factory.getOWLObjectMinCardinality(cardinality, property, factory.getOWLClass(rangeIri)) - else - factory.getOWLObjectMinCardinality(cardinality, property) - val axiom = factory.getOWLSubClassOfAxiom(class, restriction, annotations.checkIfNeeded) - manager.addAxiom(ontology, axiom) - return axiom - } - - def addObjectMaxCardinality(OWLOntology ontology, String classIri, String propertyIri, int cardinality, String rangeIri, OWLAnnotation...annotations) { - val class = factory.getOWLClass(classIri) - val property = factory.getOWLObjectProperty(propertyIri) - val restriction = if (rangeIri !== null) - factory.getOWLObjectMaxCardinality(cardinality, property, factory.getOWLClass(rangeIri)) - else - factory.getOWLObjectMaxCardinality(cardinality, property) - val axiom = factory.getOWLSubClassOfAxiom(class, restriction, annotations.checkIfNeeded) - manager.addAxiom(ontology, axiom) - return axiom - } - - def addDataExactCardinality(OWLOntology ontology, String classIri, String propertyIri, int cardinality, String rangeIri, OWLAnnotation...annotations) { - val class = factory.getOWLClass(classIri) - val property = factory.getOWLDataProperty(propertyIri) - val restriction = if (rangeIri !== null) - factory.getOWLDataExactCardinality(cardinality, property, factory.getOWLDatatype(rangeIri)) - else - factory.getOWLDataExactCardinality(cardinality, property) - val axiom = factory.getOWLSubClassOfAxiom(class, restriction, annotations.checkIfNeeded) - manager.addAxiom(ontology, axiom) - return axiom - } - - def addDataMinCardinality(OWLOntology ontology, String classIri, String propertyIri, int cardinality, String rangeIri, OWLAnnotation...annotations) { - val class = factory.getOWLClass(classIri) - val property = factory.getOWLDataProperty(propertyIri) - val restriction = if (rangeIri !== null) - factory.getOWLDataMinCardinality(cardinality, property, factory.getOWLDatatype(rangeIri)) - else - factory.getOWLDataMinCardinality(cardinality, property) - val axiom = factory.getOWLSubClassOfAxiom(class, restriction, annotations.checkIfNeeded) - manager.addAxiom(ontology, axiom) - return axiom - } - - def addDataMaxCardinality(OWLOntology ontology, String classIri, String propertyIri, int cardinality, String rangeIri, OWLAnnotation...annotations) { - val class = factory.getOWLClass(classIri) - val property = factory.getOWLDataProperty(propertyIri) - val restriction = if (rangeIri !== null) - factory.getOWLDataMaxCardinality(cardinality, property, factory.getOWLDatatype(rangeIri)) - else - factory.getOWLDataMaxCardinality(cardinality, property) - val axiom = factory.getOWLSubClassOfAxiom(class, restriction, annotations.checkIfNeeded) - manager.addAxiom(ontology, axiom) - return axiom - } - - def addDataSomeValuesFrom(OWLOntology ontology, String classIri, String propertyIri, String typeIri, OWLAnnotation...annotations) { - val class = factory.getOWLClass(classIri) - val property = factory.getOWLDataProperty(propertyIri) - val type = factory.getOWLDatatype(typeIri) - val restriction = factory.getOWLDataSomeValuesFrom(property, type) - val axiom = factory.getOWLSubClassOfAxiom(class, restriction, annotations.checkIfNeeded) - manager.addAxiom(ontology, axiom) - return axiom - } - - def addDataAllValuesFrom(OWLOntology ontology, String classIri, String propertyIri, String typeIri, OWLAnnotation...annotations) { - val class = factory.getOWLClass(classIri) - val property = factory.getOWLDataProperty(propertyIri) - val type = factory.getOWLDatatype(typeIri) - val restriction = factory.getOWLDataAllValuesFrom(property, type) - val axiom = factory.getOWLSubClassOfAxiom(class, restriction, annotations.checkIfNeeded) - manager.addAxiom(ontology, axiom) - return axiom - } - - def addDataHasValue(OWLOntology ontology, String classIri, String propertyIri, OWLLiteral literal, OWLAnnotation...annotations) { - val class = factory.getOWLClass(classIri) - val property = factory.getOWLDataProperty(propertyIri) - val restriction = factory.getOWLDataHasValue(property, literal) - val axiom = factory.getOWLSubClassOfAxiom(class, restriction, annotations.checkIfNeeded) - manager.addAxiom(ontology, axiom) - return axiom - } - - def addSubObjectPropertyOf(OWLOntology ontology, String subPropertyIri, String superPropertyIri, OWLAnnotation...annotations) { - val subProperty = factory.getOWLObjectProperty(subPropertyIri) - val supProperty = factory.getOWLObjectProperty(superPropertyIri) - val axiom = factory.getOWLSubObjectPropertyOfAxiom(subProperty, supProperty, annotations.checkIfNeeded) - manager.addAxiom(ontology, axiom) - return axiom - } - - def addObjectPropertyDomain(OWLOntology ontology, String propertyIri, String domainIri) { - val property = factory.getOWLObjectProperty(propertyIri) - val domain = factory.getOWLClass(domainIri) - val axiom = factory.getOWLObjectPropertyDomainAxiom(property, domain) - manager.addAxiom(ontology, axiom) - return axiom - } - - def addObjectPropertyRange(OWLOntology ontology, String propertyIri, String rangeIri) { - val property = factory.getOWLObjectProperty(propertyIri) - val range = factory.getOWLClass(rangeIri) - val axiom = factory.getOWLObjectPropertyRangeAxiom(property, range) - manager.addAxiom(ontology, axiom) - return axiom - } - - def addSubDataPropertyOf(OWLOntology ontology, String subPropertyIri, String superPropertyIri, OWLAnnotation...annotations) { - val subProperty = factory.getOWLDataProperty(subPropertyIri) - val supProperty = factory.getOWLDataProperty(superPropertyIri) - val axiom = factory.getOWLSubDataPropertyOfAxiom(subProperty, supProperty, annotations.checkIfNeeded) - manager.addAxiom(ontology, axiom) - return axiom - } - - def addDataPropertyDomain(OWLOntology ontology, String propertyIri, String domainIri) { - val property = factory.getOWLDataProperty(propertyIri) - val domain = factory.getOWLClass(domainIri) - val axiom = factory.getOWLDataPropertyDomainAxiom(property, domain) - manager.addAxiom(ontology, axiom) - return axiom - } - - def addDataPropertyRange(OWLOntology ontology, String propertyIri, String rangeIri) { - val property = factory.getOWLDataProperty(propertyIri) - val range = factory.getOWLDatatype(rangeIri) - val axiom = factory.getOWLDataPropertyRangeAxiom(property, range) - manager.addAxiom(ontology, axiom) - return axiom - } - - def addInverseProperties(OWLOntology ontology, String forwardPropertyIri, String reversePropertyIri) { - val forwardproperty = factory.getOWLObjectProperty(forwardPropertyIri) - val reverseProperty = factory.getOWLObjectProperty(reversePropertyIri) - val axiom = factory.getOWLInverseObjectPropertiesAxiom(forwardproperty, reverseProperty) - manager.addAxiom(ontology, axiom) - return axiom - } - - def addClassAssertion(OWLOntology ontology, String individualIri, String classIri, OWLAnnotation...annotations) { - val individual = factory.getOWLNamedIndividual(individualIri) - val class = factory.getOWLClass(classIri) - val axiom = factory.getOWLClassAssertionAxiom(class, individual, annotations.checkIfNeeded) - manager.addAxiom(ontology, axiom) - return axiom - } - - def addObjectPropertyAssertion(OWLOntology ontology, String individualIri, String propertyIri, String objectIri, OWLAnnotation...annotations) { - val object = factory.getOWLNamedIndividual(objectIri) - val individual = factory.getOWLNamedIndividual(individualIri) - return addObjectPropertyAssertion(ontology, individual, propertyIri, object, annotations.checkIfNeeded) - } - - def addObjectPropertyAssertion(OWLOntology ontology, OWLIndividual individual, String propertyIri, OWLIndividual object, OWLAnnotation...annotations) { - val property = factory.getOWLObjectProperty(propertyIri) - val axiom = factory.getOWLObjectPropertyAssertionAxiom(property, individual, object, annotations.checkIfNeeded) - manager.addAxiom(ontology, axiom) - return axiom - } - - def addDataPropertyAssertion(OWLOntology ontology, String individualIri, String propertyIri, OWLLiteral literal, OWLAnnotation...annotations) { - val individual = factory.getOWLNamedIndividual(individualIri) - return addDataPropertyAssertion(ontology, individual, propertyIri, literal, annotations.checkIfNeeded) - } - - def addDataPropertyAssertion(OWLOntology ontology, OWLIndividual individual, String propertyIri, OWLLiteral literal, OWLAnnotation...annotations) { - val property = factory.getOWLDataProperty(propertyIri) - val axiom = factory.getOWLDataPropertyAssertionAxiom(property, individual, literal, annotations.checkIfNeeded) - manager.addAxiom(ontology, axiom) - return axiom - } - - def getAnnotation(String propertyIri, OWLAnnotationValue value) { - val property = factory.getOWLAnnotationProperty(propertyIri) - return factory.getOWLAnnotation(property, value) - } - - def addOntologyAnnotation(OWLOntology ontology, OWLAnnotation annotation) { - manager.applyChange(new AddOntologyAnnotation(ontology, annotation)) - return annotation - } - - def addAnnotationAssertion(OWLOntology ontology, String subjectIri, OWLAnnotation annotation) { - val axiom = factory.getOWLAnnotationAssertionAxiom(IRI.create(subjectIri), annotation) - manager.addAxiom(ontology, axiom) - return axiom - } - - def getFacetRestriction(OWLFacet facet, OWLLiteral value) { - return factory.getOWLFacetRestriction(facet, value) - } - - def getLiteral(boolean value) { - return factory.getOWLLiteral(value) - } - - def getLiteral(int value) { - return factory.getOWLLiteral(value) - } - - def getLiteral(double value) { - return factory.getOWLLiteral(value) - } - - def getLiteral(String value) { - return factory.getOWLLiteral(value) - } - - def getLiteral(BigDecimal value) { - return getLiteralWithDatatype(value.toString, XSD+"decimal") - } - - def getLiteralWithDatatype(String value, String datatypeIri) { - val datatype = factory.getOWLDatatype(datatypeIri) - return factory.getOWLLiteral(value, datatype) - } - - def getLiteralWithLangTag(String value, String langTag) { - return factory.getOWLLiteral(value, langTag) - } - - def checkIfNeeded(OWLAnnotation...annotations) { - if (annotationsOnAxioms) { - return Arrays.asList(annotations); - } else { - return Collections.emptyList(); - } - } -} \ No newline at end of file diff --git a/owl-adapter/oml2owl/src/main/resources/version.txt b/owl-adapter/oml2owl/src/main/resources/version.txt deleted file mode 100644 index 8fd9b8c..0000000 --- a/owl-adapter/oml2owl/src/main/resources/version.txt +++ /dev/null @@ -1 +0,0 @@ -0.7.11 \ No newline at end of file diff --git a/owl-adapter/settings.gradle b/settings.gradle similarity index 100% rename from owl-adapter/settings.gradle rename to settings.gradle