use of fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException in project graal by graphik-team.
the class FrontierRestrictedChaseHaltingCondition method apply.
@Override
public CloseableIterator<Atom> apply(Rule rule, Substitution substitution, AtomSet data) throws HomomorphismFactoryException, HomomorphismException {
Set<Term> fixedVars = substitution.getValues();
if (ruleIndex.get(rule) == null) {
ruleIndex.put(rule, _currentRuleIndex++);
}
final int index = ruleIndex.get(rule).intValue();
StringBuilder frontierSb = new StringBuilder();
SortedSet<Variable> frontierSet = new TreeSet<Variable>(rule.getFrontier());
for (Term t : frontierSet) {
frontierSb.append("_");
frontierSb.append(t.getLabel());
frontierSb.append(substitution.createImageOf(t).getLabel());
}
String frontier = frontierSb.toString();
for (Variable t : rule.getExistentials()) {
substitution.put(t, DefaultTermFactory.instance().createConstant("f_" + index + "_" + t.getIdentifier() + frontier));
}
InMemoryAtomSet newFacts = substitution.createImageOf(rule.getHead());
ConjunctiveQuery query = new ConjunctiveQueryWithFixedVariables(newFacts, fixedVars);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Fixed Query:" + query);
}
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);
}
return newFacts.iterator();
}
use of fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException in project graal by graphik-team.
the class BacktrackIterator method existNegParts.
private boolean existNegParts() throws BacktrackException {
Substitution s = currentSubstitution(this.vars);
s.put(initialSubstitution);
for (PreparedExistentialHomomorphism negPart : this.currentVar().shared.negatedPartsToCheck) {
try {
if (negPart.exist(s)) {
this.data.bj.success();
return true;
}
} catch (HomomorphismException e) {
throw new BacktrackException("Error while checking anegated part: ", e);
}
}
return false;
}
use of fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException in project graal by graphik-team.
the class DefaultUCQHomomorphism method exist.
@Override
public boolean exist(UnionOfConjunctiveQueries q, AtomSet a) throws HomomorphismException {
try {
CloseableIterator<Substitution> execute = this.execute(q, a);
boolean res = execute.hasNext();
execute.close();
return res;
} catch (IteratorException e) {
throw new HomomorphismException(e);
}
}
use of fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException in project graal by graphik-team.
the class FullyInstantiatedQueryHomomorphism method execute.
@Override
public CloseableIterator<Substitution> execute(ConjunctiveQuery q, AtomSet a) throws HomomorphismException {
try {
CloseableIteratorWithoutException<Atom> it = q.getAtomSet().iterator();
boolean contains = true;
while (contains && it.hasNext()) {
contains = a.contains(it.next());
}
if (contains) {
return Iterators.singletonIterator(Substitutions.emptySubstitution());
} else {
return Iterators.emptyIterator();
}
} catch (AtomSetException e) {
throw new HomomorphismException(e);
}
}
use of fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException in project graal by graphik-team.
the class FullyInstantiatedQueryHomomorphism method execute.
@Override
public CloseableIterator<Substitution> execute(ConjunctiveQuery q, AtomSet a, RulesCompilation rc) throws HomomorphismException {
try {
CloseableIteratorWithoutException<Atom> it = q.getAtomSet().iterator();
boolean contains = true;
while (contains && it.hasNext()) {
Atom atom = it.next();
boolean containsAtom = false;
for (Pair<Atom, Substitution> im : rc.getRewritingOf(atom)) {
containsAtom = a.contains(im.getLeft());
if (containsAtom) {
break;
}
}
contains = containsAtom;
}
if (contains) {
return Iterators.singletonIterator(Substitutions.emptySubstitution());
} else {
return Iterators.emptyIterator();
}
} catch (AtomSetException e) {
throw new HomomorphismException(e);
}
}
Aggregations