public void mergeOntologies() { List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>(); for (OWLOntology ont : ontologies) { if (!ont.equals(targetOntology)) { // move the axioms for (OWLAxiom ax : ont.getAxioms()) { changes.add(new AddAxiom(targetOntology, ax)); } // move ontology annotations for (OWLAnnotation annot : ont.getAnnotations()) { changes.add(new AddOntologyAnnotation(targetOntology, annot)); } if (!targetOntology.getOntologyID().isAnonymous()) { // move ontology imports for (OWLImportsDeclaration decl : ont.getImportsDeclarations()) { if (ontologies.contains(ont.getOWLOntologyManager().getImportedOntology(decl))) { continue; } Optional<IRI> defaultDocumentIRI = targetOntology.getOntologyID().getDefaultDocumentIRI(); if (defaultDocumentIRI.isPresent() && !decl.getIRI().equals(defaultDocumentIRI.get())) { changes.add(new AddImport(targetOntology, decl)); } else { logger.warn( "Merge: ignoring import declaration for ontology " + targetOntology.getOntologyID() + " (would result in target ontology importing itself)."); } } } } } try { owlOntologyManager.applyChanges(changes); } catch (OWLOntologyChangeException e) { ErrorLogPanel.showErrorDialog(e); } }