use of fr.lirmm.graphik.graal.api.core.GraphOfRuleDependencies in project graal by graphik-team.
the class DefaultKnowledgeBase method fesSaturate.
// /////////////////////////////////////////////////////////////////////////
// PRIVATE METHODS
// /////////////////////////////////////////////////////////////////////////
/**
* Run saturation with a timeout at <code>timeout</code> milliseconds for this thread to die. A timeout of 0 means to wait forever.
* @param timeout in milliseconds
* @throws ChaseException
* @throws TimeoutException
*/
protected void fesSaturate(long timeout) throws ChaseException, TimeoutException {
if (!isFESSaturated) {
GraphOfRuleDependencies grd = this.getFESGraphOfRuleDependencies();
ChaseWithGRD<AtomSet> chase = new ChaseWithGRD<>(grd, this.store);
chase.setProfiler(this.getProfiler());
chase.execute(timeout);
this.isFESSaturated = true;
}
}
use of fr.lirmm.graphik.graal.api.core.GraphOfRuleDependencies 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.GraphOfRuleDependencies in project graal by graphik-team.
the class ChaseTest method restrictedChaseTestWithGrd.
@Theory
public void restrictedChaseTestWithGrd(InMemoryAtomSet atomSet) throws IOException, ChaseException, ParseException, AtomSetException, IteratorException {
atomSet.addAll(DlgpParser.parseAtomSet("<P>(a,a)."));
LinkedList<Rule> ruleSet = new LinkedList<>();
ruleSet.add(DlgpParser.parseRule("<Q>(X,Z) :- <P>(X,X)."));
ruleSet.add(DlgpParser.parseRule("<R>(X,Z) :- <Q>(X,Y)."));
ruleSet.add(DlgpParser.parseRule("<Q>(X,Z) :- <R>(X,Y)."));
ruleSet.add(DlgpParser.parseRule("<S>(X,X) :- <Q>(Y,X)."));
GraphOfRuleDependencies grd = new DefaultGraphOfRuleDependencies(ruleSet);
Chase chase = new ChaseWithGRDAndUnfiers<AtomSet>(grd, atomSet);
chase.execute();
int size = 0;
for (CloseableIterator<Atom> it = atomSet.iterator(); it.hasNext(); it.next()) {
++size;
}
Assert.assertEquals(4, size);
}
use of fr.lirmm.graphik.graal.api.core.GraphOfRuleDependencies in project graal by graphik-team.
the class DefaultKnowledgeBase method saturate.
@Override
public void saturate() throws KnowledgeBaseException {
if (!this.isSaturated) {
boolean run = this.approach == Approach.SATURATION_ONLY;
if (!run) {
this.analyse();
run = this.analyse.isFES();
}
if (run) {
GraphOfRuleDependencies grd = this.analysedRuleSet.getGraphOfRuleDependencies();
ChaseWithGRD<AtomSet> chase = new ChaseWithGRD<>(grd, this.store);
chase.setProfiler(this.getProfiler());
try {
chase.execute();
} catch (ChaseException e) {
throw new KnowledgeBaseException(e);
}
this.isSaturated = true;
this.isFESSaturated = true;
this.isSemiSaturated = true;
} else {
throw new KnowledgeBaseException("There is no proof for FES decidability");
}
}
}
Aggregations