From 168cb9b5391f226d88e3f12b016b2b808315e8bf Mon Sep 17 00:00:00 2001 From: Syphax Bouazzouni Date: Wed, 21 Dec 2022 09:31:10 +0100 Subject: [PATCH] remove sourceOwlManager.getOntologies() loop for addOntologyAnnotations --- .../ncbo/owlapi/wrapper/OntologyParser.java | 81 +++++++++---------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/src/main/java/org/stanford/ncbo/owlapi/wrapper/OntologyParser.java b/src/main/java/org/stanford/ncbo/owlapi/wrapper/OntologyParser.java index 1212416c..7074ade6 100644 --- a/src/main/java/org/stanford/ncbo/owlapi/wrapper/OntologyParser.java +++ b/src/main/java/org/stanford/ncbo/owlapi/wrapper/OntologyParser.java @@ -206,65 +206,64 @@ private boolean buildOWLOntology(OWLOntology masterOntology, boolean isOBO) { return false; } + for (OWLOntology sourceOnt : sourceOwlManager.getOntologies()) { IRI documentIRI = sourceOwlManager.getOntologyDocumentIRI(sourceOnt); addGroundMetadata(documentIRI, fact, sourceOnt); generateGroundTriplesForAxioms(allAxioms, fact, sourceOnt); - if (isOBO) { - if (!documentIRI.toString().startsWith("owlapi:ontology")) { - generateSKOSInObo(allAxioms, fact, sourceOnt); - } + if (isOBO && !documentIRI.toString().startsWith("owlapi:ontology")) { + generateSKOSInObo(allAxioms, fact, sourceOnt); } boolean isPrefixedOWL = sourceOwlManager.getOntologyFormat(sourceOnt).isPrefixOWLOntologyFormat(); log.info("isPrefixOWLOntologyFormat: {}", isPrefixedOWL); - if (isPrefixedOWL == true && !isOBO) { + if (isPrefixedOWL && !isOBO) { generateSKOSInOwl(allAxioms, fact, sourceOnt); } } - targetOwlManager.addAxioms(targetOwlOntology, allAxioms); - for (OWLAnnotation ann : targetOwlOntology.getAnnotations()) { + targetOwlManager.addAxioms(targetOwlOntology, allAxioms); + for (OWLAnnotation ann : targetOwlOntology.getAnnotations()) { + AddOntologyAnnotation addAnn = new AddOntologyAnnotation(targetOwlOntology, ann); + targetOwlManager.applyChange(addAnn); + } + + if (isOBO) { + String oboVersion = parserInvocation.getOBOVersion(); + if (oboVersion != null) { + log.info("Adding version: {}", oboVersion); + OWLAnnotationProperty prop = fact.getOWLAnnotationProperty(IRI.create(OWLRDFVocabulary.OWL_VERSION_INFO.toString())); + IRI versionSubjectIRI = IRI.create(VERSION_SUBJECT); + OWLAnnotationAssertionAxiom annVersion = fact.getOWLAnnotationAssertionAxiom(prop, versionSubjectIRI, fact.getOWLLiteral(oboVersion)); + targetOwlManager.addAxiom(targetOwlOntology, annVersion); + } + } + + addOntologyAnnotations(masterOntology); + escapeXMLLiterals(targetOwlOntology); + + OWLReasonerFactory reasonerFactory = new StructuralReasonerFactory(); + OWLReasoner reasoner = reasonerFactory.createReasoner(targetOwlOntology); + InferredSubClassAxiomGenerator isc = new InferredSubClassAxiomGenerator(); + Set subAxs = isc.createAxioms(targetOwlOntology.getOWLOntologyManager().getOWLDataFactory(), reasoner); + targetOwlManager.addAxioms(targetOwlOntology, subAxs); + deprecateBranch(); + + log.info("isOBO: {}", isOBO); + if (isOBO) { + replicateHierarchyAsTreeview(fact); + } + return true; + } + + private void addOntologyAnnotations(OWLOntology masterOntology){ + for (OWLAnnotation ann : masterOntology.getAnnotations()) { AddOntologyAnnotation addAnn = new AddOntologyAnnotation(targetOwlOntology, ann); targetOwlManager.applyChange(addAnn); } - - if (isOBO) { - String oboVersion = parserInvocation.getOBOVersion(); - if (oboVersion != null) { - log.info("Adding version: {}", oboVersion); - OWLAnnotationProperty prop = fact.getOWLAnnotationProperty(IRI.create(OWLRDFVocabulary.OWL_VERSION_INFO.toString())); - IRI versionSubjectIRI = IRI.create(VERSION_SUBJECT); - OWLAnnotationAssertionAxiom annVersion = fact.getOWLAnnotationAssertionAxiom(prop, versionSubjectIRI, fact.getOWLLiteral(oboVersion)); - targetOwlManager.addAxiom(targetOwlOntology, annVersion); - } - } - - for (OWLOntology sourceOnt : sourceOwlManager.getOntologies()) { - for (OWLAnnotation ann : sourceOnt.getAnnotations()) { - AddOntologyAnnotation addAnn = new AddOntologyAnnotation(targetOwlOntology, ann); - targetOwlManager.applyChange(addAnn); - } - } - - escapeXMLLiterals(targetOwlOntology); - - OWLReasonerFactory reasonerFactory = new StructuralReasonerFactory(); - OWLReasoner reasoner = reasonerFactory.createReasoner(targetOwlOntology); - InferredSubClassAxiomGenerator isc = new InferredSubClassAxiomGenerator(); - Set subAxs = isc.createAxioms(targetOwlOntology.getOWLOntologyManager().getOWLDataFactory(), reasoner); - targetOwlManager.addAxioms(targetOwlOntology, subAxs); - deprecateBranch(); - - log.info("isOBO: {}", isOBO); - if (isOBO) { - replicateHierarchyAsTreeview(fact); - } - return true; } - private void replicateHierarchyAsTreeview(OWLDataFactory fact) { Set treeViewAxs = new HashSet(); for (OWLAxiom axiom : targetOwlOntology.getAxioms()) {