public OWLOntology createOntology(Set<OWLAxiom> axioms, IRI iri) throws OWLOntologyCreationException { if (contains(iri)) { throw new OWLOntologyAlreadyExistsException(new OWLOntologyID(iri)); } OWLOntology ont = createOntology(iri); addAxioms(ont, axioms); return ont; }
@Override public void ontologyCreated(OWLOntology ontology) { // This method is called when a factory that we have asked to create or // load an ontology has created the ontology. We add the ontology to the // set of loaded ontologies. addOntology(ontology); }
public List<OWLOntologyChange> applyChange(OWLOntologyChange change) { fireBeginChanges(1); List<OWLOntologyChange> changes = enactChangeApplication(change); fireChangeApplied(change); fireEndChanges(); broadcastChanges(changes); return changes; }
public OWLOntology createOntology(Set<OWLAxiom> axioms) throws OWLOntologyCreationException { return createOntology(axioms, getNextAutoGeneratedIRI()); }
protected void actuallyApply(List<? extends OWLOntologyChange> changes, AtomicBoolean rollbackRequested, AtomicBoolean allNoOps, List<OWLOntologyChange> appliedChanges) { for (OWLOntologyChange change : changes) { // once rollback is requested by a failed change, do not carry // out any more changes if (!rollbackRequested.get()) { assert change != null; ChangeApplied enactChangeApplication = enactChangeApplication(change); if (enactChangeApplication == ChangeApplied.UNSUCCESSFULLY) { rollbackRequested.set(true); } if (enactChangeApplication == ChangeApplied.SUCCESSFULLY) { allNoOps.set(false); appliedChanges.add(change); } fireChangeApplied(change); } } }
writeLock.lock(); try { broadcastImpendingChanges(changes); AtomicBoolean rollbackRequested = new AtomicBoolean(false); AtomicBoolean allNoOps = new AtomicBoolean(true); fireBeginChanges(changes.size()); actuallyApply(changes, rollbackRequested, allNoOps, appliedChanges); if (rollbackRequested.get()) { rollBack(appliedChanges); appliedChanges.clear(); fireEndChanges(); broadcastChanges(appliedChanges); if (rollbackRequested.get()) { return new ChangeDetails(ChangeApplied.UNSUCCESSFULLY, appliedChanges); } catch (OWLOntologyChangeVetoException e) { broadcastOntologyChangesVetoed(changes, e); return new ChangeDetails(ChangeApplied.UNSUCCESSFULLY, Collections.emptyList()); } finally {
case SHALLOW: case DEEP: OWLOntology o = createOntology(toCopy.getOntologyID()); AxiomType.AXIOM_TYPES.forEach(t -> addAxioms(o, toCopy.axioms(t))); toCopy.annotations().forEach(a -> applyChange(new AddOntologyAnnotation(o, a))); toCopy.importsDeclarations().forEach(a -> applyChange(new AddImport(o, a))); toReturn = o; break; setOntologyDocumentIRI(toReturn, m.getOntologyDocumentIRI(toCopy)); OWLDocumentFormat ontologyFormat = m.getOntologyFormat(toCopy); if (ontologyFormat != null) { setOntologyFormat(toReturn, ontologyFormat);
/** * Applies a change to an ontology and performs the necessary housekeeping * tasks. * * @param change The change to be applied. * @return A list of changes that were actually applied. * * @throws OWLOntologyChangeException */ private List<OWLOntologyChange> enactChangeApplication(OWLOntologyChange change) { if (!isChangeApplicable(change)) { return Collections.emptyList(); } OWLOntology ont = change.getOntology(); if (!(ont instanceof OWLMutableOntology)) { throw new ImmutableOWLOntologyChangeException(change); } checkForOntologyIDChange(change); List<OWLOntologyChange> appliedChanges = ((OWLMutableOntology) ont).applyChange(change); checkForImportsChange(change); return appliedChanges; }
public boolean contains(IRI ontologyIRI) { return contains(new OWLOntologyID(ontologyIRI)); }
/** * Gets the set of ontologies that are in the transitive closure of the directly imports relation. * * @param ontology The ontology whose imports are to be retrieved. * @return A set of <code>OWLOntology</code>ies that are in the transitive closure of the directly imports relation * of this ontology. If, for what ever reason, an imported ontology could not be loaded, then it will not be contained in the * returned set of ontologies. * * @throws org.semanticweb.owlapi.model.UnknownOWLOntologyException * if there isn't an ontology in this manager which has the specified IRI. */ public Set<OWLOntology> getImports(OWLOntology ontology) throws UnknownOWLOntologyException { if (!contains(ontology)) { throw new UnknownOWLOntologyException(ontology.getOntologyID()); } Set<OWLOntology> result = new HashSet<OWLOntology>(); getImports(ontology, result); return result; }
protected void rollBack(List<OWLOntologyChange> appliedChanges) { for (OWLOntologyChange c : appliedChanges) { if (enactChangeApplication(c.reverseChange()) == ChangeApplied.UNSUCCESSFULLY) { // rollback could not complete, throw an exception throw new OWLRuntimeException( "Rollback of changes unsuccessful: Change " + c + " could not be rolled back"); } } }
public OWLOntology createOntology(IRI ontologyIRI, Set<OWLOntology> ontologies) throws OWLOntologyCreationException { return createOntology(ontologyIRI, ontologies, false); }
/** * 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 List<OWLOntologyChange> addAxiom(OWLOntology ont, OWLAxiom axiom) { return addAxioms(ont, Collections.singleton(axiom)); }
writeLock.lock(); try { broadcastImpendingChanges(changes); AtomicBoolean rollbackRequested = new AtomicBoolean(false); AtomicBoolean allNoOps = new AtomicBoolean(true); fireBeginChanges(changes.size()); actuallyApply(changes, rollbackRequested, allNoOps, appliedChanges); if (rollbackRequested.get()) { rollBack(appliedChanges); appliedChanges.clear(); fireEndChanges(); broadcastChanges(appliedChanges); if (rollbackRequested.get()) { return new ChangeDetails(ChangeApplied.UNSUCCESSFULLY, appliedChanges); } catch (OWLOntologyChangeVetoException e) { broadcastOntologyChangesVetoed(changes, e); return new ChangeDetails(ChangeApplied.UNSUCCESSFULLY, Collections.emptyList()); } finally {
case SHALLOW: case DEEP: OWLOntology o = createOntology(toCopy.getOntologyID()); AxiomType.AXIOM_TYPES.forEach(t -> addAxioms(o, toCopy.axioms(t))); toCopy.annotations().forEach(a -> applyChange(new AddOntologyAnnotation(o, a))); toCopy.importsDeclarations().forEach(a -> applyChange(new AddImport(o, a))); toReturn = o; break; setOntologyDocumentIRI(toReturn, m.getOntologyDocumentIRI(toCopy)); OWLDocumentFormat ontologyFormat = m.getOntologyFormat(toCopy); if (ontologyFormat != null) { setOntologyFormat(toReturn, ontologyFormat);
/** * Applies a change to an ontology and performs the necessary housekeeping tasks. * * @param change The change to be applied. * @return A list of changes that were actually applied. */ private ChangeApplied enactChangeApplication(OWLOntologyChange change) { if (!isChangeApplicable(change)) { return ChangeApplied.UNSUCCESSFULLY; } OWLOntology ont = change.getOntology(); if (!(ont instanceof OWLMutableOntology)) { throw new ImmutableOWLOntologyChangeException(change.getChangeData(), ont.toString()); } checkForOntologyIDChange(change); ChangeApplied appliedChange = ((OWLMutableOntology) ont).applyDirectChange(change); checkForImportsChange(change); return appliedChange; }
protected void actuallyApply(List<? extends OWLOntologyChange> changes, AtomicBoolean rollbackRequested, AtomicBoolean allNoOps, List<OWLOntologyChange> appliedChanges) { for (OWLOntologyChange change : changes) { // once rollback is requested by a failed change, do not carry // out any more changes if (!rollbackRequested.get()) { assert change != null; ChangeApplied enactChangeApplication = enactChangeApplication(change); if (enactChangeApplication == ChangeApplied.UNSUCCESSFULLY) { rollbackRequested.set(true); } if (enactChangeApplication == ChangeApplied.SUCCESSFULLY) { allNoOps.set(false); appliedChanges.add(change); } fireChangeApplied(change); } } }
@Override public Stream<OWLOntology> directImports(OWLOntology ontology) { readLock.lock(); try { if (!contains(ontology)) { throw new UnknownOWLOntologyException(ontology.getOntologyID()); } return ontology.importsDeclarations().map(this::getImportedOntology) .filter(Objects::nonNull); } finally { readLock.unlock(); } }
protected void rollBack(List<OWLOntologyChange> appliedChanges) { for (OWLOntologyChange c : appliedChanges) { if (enactChangeApplication(c.reverseChange()) == ChangeApplied.UNSUCCESSFULLY) { // rollback could not complete, throw an exception throw new OWLRuntimeException( "Rollback of changes unsuccessful: Change " + c + " could not be rolled back"); } } }