All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.stanford.protege.webprotege.merge.ModifiedProjectOntologiesCalculator Maven / Gradle / Ivy

The newest version!
package edu.stanford.protege.webprotege.merge;



import com.google.common.base.Optional;
import com.google.common.collect.ImmutableSet;
import edu.stanford.protege.webprotege.project.Ontology;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLOntologyID;

import javax.annotation.Nonnull;
import javax.inject.Inject;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import static com.google.common.base.Preconditions.checkNotNull;

/**
 * Matthew Horridge
 * Stanford Center for Biomedical Informatics Research
 * 26/01/15
 */
public class ModifiedProjectOntologiesCalculator {

    private final ImmutableSet projectOntologies;

    private final ImmutableSet editedOntologies;

    private final OntologyDiffCalculator diffCalculator;


    @Inject
    public ModifiedProjectOntologiesCalculator(@Nonnull Collection projectOntologies,
                                               @Nonnull Collection editedOntologies,
                                               @Nonnull OntologyDiffCalculator diffCalculator) {
        this.projectOntologies = ImmutableSet.copyOf(checkNotNull(projectOntologies));
        this.editedOntologies = ImmutableSet.copyOf(checkNotNull(editedOntologies));
        this.diffCalculator = checkNotNull(diffCalculator);
    }

    @Nonnull
    public Set getModifiedOntologyDiffs() {
        Set diffs = new HashSet<>();
        for(Ontology projectOntology : projectOntologies) {
            for(Ontology editedOntology : editedOntologies) {
                if(isDifferentVersionOfOntology(projectOntology.getOntologyId(), editedOntology.getOntologyId())) {
                    OntologyDiff ontologyDiff = diffCalculator.computeDiff(projectOntology, editedOntology);
                    if (!ontologyDiff.isEmpty()) {
                        diffs.add(ontologyDiff);
                    }
                }
            }
        }
        return diffs;
    }


    private boolean isDifferentVersionOfOntology(OWLOntologyID ontologyId, OWLOntologyID otherOntologyId) {
        if(ontologyId.isAnonymous()) {
            return false;
        }
        if(otherOntologyId.isAnonymous()) {
            return false;
        }
        Optional ontologyIRI = ontologyId.getOntologyIRI();
        Optional otherOntologyIRI = otherOntologyId.getOntologyIRI();
        return ontologyIRI.equals(otherOntologyIRI);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy