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

edu.stanford.protege.webprotege.match.AnnotationValuesAreNotDisjointMatcher Maven / Gradle / Ivy

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



import edu.stanford.protege.webprotege.index.AnnotationAssertionAxiomsIndex;
import org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom;
import org.semanticweb.owlapi.model.OWLAnnotationProperty;
import org.semanticweb.owlapi.model.OWLAnnotationValue;
import org.semanticweb.owlapi.model.OWLEntity;

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;
import static java.util.stream.Collectors.toList;

/**
 * Matthew Horridge
 * Stanford Center for Biomedical Informatics Research
 * 12 Jun 2018
 */

public class AnnotationValuesAreNotDisjointMatcher implements Matcher {

    @Nonnull
    private final AnnotationAssertionAxiomsIndex axioms;

    @Nonnull
    private final Matcher propertyA;

    @Nonnull
    private final Matcher propertyB;

    @Inject
    public AnnotationValuesAreNotDisjointMatcher(@Nonnull  AnnotationAssertionAxiomsIndex axioms,
                                                 @Nonnull Matcher propertyA,
                                                 @Nonnull Matcher propertyB) {
        this.axioms = checkNotNull(axioms);
        this.propertyA = checkNotNull(propertyA);
        this.propertyB = checkNotNull(propertyB);
    }

    @Override
    public boolean matches(@Nonnull OWLEntity value) {
        Collection assertions = axioms.getAnnotationAssertionAxioms(value.getIRI()).collect(toList());
        Set valuesA = new HashSet<>(assertions.size());
        Set valuesB = new HashSet<>(assertions.size());
        for(OWLAnnotationAssertionAxiom ax : assertions) {
            OWLAnnotationValue val = ax.getValue();
            if(propertyA.matches(ax.getProperty())) {
                valuesA.add(val);
                if(valuesB.contains(val)) {
                    return true;
                }
            }
            else if(propertyB.matches(ax.getProperty())) {
                valuesB.add(val);
                if(valuesA.contains(val)) {
                    return true;
                }
            }
        }
        return false;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy