Search in sources :

Example 11 with HomomorphismException

use of fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException in project graal by graphik-team.

the class RuleApplierIterator method hasNext.

@Override
public boolean hasNext() throws IteratorException {
    if (!this.hasNextCallDone) {
        this.hasNextCallDone = true;
        if (this.localIt != null && !this.localIt.hasNext()) {
            this.localIt.close();
            this.localIt = null;
        }
        while ((this.localIt == null || !this.localIt.hasNext()) && this.substitutionIt.hasNext()) {
            try {
                localIt = haltingCondition.apply(rule, substitutionIt.next(), atomset);
            } catch (HomomorphismFactoryException e) {
                throw new IteratorException("Error during rule application", e);
            } catch (HomomorphismException e) {
                throw new IteratorException("Error during rule application", e);
            }
        }
    }
    return this.localIt != null && this.localIt.hasNext();
}
Also used : IteratorException(fr.lirmm.graphik.util.stream.IteratorException) HomomorphismFactoryException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismFactoryException) HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException)

Example 12 with HomomorphismException

use of fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException 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)

Example 13 with HomomorphismException

use of fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException in project graal by graphik-team.

the class UnionConjunctiveQueriesSubstitutionIterator method hasNext.

@Override
public boolean hasNext() throws IteratorException {
    if (!this.hasNextCallDone) {
        this.hasNextCallDone = true;
        if (this.tmpIt != null && !this.tmpIt.hasNext()) {
            this.tmpIt.close();
            this.tmpIt = null;
            this.getProfiler().stop("SubQuery" + i++);
        }
        while ((this.tmpIt == null || !this.tmpIt.hasNext()) && this.cqueryIterator.hasNext()) {
            ConjunctiveQuery q = this.cqueryIterator.next();
            this.getProfiler().start("SubQuery" + i);
            try {
                if (this.homomorphism == null) {
                    this.tmpIt = SmartHomomorphism.instance().execute(q, this.atomSet, this.compilation);
                } else {
                    if (this.compilation != null && !(this.compilation instanceof NoCompilation)) {
                        if (this.homomorphism instanceof HomomorphismWithCompilation) {
                            this.tmpIt = ((HomomorphismWithCompilation<ConjunctiveQuery, AtomSet>) this.homomorphism).execute(q, this.atomSet, this.compilation);
                        } else {
                            throw new IteratorException("There is a compilation and selected homomorphism can't handle it : " + this.homomorphism.getClass());
                        }
                    } else {
                        this.tmpIt = this.homomorphism.execute(q, this.atomSet);
                    }
                }
                if (this.isBooleanQuery && this.tmpIt.hasNext()) {
                    this.cqueryIterator.close();
                }
            } catch (HomomorphismException e) {
                return false;
            }
        }
    }
    return this.tmpIt != null && this.tmpIt.hasNext();
}
Also used : IteratorException(fr.lirmm.graphik.util.stream.IteratorException) NoCompilation(fr.lirmm.graphik.graal.core.compilation.NoCompilation) HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException) AtomSet(fr.lirmm.graphik.graal.api.core.AtomSet) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) HomomorphismWithCompilation(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismWithCompilation)

Example 14 with HomomorphismException

use of fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException in project graal by graphik-team.

the class AtomicQueryHomomorphism method execute.

@Override
public CloseableIterator<Substitution> execute(ConjunctiveQuery q, AtomSet a, RulesCompilation rc) throws HomomorphismException {
    try {
        List<CloseableIterator<Substitution>> iteratorsList = new LinkedList<CloseableIterator<Substitution>>();
        Atom atom = q.getAtomSet().iterator().next();
        for (Pair<Atom, Substitution> im : rc.getRewritingOf(atom)) {
            iteratorsList.add(new ConverterCloseableIterator<Atom, Substitution>(a.match(im.getLeft()), new Atom2SubstitutionConverter(im.getLeft(), q.getAnswerVariables(), im.getRight())));
        }
        return new CloseableIteratorAggregator<Substitution>(new CloseableIteratorAdapter<CloseableIterator<Substitution>>(iteratorsList.iterator()));
    } catch (AtomSetException e) {
        throw new HomomorphismException(e);
    }
}
Also used : ConverterCloseableIterator(fr.lirmm.graphik.util.stream.converter.ConverterCloseableIterator) CloseableIterator(fr.lirmm.graphik.util.stream.CloseableIterator) HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) CloseableIteratorAggregator(fr.lirmm.graphik.util.stream.CloseableIteratorAggregator) LinkedList(java.util.LinkedList) Atom(fr.lirmm.graphik.graal.api.core.Atom)

Example 15 with HomomorphismException

use of fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException in project graal by graphik-team.

the class AbstractHomomorphism method exist.

// /////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
// /////////////////////////////////////////////////////////////////////////
@Override
public boolean exist(T1 q, T2 a) throws HomomorphismException {
    CloseableIterator<Substitution> results = this.execute(q, a);
    boolean val;
    try {
        val = results.hasNext();
    } catch (IteratorException e) {
        throw new HomomorphismException(e);
    }
    results.close();
    return val;
}
Also used : IteratorException(fr.lirmm.graphik.util.stream.IteratorException) HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException) Substitution(fr.lirmm.graphik.graal.api.core.Substitution)

Aggregations

HomomorphismException (fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException)35 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)17 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)15 Atom (fr.lirmm.graphik.graal.api.core.Atom)14 IteratorException (fr.lirmm.graphik.util.stream.IteratorException)13 AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)11 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)8 Variable (fr.lirmm.graphik.graal.api.core.Variable)8 Term (fr.lirmm.graphik.graal.api.core.Term)7 LinkedListAtomSet (fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet)7 LinkedList (java.util.LinkedList)6 ChaseException (fr.lirmm.graphik.graal.api.forward_chaining.ChaseException)5 RuleApplicationException (fr.lirmm.graphik.graal.api.forward_chaining.RuleApplicationException)5 SubstitutionIterator2AtomIterator (fr.lirmm.graphik.graal.core.stream.SubstitutionIterator2AtomIterator)5 SqlHomomorphism (fr.lirmm.graphik.graal.store.rdbms.homomorphism.SqlHomomorphism)5 RuleSet (fr.lirmm.graphik.graal.api.core.RuleSet)4 HomomorphismFactoryException (fr.lirmm.graphik.graal.api.homomorphism.HomomorphismFactoryException)4 HashMapSubstitution (fr.lirmm.graphik.graal.core.HashMapSubstitution)4 LinkedListRuleSet (fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet)4 AnalyserRuleSet (fr.lirmm.graphik.graal.rulesetanalyser.util.AnalyserRuleSet)4