use of fr.lirmm.graphik.graal.api.core.Variable 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.Variable in project graal by graphik-team.
the class BacktrackIteratorData method preprocessing.
private void preprocessing(Set<Variable> variablesToParameterize, Profiler profiler) throws HomomorphismException {
profiler.start("preprocessingTime");
// Compute order on query variables and atoms
if (variablesToParameterize != null && !variablesToParameterize.isEmpty()) {
assert this.scheduler instanceof PatternScheduler;
PatternScheduler sched = (PatternScheduler) this.scheduler;
this.varsOrder = sched.execute(this.query, variablesToParameterize, ans, this.data, this.compilation);
} else {
this.varsOrder = this.scheduler.execute(this.query, ans, this.data, this.compilation);
}
this.levelMax = varsOrder.length - 2;
// PROFILING
if (profiler.isProfilingEnabled()) {
this.profilingVarOrder(this.varsOrder, profiler);
}
// Index Var structures by original variable object
this.index = new TreeMap<Variable, Integer>();
for (VarSharedData v : this.varsOrder) {
if (v.value != null) {
//
this.index.put(v.value, v.level);
}
}
if (this.ans.isEmpty()) {
this.varsOrder[this.levelMax + 1].previousLevel = -1;
}
computeAtomOrder(this.query, this.varsOrder, this.index);
this.fc.init(this.varsOrder, this.index);
this.bj.init(this.varsOrder);
Set<Variable> allVarsFromH = query.getVariables();
for (InMemoryAtomSet negPart : this.negParts) {
Set<Variable> frontier = SetUtils.intersection(allVarsFromH, negPart.getVariables());
this.varsOrder[maxLevel(frontier)].negatedPartsToCheck.add(BacktrackHomomorphismPattern.instance().prepareHomomorphism(new DefaultConjunctiveQuery(negPart, Collections.<Term>emptyList()), frontier, this.data, this.compilation));
}
profiler.stop("preprocessingTime");
}
Aggregations