Search in sources :

Example 1 with AxiomSubjectProvider

use of org.semanticweb.owlapi.util.AxiomSubjectProvider in project webprotege by protegeproject.

the class HighLevelEventGenerator method translateOntologyChanges.

@Override
public void translateOntologyChanges(Revision revision, ChangeApplicationResult<?> changes, final List<ProjectEvent<?>> projectEventList) {
    // TODO: NEED TIDYING AND SPLITTING UP
    final Set<OWLEntity> changedEntities = new HashSet<>();
    for (OWLOntologyChange change : changes.getChangeList()) {
        change.accept(new OWLOntologyChangeVisitor() {

            @Override
            public void visit(@Nonnull AddAxiom change) {
                final OWLAxiom axiom = change.getAxiom();
                handleAxiomChange(axiom);
            }

            @Override
            public void visit(@Nonnull RemoveAxiom change) {
                handleAxiomChange(change.getAxiom());
            }

            @Override
            public void visit(@Nonnull SetOntologyID change) {
                projectEventList.add(new OntologyFrameChangedEvent(change.getOntology().getOntologyID(), projectId));
            }

            @Override
            public void visit(@Nonnull AddImport change) {
                projectEventList.add(new OntologyFrameChangedEvent(change.getOntology().getOntologyID(), projectId));
            }

            @Override
            public void visit(@Nonnull RemoveImport change) {
                projectEventList.add(new OntologyFrameChangedEvent(change.getOntology().getOntologyID(), projectId));
            }

            @Override
            public void visit(@Nonnull AddOntologyAnnotation change) {
                projectEventList.add(new OntologyFrameChangedEvent(change.getOntology().getOntologyID(), projectId));
            }

            @Override
            public void visit(@Nonnull RemoveOntologyAnnotation change) {
                projectEventList.add(new OntologyFrameChangedEvent(change.getOntology().getOntologyID(), projectId));
            }

            private void handleAxiomChange(OWLAxiom axiom) {
                AxiomSubjectProvider p = new AxiomSubjectProvider();
                OWLObject subject = p.getSubject(axiom);
                Set<OWLEntity> entities;
                if (subject instanceof IRI) {
                    entities = hasGetEntitiesWithIRI.getEntitiesWithIRI((IRI) subject);
                } else if (subject instanceof OWLEntity) {
                    entities = Collections.singleton((OWLEntity) subject);
                } else {
                    entities = Collections.emptySet();
                }
                for (OWLEntity e : entities) {
                    if (!changedEntities.contains(e)) {
                        changedEntities.add(e);
                        ProjectEvent<?> event = e.accept(new OWLEntityVisitorEx<ProjectEvent<?>>() {

                            @Nonnull
                            @Override
                            public ProjectEvent<?> visit(@Nonnull OWLClass cls) {
                                return new ClassFrameChangedEvent(cls, projectId, revision.getUserId());
                            }

                            @Nonnull
                            @Override
                            public ProjectEvent<?> visit(@Nonnull OWLObjectProperty property) {
                                return new ObjectPropertyFrameChangedEvent(property, projectId, revision.getUserId());
                            }

                            @Nonnull
                            @Override
                            public ProjectEvent<?> visit(@Nonnull OWLDataProperty property) {
                                return new DataPropertyFrameChangedEvent(property, projectId, revision.getUserId());
                            }

                            @Nonnull
                            @Override
                            public ProjectEvent<?> visit(@Nonnull OWLNamedIndividual individual) {
                                return new NamedIndividualFrameChangedEvent(individual, projectId, revision.getUserId());
                            }

                            @Nonnull
                            @Override
                            public ProjectEvent<?> visit(@Nonnull OWLDatatype datatype) {
                                return new DatatypeFrameChangedEvent(datatype, projectId, revision.getUserId());
                            }

                            @Nonnull
                            @Override
                            public ProjectEvent<?> visit(@Nonnull OWLAnnotationProperty property) {
                                return new AnnotationPropertyFrameChangedEvent(property, projectId, revision.getUserId());
                            }
                        });
                        projectEventList.add(event);
                    }
                }
            }
        });
    }
    Set<OWLEntityData> changedEntitiesData = new HashSet<>();
    Object subject = changes.getSubject();
    if (subject instanceof OWLEntity) {
        OWLEntity entity = (OWLEntity) subject;
        if (rootOntology.containsEntityInSignature(entity)) {
            String browserText = browserTextProvider.getOWLEntityBrowserText(entity).orElse("");
            changedEntitiesData.add(DataFactory.getOWLEntityData(entity, browserText));
        }
    } else if (subject instanceof OWLEntityData) {
        OWLEntityData entityData = (OWLEntityData) subject;
        if (rootOntology.containsEntityInSignature(entityData.getEntity())) {
            changedEntitiesData.add(entityData);
        }
    } else if (subject instanceof Collection) {
        Collection<?> collection = (Collection<?>) subject;
        collection.stream().filter(element -> element instanceof OWLEntity).map(element -> (OWLEntity) element).filter(rootOntology::containsEntityInSignature).forEach(entity -> {
            String browserText = browserTextProvider.getOWLEntityBrowserText(entity).orElse("");
            changedEntitiesData.add(DataFactory.getOWLEntityData(entity, browserText));
        });
    }
    Optional<RevisionSummary> revisionSummary = hasGetRevisionSummary.getRevisionSummary(revision.getRevisionNumber());
    if (revisionSummary.isPresent()) {
        ProjectEvent<?> event = new ProjectChangedEvent(projectId, revisionSummary.get(), changedEntitiesData);
        projectEventList.add(event);
    }
}
Also used : BrowserTextProvider(edu.stanford.bmir.protege.web.shared.BrowserTextProvider) Revision(edu.stanford.bmir.protege.web.server.revision.Revision) java.util(java.util) org.semanticweb.owlapi.model(org.semanticweb.owlapi.model) HasGetRevisionSummary(edu.stanford.bmir.protege.web.server.change.HasGetRevisionSummary) AxiomSubjectProvider(org.semanticweb.owlapi.util.AxiomSubjectProvider) OWLEntityData(edu.stanford.bmir.protege.web.shared.entity.OWLEntityData) DataFactory(edu.stanford.bmir.protege.web.shared.DataFactory) HasGetEntitiesWithIRI(edu.stanford.bmir.protege.web.shared.HasGetEntitiesWithIRI) Inject(javax.inject.Inject) edu.stanford.bmir.protege.web.shared.event(edu.stanford.bmir.protege.web.shared.event) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) Nonnull(javax.annotation.Nonnull) ChangeApplicationResult(edu.stanford.bmir.protege.web.server.change.ChangeApplicationResult) RevisionSummary(edu.stanford.bmir.protege.web.shared.revision.RevisionSummary) HasGetEntitiesWithIRI(edu.stanford.bmir.protege.web.shared.HasGetEntitiesWithIRI) Nonnull(javax.annotation.Nonnull) OWLEntityData(edu.stanford.bmir.protege.web.shared.entity.OWLEntityData) AxiomSubjectProvider(org.semanticweb.owlapi.util.AxiomSubjectProvider) HasGetRevisionSummary(edu.stanford.bmir.protege.web.server.change.HasGetRevisionSummary) RevisionSummary(edu.stanford.bmir.protege.web.shared.revision.RevisionSummary)

Aggregations

ChangeApplicationResult (edu.stanford.bmir.protege.web.server.change.ChangeApplicationResult)1 HasGetRevisionSummary (edu.stanford.bmir.protege.web.server.change.HasGetRevisionSummary)1 Revision (edu.stanford.bmir.protege.web.server.revision.Revision)1 BrowserTextProvider (edu.stanford.bmir.protege.web.shared.BrowserTextProvider)1 DataFactory (edu.stanford.bmir.protege.web.shared.DataFactory)1 HasGetEntitiesWithIRI (edu.stanford.bmir.protege.web.shared.HasGetEntitiesWithIRI)1 OWLEntityData (edu.stanford.bmir.protege.web.shared.entity.OWLEntityData)1 edu.stanford.bmir.protege.web.shared.event (edu.stanford.bmir.protege.web.shared.event)1 ProjectId (edu.stanford.bmir.protege.web.shared.project.ProjectId)1 RevisionSummary (edu.stanford.bmir.protege.web.shared.revision.RevisionSummary)1 java.util (java.util)1 Nonnull (javax.annotation.Nonnull)1 Inject (javax.inject.Inject)1 org.semanticweb.owlapi.model (org.semanticweb.owlapi.model)1 AxiomSubjectProvider (org.semanticweb.owlapi.util.AxiomSubjectProvider)1