Search in sources :

Example 1 with EqualityHandlerConverter

use of fr.lirmm.graphik.graal.homomorphism.utils.EqualityHandlerConverter in project graal by graphik-team.

the class RecursiveBacktrackHomomorphism method execute.

// /////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
// /////////////////////////////////////////////////////////////////////////
@Override
public CloseableIterator<Substitution> execute(ConjunctiveQuery query, AtomSet facts) throws HomomorphismException {
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace(query.toString());
    }
    if (profiler != null) {
        profiler.start("preprocessing time");
    }
    Pair<ConjunctiveQuery, Substitution> pair = EqualityUtils.processEquality(query);
    List<Variable> orderedVars = order(pair.getLeft().getAtomSet().getVariables());
    Collection<Atom>[] queryAtomRanked = getAtomRank(pair.getLeft().getAtomSet(), orderedVars);
    if (profiler != null) {
        profiler.stop("preprocessing time");
    }
    try {
        this.domain = facts.getTerms();
        if (profiler != null) {
            profiler.start("backtracking time");
        }
        CloseableIterator<Substitution> results;
        if (isHomomorphism(queryAtomRanked[0], facts, new HashMapSubstitution())) {
            results = new CloseableIteratorAdapter<Substitution>(homomorphism(pair.getLeft(), queryAtomRanked, facts, new HashMapSubstitution(), orderedVars, 1).iterator());
        } else {
            // return false
            results = new CloseableIteratorAdapter<Substitution>(Collections.<Substitution>emptyList().iterator());
        }
        if (profiler != null) {
            profiler.stop("backtracking time");
        }
        if (!pair.getRight().getTerms().isEmpty()) {
            results = new ConverterCloseableIterator<Substitution, Substitution>(results, new EqualityHandlerConverter(pair.getRight()));
        }
        return results;
    } catch (Exception e) {
        throw new HomomorphismException(e.getMessage(), e);
    }
}
Also used : Variable(fr.lirmm.graphik.graal.api.core.Variable) HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException) HashMapSubstitution(fr.lirmm.graphik.graal.core.HashMapSubstitution) CloseableIteratorWithoutException(fr.lirmm.graphik.util.stream.CloseableIteratorWithoutException) CloseableIterableWithoutException(fr.lirmm.graphik.util.stream.CloseableIterableWithoutException) HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) HashMapSubstitution(fr.lirmm.graphik.graal.core.HashMapSubstitution) Collection(java.util.Collection) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) EqualityHandlerConverter(fr.lirmm.graphik.graal.homomorphism.utils.EqualityHandlerConverter)

Aggregations

ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)1 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)1 Variable (fr.lirmm.graphik.graal.api.core.Variable)1 HomomorphismException (fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException)1 HashMapSubstitution (fr.lirmm.graphik.graal.core.HashMapSubstitution)1 EqualityHandlerConverter (fr.lirmm.graphik.graal.homomorphism.utils.EqualityHandlerConverter)1 CloseableIterableWithoutException (fr.lirmm.graphik.util.stream.CloseableIterableWithoutException)1 CloseableIteratorWithoutException (fr.lirmm.graphik.util.stream.CloseableIteratorWithoutException)1 Collection (java.util.Collection)1