public int getParentCount(Object obj) { return ((OWLOntology) obj).getImportsDeclarations().size(); }
public Iterator getParents(Object obj) { return ((OWLOntology) obj).getImportsDeclarations().iterator(); }
public GetUncommittedChangesVisitor(OWLOntology ontology) { this.ontology = ontology; this.ontologyId = ontology.getOntologyID(); ontologyIdChanged = !ontologyId.isAnonymous(); for (OWLImportsDeclaration decl : ontology.getImportsDeclarations()) { importChanges.put(decl, OntologyChangeType.ADDED); } for (OWLAnnotation annotation : ontology.getAnnotations()) { annotationChanges.put(annotation, OntologyChangeType.ADDED); } for (OWLAxiom axiom : ontology.getAxioms()) { axiomChanges.put(axiom, OntologyChangeType.ADDED); } }
private static void adjustImports(OWLOntology ontology, List<OWLOntologyChange> changes, OWLOntologyLoaderConfiguration configuration) throws UnloadableImportException { OWLOntologyManager manager = ontology.getOWLOntologyManager(); Set<OWLImportsDeclaration> finalDeclaredImports = ontology.getImportsDeclarations(); Set<OWLImportsDeclaration> missingImports = new TreeSet<OWLImportsDeclaration>(); for (OWLOntologyChange change : changes) { if (change instanceof AddImport) { OWLImportsDeclaration importDecl = ((AddImport) change).getImportDeclaration(); if (finalDeclaredImports.contains(importDecl) && manager.getImportedOntology(importDecl) == null) { missingImports.add(importDecl); } } } for (OWLImportsDeclaration missingImport : missingImports) { manager.makeLoadImportRequest(missingImport, configuration); } }
public void setOntology(OWLOntology ont) { this.ont = ont; List<Object> data = new ArrayList<>(); data.add(directImportsHeader); // @@TODO ordering for (OWLImportsDeclaration decl : ont.getImportsDeclarations()) { data.add(new OntologyImportItem(ont, decl, editorKit)); } data.add(indirectImportsHeader); // @@TODO ordering try { for (OWLOntology ontRef : editorKit.getOWLModelManager().getOWLOntologyManager().getImportsClosure(ont)) { if (!ontRef.equals(ont)) { for (OWLImportsDeclaration dec : ontRef.getImportsDeclarations()) { if (!data.contains(dec)) { data.add(new OntologyImportItem(ontRef, dec, editorKit)); } } } } } catch (UnknownOWLOntologyException e) { throw new OWLRuntimeException(e); } setListData(data.toArray()); }
public void setOntology(OWLOntology ont){ this.ont = ont; List<Object> data = new ArrayList<Object>(); data.add(directImportsHeader); // @@TODO ordering for (OWLImportsDeclaration decl : ont.getImportsDeclarations()){ data.add(new OntologyImportItem(ont, decl, eKit)); } data.add(indirectImportsHeader); // @@TODO ordering try { for (OWLOntology ontRef : eKit.getOWLModelManager().getOWLOntologyManager().getImportsClosure(ont)) { if (!ontRef.equals(ont)) { for (OWLImportsDeclaration dec : ontRef.getImportsDeclarations()) { if (!data.contains(dec)) { data.add(new OntologyImportItem(ontRef, dec, eKit)); } } } } } catch (UnknownOWLOntologyException e) { throw new OWLRuntimeException(e); } setListData(data.toArray()); }
public void setOntology(OWLOntology ont) { this.ont = ont; List<Object> data = new ArrayList<>(); data.add(directImportsHeader); // @@TODO ordering for (OWLImportsDeclaration decl : ont.getImportsDeclarations()) { data.add(new OntologyImportItem(ont, decl, editorKit)); } data.add(indirectImportsHeader); // @@TODO ordering try { for (OWLOntology ontRef : editorKit.getOWLModelManager().getOWLOntologyManager().getImportsClosure(ont)) { if (!ontRef.equals(ont)) { for (OWLImportsDeclaration dec : ontRef.getImportsDeclarations()) { if (!data.contains(dec)) { data.add(new OntologyImportItem(ontRef, dec, editorKit)); } } } } } catch (UnknownOWLOntologyException e) { throw new OWLRuntimeException(e); } setListData(data.toArray()); }
/** * Given an ontology, remove the import declarations. * * @param ontology OWLOntology to remove imports from */ public static void removeImports(OWLOntology ontology) { OWLOntologyManager manager = ontology.getOWLOntologyManager(); for (OWLImportsDeclaration i : ontology.getImportsDeclarations()) { manager.applyChange(new RemoveImport(ontology, i)); } }
/** * Given an ontology, remove the import statements. * * @param ontology the ontology to remove import statements from */ private static void removeImports(OWLOntology ontology) { Set<OWLImportsDeclaration> oids = ontology.getImportsDeclarations(); for (OWLImportsDeclaration oid : oids) { RemoveImport ri = new RemoveImport(ontology, oid); ontology.getOWLOntologyManager().applyChange(ri); } }
/** * Gets the set of <em>loaded</em> ontologies that the specified ontology is related to via the directlyImports relation as * defined in Section 3.4 of the OWL 2 Structural specification * * @param ontology The ontology whose direct imports are to be retrieved. * @return The set of <em>loaded</em> ontologies that the specified ontology is related to via the directlyImports * relation. * * @throws org.semanticweb.owlapi.model.UnknownOWLOntologyException * if there isn't an ontology in this manager which has the specified IRI. */ public Set<OWLOntology> getDirectImports(OWLOntology ontology) throws UnknownOWLOntologyException { if (!contains(ontology)) { throw new UnknownOWLOntologyException(ontology.getOntologyID()); } Set<OWLOntology> imports = new HashSet<OWLOntology>(); for (OWLImportsDeclaration axiom : ontology.getImportsDeclarations()) { OWLOntology importedOntology = getImportedOntology(axiom); if (importedOntology != null) { imports.add(importedOntology); } } return imports; }
public void visit(OWLOntology ontology) { for (OWLImportsDeclaration decl : ontology.getImportsDeclarations()) { writer.writeStartElement(IMPORT); writer.writeTextContent(decl.getURI().toString()); writer.writeEndElement(); } for(OWLAnnotation annotation : ontology.getAnnotations()) { annotation.accept(this); } List<OWLAxiom> axioms = new ArrayList<OWLAxiom>(ontology.getAxioms()); Collections.sort(axioms); for (OWLAxiom ax : axioms) { ax.accept(this); } }
@Override public void visit(OWLOntology ontology) { for (OWLImportsDeclaration decl : ontology.getImportsDeclarations()) { writer.writeStartElement(IMPORT); writer.writeTextContent(decl.getURI().toString()); writer.writeEndElement(); } for (OWLAnnotation annotation : ontology.getAnnotations()) { annotation.accept(this); } List<OWLAxiom> axioms = new ArrayList<OWLAxiom>(ontology.getAxioms()); Collections.sort(axioms); for (OWLAxiom ax : axioms) { ax.accept(this); } }
private List<OWLOntologyChange> getChanges(OWLOntology ontology, OWLOntologyID id) { List<OWLOntologyChange> changes = new ArrayList<>(); OWLOntologyManager owlOntologyManager = ontology.getOWLOntologyManager(); OWLDataFactory factory = owlOntologyManager.getOWLDataFactory(); OWLOntologyID oldId = ontology.getOntologyID(); changes.add(new SetOntologyID(ontology, id)); if (!id.isAnonymous() && !id.equals(oldId)) { for (OWLOntology ont : owlOntologyManager.getOntologies()) { for (OWLImportsDeclaration decl : ont.getImportsDeclarations()) { if (Optional.of(decl.getIRI()).equals(oldId.getVersionIRI())) { changes.add(new RemoveImport(ont, decl)); changes.add(new AddImport(ont, factory.getOWLImportsDeclaration(id.getDefaultDocumentIRI().get()))); } else if (Optional.of(decl.getIRI()).equals(oldId.getOntologyIRI())) { changes.add(new RemoveImport(ont, decl)); changes.add(new AddImport(ont, factory.getOWLImportsDeclaration(id.getOntologyIRI().get()))); } } } } return changes; }
private List<OWLOntologyChange> getChanges(OWLOntology ontology, OWLOntologyID id) { List<OWLOntologyChange> changes = new ArrayList<>(); OWLOntologyManager owlOntologyManager = ontology.getOWLOntologyManager(); OWLDataFactory factory = owlOntologyManager.getOWLDataFactory(); OWLOntologyID oldId = ontology.getOntologyID(); changes.add(new SetOntologyID(ontology, id)); if (!id.isAnonymous() && !id.equals(oldId)) { for (OWLOntology ont : owlOntologyManager.getOntologies()) { for (OWLImportsDeclaration decl : ont.getImportsDeclarations()) { if (Optional.of(decl.getIRI()).equals(oldId.getVersionIRI())) { changes.add(new RemoveImport(ont, decl)); changes.add(new AddImport(ont, factory.getOWLImportsDeclaration(id.getDefaultDocumentIRI().get()))); } else if (Optional.of(decl.getIRI()).equals(oldId.getOntologyIRI())) { changes.add(new RemoveImport(ont, decl)); changes.add(new AddImport(ont, factory.getOWLImportsDeclaration(id.getOntologyIRI().get()))); } } } } return changes; }
/** * Changes the URI of the specified ontology to the new URI. * * @param ontology The ontology whose URI is to be changed. * @param newIRI * @return A list of changes, which when applied will change the URI of the * specified ontology, and also update the imports declarations in any ontologies * which import the specified ontology. */ public List<OWLOntologyChange> getChanges(OWLOntology ontology, IRI newIRI) { List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>(); changes.add(new SetOntologyID(ontology, new OWLOntologyID(newIRI, ontology.getOntologyID().getVersionIRI()))); for (OWLOntology ont : owlOntologyManager.getOntologies()) { for (OWLImportsDeclaration decl : ont.getImportsDeclarations()) { if (decl.getIRI().equals(ontology.getOntologyID().getOntologyIRI())) { changes.add(new RemoveImport(ont, decl)); changes.add(new AddImport(ont, owlOntologyManager.getOWLDataFactory().getOWLImportsDeclaration(newIRI))); } } } return changes; } }
private List<OWLOntologyChange> getChanges(OWLOntology ontology, OWLOntologyID id) { List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>(); OWLOntologyManager owlOntologyManager = ontology.getOWLOntologyManager(); OWLDataFactory factory = owlOntologyManager.getOWLDataFactory(); OWLOntologyID oldId = ontology.getOntologyID(); changes.add(new SetOntologyID(ontology, id)); if (!id.isAnonymous() && !id.equals(oldId)) { for (OWLOntology ont : owlOntologyManager.getOntologies()) { for (OWLImportsDeclaration decl : ont.getImportsDeclarations()) { if (decl.getIRI().equals(oldId.getVersionIRI())) { changes.add(new RemoveImport(ont, decl)); changes.add(new AddImport(ont, factory.getOWLImportsDeclaration(id.getDefaultDocumentIRI()))); } else if (decl.getIRI().equals(oldId.getOntologyIRI())) { changes.add(new RemoveImport(ont, decl)); changes.add(new AddImport(ont, factory.getOWLImportsDeclaration(id.getOntologyIRI()))); } } } } return changes; }
private ImmutableList<OWLOntologyChangeRecord> getInitialChangeRecords(OWLOntologyManager rootOntologyManager) { // TODO: Separate change generator ImmutableList.Builder<OWLOntologyChangeRecord> changeRecordList = ImmutableList.builder(); for (OWLOntology ont : rootOntologyManager.getOntologies()) { rootOntologyManager.setOntologyFormat(ont, new BinaryOWLOntologyDocumentFormat()); for (OWLAxiom axiom : ont.getAxioms()) { changeRecordList.add(new OWLOntologyChangeRecord(ont.getOntologyID(), new AddAxiomData(axiom))); } for (OWLAnnotation annotation : ont.getAnnotations()) { changeRecordList.add(new OWLOntologyChangeRecord(ont.getOntologyID(), new AddOntologyAnnotationData(annotation))); } for (OWLImportsDeclaration importsDeclaration : ont.getImportsDeclarations()) { changeRecordList.add(new OWLOntologyChangeRecord(ont.getOntologyID(), new AddImportData(importsDeclaration))); } } return changeRecordList.build(); }
private void addImportsDeclarationsToOntologyHeader(RDFResource ontologyHeaderNode) { for (OWLImportsDeclaration decl : ontology.getImportsDeclarations()) { graph.addTriple(new RDFTriple(ontologyHeaderNode, new RDFResourceIRI(OWL_IMPORTS.getIRI()), new RDFResourceIRI(decl.getIRI()))); } }
private List<OWLOntologyChange> getChanges(OWLOntology ontology, OWLOntologyID id) { List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>(); OWLOntologyManager owlOntologyManager = ontology.getOWLOntologyManager(); OWLDataFactory factory = owlOntologyManager.getOWLDataFactory(); OWLOntologyID oldId = ontology.getOntologyID(); changes.add(new SetOntologyID(ontology, id)); if (!id.isAnonymous() && !id.equals(oldId)) { for (OWLOntology ont : owlOntologyManager.getOntologies()) { for (OWLImportsDeclaration decl : ont.getImportsDeclarations()) { if (decl.getIRI().equals(oldId.getVersionIRI())) { changes.add(new RemoveImport(ont, decl)); changes.add(new AddImport(ont, factory.getOWLImportsDeclaration(id.getDefaultDocumentIRI()))); } else if (decl.getIRI().equals(oldId.getOntologyIRI())) { changes.add(new RemoveImport(ont, decl)); changes.add(new AddImport(ont, factory.getOWLImportsDeclaration(id.getOntologyIRI()))); } } } } return changes; }
void addOntologyStructure(OWLOntologyManager manager, OWLOntology ontology) { long parent = graph.createNode(OwlApiUtils.getIri(ontology)); graph.addLabel(parent, OwlLabels.OWL_ONTOLOGY); for (OWLImportsDeclaration importDeclaration : ontology.getImportsDeclarations()) { OWLOntology childOnt = manager.getImportedOntology(importDeclaration); if (null == childOnt) { // TODO: Why is childOnt sometimes null (when importing rdf)? continue; } long child = graph.createNode(OwlApiUtils.getIri(childOnt)); graph.addLabel(parent, OwlLabels.OWL_ONTOLOGY); if (graph.getRelationship(child, parent, OwlRelationships.RDFS_IS_DEFINED_BY).isPresent()) { continue; } graph.createRelationship(child, parent, OwlRelationships.RDFS_IS_DEFINED_BY); addOntologyStructure(manager, childOnt); } }