Search in sources :

Example 36 with IteratorException

use of fr.lirmm.graphik.util.stream.IteratorException in project graal by graphik-team.

the class RestrictedChaseRuleApplier method apply.

// /////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
// /////////////////////////////////////////////////////////////////////////
@Override
public boolean apply(Rule rule, T atomSet) throws RuleApplicationException {
    try {
        boolean res = false;
        ConjunctiveQueryWithNegatedParts query = new RuleWrapper2ConjunctiveQueryWithNegatedParts(rule);
        CloseableIterator<Substitution> results;
        results = SmartHomomorphism.instance().execute(query, atomSet);
        while (results.hasNext()) {
            res = true;
            Substitution proj = results.next();
            // replace variables by fresh symbol
            for (Variable t : rule.getExistentials()) {
                proj.put(t, atomSet.getFreshSymbolGenerator().getFreshSymbol());
            }
            CloseableIteratorWithoutException<Atom> it = proj.createImageOf(rule.getHead()).iterator();
            while (it.hasNext()) {
                atomSet.add(it.next());
            }
        }
        return res;
    } catch (HomomorphismException e) {
        throw new RuleApplicationException("", e);
    } catch (AtomSetException e) {
        throw new RuleApplicationException("", e);
    } catch (IteratorException e) {
        throw new RuleApplicationException("", e);
    }
}
Also used : IteratorException(fr.lirmm.graphik.util.stream.IteratorException) RuleWrapper2ConjunctiveQueryWithNegatedParts(fr.lirmm.graphik.graal.core.RuleWrapper2ConjunctiveQueryWithNegatedParts) RuleApplicationException(fr.lirmm.graphik.graal.api.forward_chaining.RuleApplicationException) Variable(fr.lirmm.graphik.graal.api.core.Variable) HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException) RuleWrapper2ConjunctiveQueryWithNegatedParts(fr.lirmm.graphik.graal.core.RuleWrapper2ConjunctiveQueryWithNegatedParts) ConjunctiveQueryWithNegatedParts(fr.lirmm.graphik.graal.api.core.ConjunctiveQueryWithNegatedParts) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) Atom(fr.lirmm.graphik.graal.api.core.Atom)

Example 37 with IteratorException

use of fr.lirmm.graphik.util.stream.IteratorException in project graal by graphik-team.

the class AbstractHomomorphismWithCompilation method exist.

@Override
public boolean exist(T1 q, T2 a, RulesCompilation compilation) throws HomomorphismException {
    CloseableIterator<Substitution> results = this.execute(q, a, compilation);
    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

IteratorException (fr.lirmm.graphik.util.stream.IteratorException)37 AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)24 Atom (fr.lirmm.graphik.graal.api.core.Atom)16 Term (fr.lirmm.graphik.graal.api.core.Term)14 HomomorphismException (fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException)14 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)13 Predicate (fr.lirmm.graphik.graal.api.core.Predicate)9 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)8 TreeSet (java.util.TreeSet)8 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)7 BacktrackException (fr.lirmm.graphik.graal.homomorphism.BacktrackException)6 CloseableIteratorAdapter (fr.lirmm.graphik.util.stream.CloseableIteratorAdapter)6 RuleApplicationException (fr.lirmm.graphik.graal.api.forward_chaining.RuleApplicationException)5 Variable (fr.lirmm.graphik.graal.api.core.Variable)4 SQLException (java.sql.SQLException)4 AtomSet (fr.lirmm.graphik.graal.api.core.AtomSet)3 Rule (fr.lirmm.graphik.graal.api.core.Rule)3 HomomorphismFactoryException (fr.lirmm.graphik.graal.api.homomorphism.HomomorphismFactoryException)3 DBTable (fr.lirmm.graphik.graal.store.rdbms.util.DBTable)3 SQLQuery (fr.lirmm.graphik.graal.store.rdbms.util.SQLQuery)3