Search in sources :

Example 6 with RuleApplicationException

use of fr.lirmm.graphik.graal.api.forward_chaining.RuleApplicationException 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 7 with RuleApplicationException

use of fr.lirmm.graphik.graal.api.forward_chaining.RuleApplicationException 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 8 with RuleApplicationException

use of fr.lirmm.graphik.graal.api.forward_chaining.RuleApplicationException in project graal by graphik-team.

the class StoreTest method bugConcurrentModificationException.

@Theory
public void bugConcurrentModificationException(InMemoryAtomSet store) throws IteratorException, RuleApplicationException, AtomSetException {
    Assume.assumeTrue(store instanceof Store);
    Rule r = DlgpParser.parseRule("<T>(Z,W), <P>(Y,W) :- <P>(X,Y).");
    store.addAll(DlgpParser.parseAtomSet("<P>(a,a)."));
    try {
        DefaultRuleApplier<InMemoryAtomSet> applier = new DefaultRuleApplier<InMemoryAtomSet>();
        applier.apply(r, store);
        applier.apply(r, store);
    } catch (Exception e) {
        Assert.fail();
    }
}
Also used : InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) RdbmsStore(fr.lirmm.graphik.graal.store.rdbms.RdbmsStore) Store(fr.lirmm.graphik.graal.api.store.Store) TripleStore(fr.lirmm.graphik.graal.api.store.TripleStore) Rule(fr.lirmm.graphik.graal.api.core.Rule) RuleApplicationException(fr.lirmm.graphik.graal.api.forward_chaining.RuleApplicationException) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) SQLException(java.sql.SQLException) HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException) ParseException(fr.lirmm.graphik.graal.api.io.ParseException) IteratorException(fr.lirmm.graphik.util.stream.IteratorException) DefaultRuleApplier(fr.lirmm.graphik.graal.forward_chaining.rule_applier.DefaultRuleApplier) Theory(org.junit.experimental.theories.Theory)

Aggregations

RuleApplicationException (fr.lirmm.graphik.graal.api.forward_chaining.RuleApplicationException)8 HomomorphismException (fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException)6 AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)5 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)5 IteratorException (fr.lirmm.graphik.util.stream.IteratorException)5 Atom (fr.lirmm.graphik.graal.api.core.Atom)4 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)3 Rule (fr.lirmm.graphik.graal.api.core.Rule)3 HomomorphismFactoryException (fr.lirmm.graphik.graal.api.homomorphism.HomomorphismFactoryException)3 ConjunctiveQueryWithNegatedParts (fr.lirmm.graphik.graal.api.core.ConjunctiveQueryWithNegatedParts)2 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)2 ChaseException (fr.lirmm.graphik.graal.api.forward_chaining.ChaseException)2 RuleWrapper2ConjunctiveQueryWithNegatedParts (fr.lirmm.graphik.graal.core.RuleWrapper2ConjunctiveQueryWithNegatedParts)2 SQLException (java.sql.SQLException)2 GraphOfRuleDependencies (fr.lirmm.graphik.graal.api.core.GraphOfRuleDependencies)1 Term (fr.lirmm.graphik.graal.api.core.Term)1 Variable (fr.lirmm.graphik.graal.api.core.Variable)1 AbstractChase (fr.lirmm.graphik.graal.api.forward_chaining.AbstractChase)1 Chase (fr.lirmm.graphik.graal.api.forward_chaining.Chase)1 ParseException (fr.lirmm.graphik.graal.api.io.ParseException)1