use of fr.lirmm.graphik.graal.api.core.AtomSetException in project graal by graphik-team.
the class BacktrackIterator method computeNext.
// /////////////////////////////////////////////////////////////////////////
// PRIVATE METHODS
// /////////////////////////////////////////////////////////////////////////
/**
* level < 0 : no more answers <br/>
* level 0 : not initialized
*/
private Substitution computeNext() throws BacktrackException {
if (profiler != null) {
profiler.start("backtrackingTime");
}
try {
if (level == 0) {
// check if the full instantiated atoms from the query are in data
if (BacktrackUtils.isHomomorphism(this.data.varsOrder[level].preAtoms, this.data.data, this.initialSubstitution, this.data.index, this.vars, this.data.compilation)) {
if (this.existNegParts()) {
this.data.bj.success();
backtrack(false);
} else {
++level;
}
} else {
--level;
}
}
while (level > 0) {
profiler.incr("#calls", 1);
if (level > this.data.levelMax) {
// Homomorphism found
Substitution sol = solutionFound(this.data.ans);
this.data.bj.success();
backtrack(false);
if (profiler != null) {
profiler.stop("backtrackingTime");
}
return sol;
} else {
if (goBack) {
if (hasMoreValues(currentVar(), this.data.data)) {
goBack = false;
++level;
} else {
backtrack(true);
}
} else {
if (getFirstValue(currentVar(), this.data.data)) {
++level;
} else {
backtrack(true);
}
}
}
}
} catch (AtomSetException e) {
throw new BacktrackException("Exception during backtracking", e);
}
--level;
if (profiler != null) {
profiler.stop("backtrackingTime");
}
return null;
}
use of fr.lirmm.graphik.graal.api.core.AtomSetException in project graal by graphik-team.
the class FullyInstantiatedQueryHomomorphism method execute.
// /////////////////////////////////////////////////////////////////////////
// HOMOMORPHISM METHODS
// /////////////////////////////////////////////////////////////////////////
public <U2 extends AtomSet> CloseableIterator<Substitution> execute(InMemoryAtomSet q, U2 a) throws HomomorphismException {
try {
CloseableIteratorWithoutException<Atom> it = q.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.core.AtomSetException 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.core.AtomSetException in project graal by graphik-team.
the class BreadthFirstChase method dispatchNewData.
// /////////////////////////////////////////////////////////////////////////
// PRIVATE CLASS
// /////////////////////////////////////////////////////////////////////////
protected void dispatchNewData(Collection<Atom> newData) throws ChaseException {
for (Atom a : newData) {
Predicate p = a.getPredicate();
for (Rule r : ruleSet.getRulesByBodyPredicate(p)) {
if (linearRuleCheck(r)) {
AtomSet set = nextRulesToCheck.get(r);
if (set == null) {
set = new DefaultInMemoryGraphStore();
nextRulesToCheck.put(r, set);
}
try {
set.add(a);
} catch (AtomSetException e) {
throw new ChaseException("Exception while adding data into a tmp store", e);
}
} else {
nextRulesToCheck.put(r, atomSet);
}
}
}
}
Aggregations