Search in sources :

Example 26 with HomomorphismException

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

the class AbstractRuleApplier method apply.

@Override
public boolean apply(Rule rule, T atomSet) throws RuleApplicationException {
    boolean isChanged = false;
    ConjunctiveQuery query = this.generateQuery(rule);
    try {
        CloseableIterator<Substitution> subIt = this.executeQuery(query, atomSet);
        while (subIt.hasNext()) {
            Substitution substitution = subIt.next();
            CloseableIterator<Atom> it = this.getHaltingCondition().apply(rule, substitution, atomSet);
            if (it.hasNext()) {
                atomSet.addAll(it);
                isChanged = true;
            }
        }
        subIt.close();
    } catch (HomomorphismFactoryException e) {
        throw new RuleApplicationException("Error during rule application", e);
    } catch (HomomorphismException e) {
        throw new RuleApplicationException("Error during rule application", e);
    } catch (AtomSetException e) {
        throw new RuleApplicationException("Error during rule application", e);
    } catch (IteratorException e) {
        throw new RuleApplicationException("Error during rule application", e);
    }
    return isChanged;
}
Also used : IteratorException(fr.lirmm.graphik.util.stream.IteratorException) RuleApplicationException(fr.lirmm.graphik.graal.api.forward_chaining.RuleApplicationException) HomomorphismFactoryException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismFactoryException) HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) Atom(fr.lirmm.graphik.graal.api.core.Atom)

Example 27 with HomomorphismException

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

the class AbstractRuleApplier method delegatedApply.

@Override
public CloseableIterator<Atom> delegatedApply(Rule rule, T atomSetOnWichQuerying, T atomSetOnWichCheck) throws RuleApplicationException {
    ConjunctiveQuery query = this.generateQuery(rule);
    CloseableIterator<Substitution> subIt;
    try {
        subIt = this.executeQuery(query, atomSetOnWichQuerying);
    } catch (HomomorphismFactoryException e) {
        throw new RuleApplicationException("Error during rule application", e);
    } catch (HomomorphismException e) {
        throw new RuleApplicationException("Error during rule application", e);
    }
    return new RuleApplierIterator(subIt, rule, atomSetOnWichCheck, haltingCondition);
}
Also used : RuleApplicationException(fr.lirmm.graphik.graal.api.forward_chaining.RuleApplicationException) HomomorphismFactoryException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismFactoryException) HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)

Example 28 with HomomorphismException

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

the class FullyInstantiatedQueryHomomorphism method execute.

// /////////////////////////////////////////////////////////////////////////
// HOMOMORPHISM METHODS
// /////////////////////////////////////////////////////////////////////////
public <U2 extends AtomSet> CloseableIterator<Substitution> execute(InMemoryAtomSet q, U2 a) throws HomomorphismException {
    try {
        CloseableIteratorWithoutException<Atom> it = q.iterator();
        boolean contains = true;
        while (contains && it.hasNext()) {
            contains = a.contains(it.next());
        }
        if (contains) {
            return Iterators.singletonIterator(Substitutions.emptySubstitution());
        } else {
            return Iterators.emptyIterator();
        }
    } catch (AtomSetException e) {
        throw new HomomorphismException(e);
    }
}
Also used : HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) Atom(fr.lirmm.graphik.graal.api.core.Atom)

Example 29 with HomomorphismException

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

the class PreparedBacktrackHomomorphism method exist.

// /////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
// /////////////////////////////////////////////////////////////////////////
@Override
public boolean exist(Substitution s) throws HomomorphismException {
    CloseableIterator<Substitution> results = this.execute(s);
    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)

Example 30 with HomomorphismException

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

the class DefaultUCQHomomorphismWithCompilation method exist.

@Override
public boolean exist(UnionOfConjunctiveQueries q, AtomSet a, RulesCompilation compilation) throws HomomorphismException {
    try {
        CloseableIterator<Substitution> execute = this.execute(q, a, compilation);
        boolean res = execute.hasNext();
        execute.close();
        return res;
    } catch (IteratorException e) {
        throw new HomomorphismException(e);
    }
}
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