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 MFAProperty method check.
/**
*/
@Override
public int check(AnalyserRuleSet ruleSet) {
RuleSet R = translateToMFA(ruleSet);
AtomSet A = Rules.criticalInstance(ruleSet);
Chase chase = new ChaseWithGRD<AtomSet>(new DefaultGraphOfRuleDependencies(R), A, new DefaultRuleApplier<AtomSet>(new FrontierRestrictedChaseHaltingCondition()));
DefaultConjunctiveQuery Q = new DefaultConjunctiveQuery();
DefaultAtom q = new DefaultAtom(C);
q.setTerm(0, FAKE);
Q.getAtomSet().add(q);
try {
while (chase.hasNext()) {
chase.next();
if (SmartHomomorphism.instance().exist(Q, A)) {
return -1;
}
}
} catch (ChaseException e) {
LOGGER.warn("An error occurs during the chase: ", e);
return 0;
} catch (HomomorphismException e) {
LOGGER.warn("An error occurs during the homomorphism: ", e);
return 0;
}
return 1;
}
use of fr.lirmm.graphik.graal.api.forward_chaining.Chase in project graal by graphik-team.
the class ChaseTest method test1.
@Theory
public void test1(AtomSet atomSet) throws AtomSetException, HomomorphismFactoryException, HomomorphismException, ChaseException, IteratorException, ParseException {
atomSet.addAll(DlgpParser.parseAtomSet("<P>(X,a),<Q>(a,a)."));
LinkedList<Rule> ruleSet = new LinkedList<>();
ruleSet.add(DlgpParser.parseRule("<Q>(X,Y) :- <P>(X,Y)."));
Chase chase = new BreadthFirstChase(ruleSet, atomSet);
chase.execute();
ConjunctiveQuery query = DlgpParser.parseQuery("? :- <P>(X,Y),<Q>(X,Y).");
Assert.assertTrue(SmartHomomorphism.instance().execute(query, atomSet).hasNext());
}
use of fr.lirmm.graphik.graal.api.forward_chaining.Chase in project graal by graphik-team.
the class ChaseTest method restrictedChaseTest.
@Theory
public void restrictedChaseTest(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)."));
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)."));
Chase chase = new BreadthFirstChase(ruleSet, atomSet);
chase.execute();
int size = 0;
for (CloseableIterator<Atom> it = atomSet.iterator(); it.hasNext(); it.next()) {
++size;
}
Assert.assertEquals(4, size);
}
Aggregations