use of fr.lirmm.graphik.graal.api.forward_chaining.ChaseException in project graal by graphik-team.
the class BasicChase method next.
// /////////////////////////////////////////////////////////////////////////
// PUBLICS METHODS
// /////////////////////////////////////////////////////////////////////////
@Override
public void next() throws ChaseException {
try {
this.hasNext = false;
for (Rule rule : this.ruleSet) {
if (this.getProfiler().isProfilingEnabled()) {
this.getProfiler().start("saturationTime");
}
String key = null;
if (this.getProfiler().isProfilingEnabled()) {
key = "Rule " + rule.getLabel() + " application time";
this.getProfiler().clear(key);
this.getProfiler().trace(rule.toString());
this.getProfiler().start(key);
}
boolean val = this.getRuleApplier().apply(rule, this.atomSet);
this.hasNext = this.hasNext || val;
if (this.getProfiler().isProfilingEnabled()) {
this.getProfiler().stop(key);
}
if (this.getProfiler().isProfilingEnabled()) {
this.getProfiler().stop("saturationTime");
}
}
} catch (Exception e) {
throw new ChaseException("An error occured during saturation step.", e);
}
}
use of fr.lirmm.graphik.graal.api.forward_chaining.ChaseException in project graal by graphik-team.
the class BreadthFirstChase method next.
// /////////////////////////////////////////////////////////////////////////
// PUBLICS METHODS
// /////////////////////////////////////////////////////////////////////////
@Override
public void next() throws ChaseException {
this.rulesToCheck = this.nextRulesToCheck;
this.nextRulesToCheck = new TreeMap<Rule, AtomSet>();
try {
if (!this.rulesToCheck.isEmpty()) {
if (this.getProfiler().isProfilingEnabled()) {
this.getProfiler().start("saturationTime");
}
for (Entry<Rule, AtomSet> e : this.rulesToCheck.entrySet()) {
String key = null;
Rule rule = e.getKey();
AtomSet data = e.getValue();
if (this.getProfiler().isProfilingEnabled()) {
key = "Rule " + rule.getLabel() + " application time";
this.getProfiler().clear(key);
this.getProfiler().trace(rule.toString());
this.getProfiler().start(key);
}
CloseableIterator<Atom> it = this.getRuleApplier().delegatedApply(rule, data, this.atomSet);
while (it.hasNext()) {
tmpData.add(it.next());
}
it.close();
if (this.getProfiler().isProfilingEnabled()) {
this.getProfiler().stop(key);
}
}
this.dispatchNewData(this.tmpData);
this.atomSet.addAll(new CloseableIteratorAdapter<Atom>(this.tmpData.iterator()));
this.tmpData.clear();
if (this.getProfiler().isProfilingEnabled()) {
this.getProfiler().stop("saturationTime");
}
}
} catch (Exception e) {
throw new ChaseException("An error occured during saturation step.", e);
}
}
use of fr.lirmm.graphik.graal.api.forward_chaining.ChaseException in project graal by graphik-team.
the class ChaseWithGRD method next.
// /////////////////////////////////////////////////////////////////////////
// METHODS
// /////////////////////////////////////////////////////////////////////////
@Override
public void next() throws ChaseException {
Queue<Rule> newQueue = new LinkedList<Rule>();
List<Atom> newAtomSet = new LinkedList<Atom>();
try {
while (!queue.isEmpty()) {
Rule rule = queue.poll();
if (rule != null) {
CloseableIterator<Atom> it = this.getRuleApplier().delegatedApply(rule, this.atomSet);
if (it.hasNext()) {
while (it.hasNext()) {
newAtomSet.add(it.next());
}
for (Rule triggeredRule : this.grd.getTriggeredRules(rule)) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("-- -- Dependency: " + triggeredRule);
}
if (!newQueue.contains(triggeredRule)) {
newQueue.add(triggeredRule);
}
}
}
it.close();
}
}
queue = newQueue;
atomSet.addAll(new CloseableIteratorAdapter<Atom>(newAtomSet.iterator()));
} catch (Exception e) {
throw new ChaseException("An error occur pending saturation step.", e);
}
}
use of fr.lirmm.graphik.graal.api.forward_chaining.ChaseException in project graal by graphik-team.
the class SccChase method next.
// /////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
// /////////////////////////////////////////////////////////////////////////
@Override
public void next() throws ChaseException {
++this.level;
tmpAtom = new LinkedList<Atom>();
for (Integer scc : layers[level]) {
Set<Rule> component = this.sccg.getComponent(scc);
GraphOfRuleDependencies subGraph = this.grd.getSubGraph(component);
if (component.size() == 1 && !subGraph.hasCircuit()) {
try {
CloseableIterator<Atom> it = this.getRuleApplier().delegatedApply(component.iterator().next(), atomSet);
while (it.hasNext()) {
tmpAtom.add(it.next());
}
it.close();
} catch (RuleApplicationException e) {
throw new ChaseException("", e);
} catch (IteratorException e) {
throw new ChaseException("", e);
}
} else {
Chase chase = new ChaseWithGRD<T>(subGraph, atomSet, this.getRuleApplier());
chase.execute();
}
}
try {
atomSet.addAll(new CloseableIteratorAdapter<Atom>(tmpAtom.iterator()));
} catch (AtomSetException e) {
throw new ChaseException("", e);
}
}
use of fr.lirmm.graphik.graal.api.forward_chaining.ChaseException in project graal by graphik-team.
the class RdbmsStoreTest method SQLRuleApplierTest.
// /////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
// /////////////////////////////////////////////////////////////////////////
@Theory
public void SQLRuleApplierTest(RdbmsStore store) throws AtomSetException, IteratorException, ParseException {
RuleSet ruleSet = new LinkedListRuleSet();
ruleSet.add(DlgpParser.parseRule("<Q>(X,Y) :- <P>(X)."));
ruleSet.add(DlgpParser.parseRule("<R>(Y) :- <Q>(X,Y)."));
Atom a = DlgpParser.parseAtom("<P>(a).");
store.add(a);
Chase chase = new BasicChase<RdbmsStore>(ruleSet, store, new SQLRuleApplier(SqlHomomorphism.instance()));
try {
chase.execute();
} catch (ChaseException e) {
Assert.fail(e.getMessage());
}
CloseableIterator<Atom> it = store.iterator();
int count = Iterators.count(it);
Assert.assertEquals(3, count);
}
Aggregations