Search in sources :

Example 1 with ConjunctiveQueryWithNegatedParts

use of fr.lirmm.graphik.graal.api.core.ConjunctiveQueryWithNegatedParts 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 2 with ConjunctiveQueryWithNegatedParts

use of fr.lirmm.graphik.graal.api.core.ConjunctiveQueryWithNegatedParts in project graal by graphik-team.

the class RestrictedChaseRuleApplier method delegatedApply.

@Override
public CloseableIterator<Atom> delegatedApply(Rule rule, T atomSet) throws RuleApplicationException {
    try {
        ConjunctiveQueryWithNegatedParts query = new RuleWrapper2ConjunctiveQueryWithNegatedParts(rule);
        CloseableIterator<Substitution> results = SmartHomomorphism.instance().execute(query, atomSet);
        return new RuleApplierIterator(results, rule, atomSet);
    } catch (HomomorphismException e) {
        throw new RuleApplicationException("", e);
    }
}
Also used : RuleWrapper2ConjunctiveQueryWithNegatedParts(fr.lirmm.graphik.graal.core.RuleWrapper2ConjunctiveQueryWithNegatedParts) RuleApplicationException(fr.lirmm.graphik.graal.api.forward_chaining.RuleApplicationException) 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)

Aggregations

ConjunctiveQueryWithNegatedParts (fr.lirmm.graphik.graal.api.core.ConjunctiveQueryWithNegatedParts)2 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)2 RuleApplicationException (fr.lirmm.graphik.graal.api.forward_chaining.RuleApplicationException)2 HomomorphismException (fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException)2 RuleWrapper2ConjunctiveQueryWithNegatedParts (fr.lirmm.graphik.graal.core.RuleWrapper2ConjunctiveQueryWithNegatedParts)2 Atom (fr.lirmm.graphik.graal.api.core.Atom)1 AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)1 Variable (fr.lirmm.graphik.graal.api.core.Variable)1 IteratorException (fr.lirmm.graphik.util.stream.IteratorException)1