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

org.coode.oppl.search.solvability.MultipleAxiomSolvability Maven / Gradle / Ivy

package org.coode.oppl.search.solvability;

import static org.coode.oppl.utils.ArgCheck.checkNotNull;

import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import org.coode.oppl.bindingtree.BindingNode;
import org.semanticweb.owlapi.model.OWLAxiom;

/** Applies a set of solvability strategies, until either a node is solved or the
 * strategies are exhausted.
 * 
 * @author Luigi Iannone */
public class MultipleAxiomSolvability implements AxiomSolvability {
    private final Set delegates = new HashSet();

    /** @param delegates
     *            delegates */
    public MultipleAxiomSolvability(Collection delegates) {
        this.delegates.addAll(checkNotNull(delegates, "delegates"));
        if (delegates.isEmpty()) {
            throw new IllegalArgumentException("The delegate collection canont be empty");
        }
    }

    @Override
    public SolvabilitySearchNode getSolvabilitySearchNode(OWLAxiom owlAxiom,
            BindingNode bindingNode) {
        boolean solved = false;
        Iterator iterator = delegates.iterator();
        SolvabilitySearchNode toReturn = null;
        while (!solved && iterator.hasNext()) {
            AxiomSolvability axiomSolvability = iterator.next();
            toReturn = axiomSolvability.getSolvabilitySearchNode(owlAxiom, bindingNode);
            solved = toReturn.accept(new SolvabilitySearchNodeVisitorEx() {
                @Override
                public Boolean visitSolvableSearchNode(
                        SolvableSearchNode solvableSearchNode) {
                    return true;
                }

                @Override
                public Boolean visitSolvedSearchNode(SolvedSearchNode solvedSearchNode) {
                    return true;
                }

                @Override
                public Boolean visitNoSolutionSolvableSearchNode(
                        NoSolutionSolvableSearchNode noSolutionSolvableSearchNode) {
                    return true;
                }

                @Override
                public Boolean visitUnsolvableSearchNode(
                        UnsolvableSearchNode unsolvableSearchNode) {
                    return false;
                }
            });
        }
        return toReturn;
    }

    /** @return the delegates */
    public Set getDelegates() {
        return new HashSet(delegates);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy