Search in sources :

Example 1 with OWLOntologyChangeRecord

use of org.semanticweb.owlapi.change.OWLOntologyChangeRecord in project webprotege by protegeproject.

the class ProjectDocumentStore method saveOntologyChanges.

// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public void saveOntologyChanges(List<OWLOntologyChange> rawChangeList) {
    // Put changes into a buffer
    try {
        writeLock.lock();
        try {
            ListMultimap<OWLOntology, OWLOntologyChange> changesByOntology = ArrayListMultimap.create();
            for (OWLOntologyChange change : rawChangeList) {
                changesByOntology.put(change.getOntology(), change);
            }
            for (OWLOntology ontology : changesByOntology.keySet()) {
                IRI docIRI = ontology.getOWLOntologyManager().getOntologyDocumentIRI(ontology);
                if (!"file".equalsIgnoreCase(docIRI.toURI().getScheme())) {
                    throw new RuntimeException("Document IRI is not a local file IRI");
                }
                List<OWLOntologyChange> ontologyChangeList = changesByOntology.get(ontology);
                List<OWLOntologyChangeData> infoList = new ArrayList<>();
                for (OWLOntologyChange change : ontologyChangeList) {
                    OWLOntologyChangeRecord changeRecord = change.getChangeRecord();
                    infoList.add(changeRecord.getData());
                }
                File file = new File(docIRI.toURI());
                BinaryOWLOntologyDocumentSerializer serializer = new BinaryOWLOntologyDocumentSerializer();
                serializer.appendOntologyChanges(file, new OntologyChangeDataList(infoList, System.currentTimeMillis(), BinaryOWLMetadata.emptyMetadata()));
            }
        } catch (IOException e) {
            logger.error("An error occurred whilst saving ontology changes: {}", e.getMessage(), e);
            e.printStackTrace();
        }
    } finally {
        writeLock.unlock();
    }
}
Also used : ArrayList(java.util.ArrayList) OntologyChangeDataList(org.semanticweb.binaryowl.change.OntologyChangeDataList) OWLOntologyCreationIOException(org.semanticweb.owlapi.io.OWLOntologyCreationIOException) BinaryOWLOntologyDocumentSerializer(org.semanticweb.binaryowl.BinaryOWLOntologyDocumentSerializer) OWLOntologyChangeRecord(org.semanticweb.owlapi.change.OWLOntologyChangeRecord) OWLOntologyChangeData(org.semanticweb.owlapi.change.OWLOntologyChangeData)

Example 2 with OWLOntologyChangeRecord

use of org.semanticweb.owlapi.change.OWLOntologyChangeRecord in project webprotege by protegeproject.

the class ProjectImporter method generateInitialChanges.

private void generateInitialChanges(UserId owner, OWLOntologyManager rootOntologyManager) {
    ImmutableList<OWLOntologyChangeRecord> changeRecords = getInitialChangeRecords(rootOntologyManager);
    revisionStore.addRevision(new Revision(owner, RevisionNumber.getRevisionNumber(1), changeRecords, System.currentTimeMillis(), "Initial import"));
}
Also used : OWLOntologyChangeRecord(org.semanticweb.owlapi.change.OWLOntologyChangeRecord) Revision(edu.stanford.bmir.protege.web.server.revision.Revision)

Example 3 with OWLOntologyChangeRecord

use of org.semanticweb.owlapi.change.OWLOntologyChangeRecord in project webprotege by protegeproject.

the class ChangeManager method logAndBroadcastAppliedChanges.

private <R> Revision logAndBroadcastAppliedChanges(UserId userId, ChangeListGenerator<R> changeList, ChangeApplicationResult<R> finalResult) {
    // Generate a description for the changes that were actually applied
    String changeDescription = changeList.getMessage(finalResult);
    // Log the changes
    List<OWLOntologyChangeRecord> changeRecords = finalResult.getChangeList().stream().map(OWLOntologyChange::getChangeRecord).collect(toList());
    Revision revision = changeManager.addRevision(userId, changeRecords, changeDescription);
    // TODO: THis list of "listeners" should be injected
    List<OWLOntologyChange> changes = finalResult.getChangeList();
    documentStore.saveOntologyChanges(changes);
    classHierarchyProvider.handleChanges(changes);
    objectPropertyHierarchyProvider.handleChanges(changes);
    dataPropertyHierarchyProvider.handleChanges(changes);
    annotationPropertyHierarchyProvider.handleChanges(changes);
    return revision;
}
Also used : OWLOntologyChangeRecord(org.semanticweb.owlapi.change.OWLOntologyChangeRecord) Revision(edu.stanford.bmir.protege.web.server.revision.Revision)

Example 4 with OWLOntologyChangeRecord

use of org.semanticweb.owlapi.change.OWLOntologyChangeRecord in project webprotege by protegeproject.

the class EntitiesByRevisionCache method getEntitiesInternal.

private ImmutableSet<OWLEntity> getEntitiesInternal(Revision revision) {
    ImmutableSet.Builder<OWLEntity> result = ImmutableSet.builder();
    Set<IRI> iris = new HashSet<>();
    for (OWLOntologyChangeRecord change : revision) {
        if (change.getData() instanceof AxiomChangeData) {
            OWLAxiom ax = ((AxiomChangeData) change.getData()).getAxiom();
            java.util.Optional<? extends OWLObject> subject = axiomSubjectProvider.getSubject(ax);
            if (subject.isPresent()) {
                if (subject.get() instanceof OWLEntity) {
                    result.add((OWLEntity) subject.get());
                } else if (subject.get() instanceof IRI) {
                    iris.add((IRI) subject.get());
                }
            }
        }
    }
    for (IRI iri : iris) {
        for (EntityType<?> entityType : EntityType.values()) {
            OWLEntity entity = dataFactory.getOWLEntity(entityType, iri);
            if (hasContainsEntityInSignature.containsEntityInSignature(entity)) {
                result.add(entity);
            }
        }
    }
    return result.build();
}
Also used : OWLOntologyChangeRecord(org.semanticweb.owlapi.change.OWLOntologyChangeRecord) AxiomChangeData(org.semanticweb.owlapi.change.AxiomChangeData) ImmutableSet(com.google.common.collect.ImmutableSet) HashSet(java.util.HashSet)

Example 5 with OWLOntologyChangeRecord

use of org.semanticweb.owlapi.change.OWLOntologyChangeRecord in project webprotege by protegeproject.

the class RevisionManagerImpl method getOntologyManagerForRevision.

@Nonnull
@Override
public OWLOntologyManager getOntologyManagerForRevision(@Nonnull RevisionNumber revision) {
    try {
        OWLOntologyManager manager = WebProtegeOWLManager.createOWLOntologyManager();
        final OWLOntologyID singletonOntologyId = new OWLOntologyID();
        for (Revision rev : revisionStore.getRevisions()) {
            if (rev.getRevisionNumber().compareTo(revision) <= 0) {
                for (OWLOntologyChangeRecord record : rev) {
                    // Anonymous ontologies are not handled nicely at all.
                    OWLOntologyChangeRecord normalisedChangeRecord = normaliseChangeRecord(record, singletonOntologyId);
                    OWLOntologyID ontologyId = normalisedChangeRecord.getOntologyID();
                    if (!manager.contains(ontologyId)) {
                        manager.createOntology(ontologyId);
                    }
                    OWLOntologyChange change = normalisedChangeRecord.createOntologyChange(manager);
                    manager.applyChange(change);
                }
            }
        }
        if (manager.getOntologies().isEmpty()) {
            // No revisions exported.  Just create an empty ontology
            manager.createOntology();
        }
        return manager;
    } catch (OWLOntologyCreationException e) {
        throw new RuntimeException("Problem creating ontology: " + e);
    }
}
Also used : OWLOntologyChangeRecord(org.semanticweb.owlapi.change.OWLOntologyChangeRecord) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntologyChange(org.semanticweb.owlapi.model.OWLOntologyChange) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) Nonnull(javax.annotation.Nonnull)

Aggregations

OWLOntologyChangeRecord (org.semanticweb.owlapi.change.OWLOntologyChangeRecord)8 Revision (edu.stanford.bmir.protege.web.server.revision.Revision)4 ArrayList (java.util.ArrayList)2 OWLOntologyChangeData (org.semanticweb.owlapi.change.OWLOntologyChangeData)2 OWLOntologyChange (org.semanticweb.owlapi.model.OWLOntologyChange)2 OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)2 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Revision2DiffElementsTranslator (edu.stanford.bmir.protege.web.server.diff.Revision2DiffElementsTranslator)1 ProjectChange (edu.stanford.bmir.protege.web.shared.change.ProjectChange)1 DiffElement (edu.stanford.bmir.protege.web.shared.diff.DiffElement)1 Page (edu.stanford.bmir.protege.web.shared.pagination.Page)1 UserId (edu.stanford.bmir.protege.web.shared.user.UserId)1 HashSet (java.util.HashSet)1 Nonnull (javax.annotation.Nonnull)1 Test (org.junit.Test)1 BinaryOWLOntologyDocumentSerializer (org.semanticweb.binaryowl.BinaryOWLOntologyDocumentSerializer)1 OntologyChangeDataList (org.semanticweb.binaryowl.change.OntologyChangeDataList)1 AddAxiomData (org.semanticweb.owlapi.change.AddAxiomData)1