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);
}
}
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;
}
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);
}
}
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);
}
}
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;
}
Aggregations