use of fr.lirmm.graphik.graal.api.forward_chaining.Chase 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.Chase in project graal by graphik-team.
the class StaticChase method executeChase.
public static void executeChase(AtomSet atomSet, DefaultGraphOfRuleDependencies grd) throws ChaseException {
Chase chase = new SccChase<AtomSet>(grd, atomSet);
chase.execute();
}
use of fr.lirmm.graphik.graal.api.forward_chaining.Chase in project graal by graphik-team.
the class StaticChase method executeOneStepChase.
public static void executeOneStepChase(AtomSet atomSet, DefaultGraphOfRuleDependencies grd) throws ChaseException {
Chase chase = new SccChase<AtomSet>(grd, atomSet);
chase.next();
}
use of fr.lirmm.graphik.graal.api.forward_chaining.Chase in project graal by graphik-team.
the class ChaseTest method test.
@Test
public void test() throws ParseException, ChaseException {
Ontology onto = new DefaultOntology();
onto.add(DlgpParser.parseRule("p(X) :- q(X)."));
onto.add(DlgpParser.parseRule("q(X) :- p(X)."));
InMemoryAtomSet store = new DefaultInMemoryGraphStore();
store.add(DlgpParser.parseAtom("p(a)."));
Chase chase = new BreadthFirstChase(onto, store);
Assert.assertTrue(chase.hasNext());
chase.next();
Assert.assertTrue(chase.hasNext());
chase.next();
Assert.assertFalse(chase.hasNext());
}
use of fr.lirmm.graphik.graal.api.forward_chaining.Chase in project graal by graphik-team.
the class ChaseTest method restrictedChaseTest0.
@Theory
public void restrictedChaseTest0(AtomSet atomSet) throws AtomSetException, HomomorphismFactoryException, HomomorphismException, ChaseException, IteratorException, ParseException {
atomSet.addAll(DlgpParser.parseAtomSet("<P>(a,a)."));
LinkedList<Rule> ruleSet = new LinkedList<>();
ruleSet.add(DlgpParser.parseRule("<Q>(X,Z) :- <P>(X,X)."));
Chase chase = new BreadthFirstChase(ruleSet, atomSet);
chase.execute();
int size = 0;
for (CloseableIterator<Atom> it = atomSet.iterator(); it.hasNext(); it.next()) {
++size;
}
Assert.assertEquals(2, size);
}
Aggregations