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

uk.ac.manchester.cs.atomicdecomposition.Atom Maven / Gradle / Ivy

There is a newer version: 5.5.1
Show newest version
package uk.ac.manchester.cs.atomicdecomposition;

import static org.semanticweb.owlapi.util.OWLAPIPreconditions.verifyNotNull;
import static org.semanticweb.owlapi.util.OWLAPIStreamUtils.add;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.annotation.Nullable;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLEntity;

/**
 * An atom in the atomic decomposition
 */
public class Atom {

    private final Collection axioms;
    // XXX cache properly
    @Nullable
    private List signature;
    @Nullable
    private Collection label;
    private final int hashcode;

    /**
     * @param axioms build an atom out of a set of axioms
     */
    public Atom(Collection axioms) {
        this.axioms = axioms;
        hashcode = this.axioms.hashCode();
    }

    /**
     * @param ax axiom
     * @return true if ax is in this atom
     */
    public boolean contains(OWLAxiom ax) {
        return axioms.contains(ax);
    }

    private void initSignature() {
        if (signature == null) {
            signature = new ArrayList<>();
            axioms.forEach(ax -> add(verifyNotNull(signature), ax.signature()));
        }
    }

    /**
     * @return signature for the atom
     */
    public Collection getSignature() {
        initSignature();
        return verifyNotNull(signature);
    }

    /**
     * @return axioms in the atom
     */
    public Collection getAxioms() {
        return axioms;
    }

    /**
     * @return label for the atom
     */
    @Nullable
    public Collection getLabel() {
        return label;
    }

    /**
     * @param labelSignature the label for the atom
     */
    public void setLabel(Collection labelSignature) {
        label = labelSignature;
    }

    @Override
    public boolean equals(@Nullable Object obj) {
        if (obj == this) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (obj instanceof Atom) {
            return axioms.equals(((Atom) obj).axioms);
        }
        return false;
    }

    @Override
    public int hashCode() {
        return hashcode;
    }

    @Override
    public String toString() {
        return axioms.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy