use of fr.lirmm.graphik.graal.api.core.Rule 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.core.Rule 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.core.Rule 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.core.Rule in project graal by graphik-team.
the class DefaultOntologyTest method testIterator_empty.
/**
* Test method for
* {@link fr.lirmm.graphik.graal.core.ruleset.DefaultOntology#iterator()}.
*/
@Test
public void testIterator_empty() {
// given
Ontology onto = new DefaultOntology();
// when
Iterator<Rule> it = onto.iterator();
// then
Assert.assertFalse(it.hasNext());
}
use of fr.lirmm.graphik.graal.api.core.Rule in project graal by graphik-team.
the class DefaultOntologyTest method testIterator.
/**
* Test method for
* {@link fr.lirmm.graphik.graal.core.ruleset.DefaultOntology#iterator()}.
*/
@Test
public void testIterator() {
boolean isThereR1 = false;
boolean isThereNoName = false;
// given
Ontology onto = new DefaultOntology();
onto.add(r1);
onto.add(noName);
// when
Iterator<Rule> it = onto.iterator();
while (it.hasNext()) {
Rule r = it.next();
if (r == r1 && !isThereR1) {
isThereR1 = true;
} else if (r == noName && !isThereNoName) {
isThereNoName = true;
} else {
fail("Not wanted rule: " + r);
}
}
// then
Assert.assertTrue("isThereR1", isThereR1);
Assert.assertTrue("isThereNoName", isThereNoName);
}
Aggregations