Search in sources :

Example 31 with HomomorphismException

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

the class RecursiveBacktrackHomomorphism method exist.

@Override
public boolean exist(ConjunctiveQuery query, AtomSet data) throws HomomorphismException {
    try {
        InMemoryAtomSet atomSet1 = query.getAtomSet();
        List<Variable> orderedVars = order(atomSet1.getVariables());
        Collection<Atom>[] queryAtomRanked = getAtomRank(atomSet1, orderedVars);
        if (isHomomorphism(queryAtomRanked[0], data, new HashMapSubstitution())) {
            return existHomomorphism(atomSet1, queryAtomRanked, data, new HashMapSubstitution(), orderedVars, 1);
        } else {
            return false;
        }
    } 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) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) Collection(java.util.Collection) 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)

Example 32 with HomomorphismException

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

the class RestrictedChaseHaltingCondition method apply.

@Override
public CloseableIterator<Atom> apply(Rule rule, Substitution substitution, AtomSet data) throws HomomorphismFactoryException, HomomorphismException {
    InMemoryAtomSet newFacts = substitution.createImageOf(rule.getHead());
    ConjunctiveQuery query = new ConjunctiveQueryWithFixedVariables(newFacts, substitution.createImageOf(rule.getFrontier()));
    try {
        if (SmartHomomorphism.instance().execute(query, data).hasNext()) {
            return new CloseableIteratorAdapter<Atom>(Collections.<Atom>emptyList().iterator());
        }
    } catch (IteratorException e) {
        throw new HomomorphismException("An errors occurs while iterating results", e);
    } catch (BacktrackException e) {
        throw new HomomorphismException("An errors occurs while iterating results", e);
    }
    // replace variables by fresh symbol
    for (Variable t : rule.getExistentials()) {
        substitution.put(t, data.getFreshSymbolGenerator().getFreshSymbol());
    }
    CloseableIteratorWithoutException<Atom> it = substitution.createImageOf(rule.getHead()).iterator();
    return it;
}
Also used : IteratorException(fr.lirmm.graphik.util.stream.IteratorException) HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException) Variable(fr.lirmm.graphik.graal.api.core.Variable) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) CloseableIteratorAdapter(fr.lirmm.graphik.util.stream.CloseableIteratorAdapter) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) ConjunctiveQueryWithFixedVariables(fr.lirmm.graphik.graal.core.ConjunctiveQueryWithFixedVariables) Atom(fr.lirmm.graphik.graal.api.core.Atom) BacktrackException(fr.lirmm.graphik.graal.homomorphism.BacktrackException)

Example 33 with HomomorphismException

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

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

Example 35 with HomomorphismException

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

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