Search in sources :

Example 1 with DefaultGraphOfRuleDependencies

use of fr.lirmm.graphik.graal.core.grd.DefaultGraphOfRuleDependencies 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);
}
Also used : DefaultGraphOfRuleDependencies(fr.lirmm.graphik.graal.core.grd.DefaultGraphOfRuleDependencies) Rule(fr.lirmm.graphik.graal.api.core.Rule) GraphOfRuleDependencies(fr.lirmm.graphik.graal.api.core.GraphOfRuleDependencies) DefaultGraphOfRuleDependencies(fr.lirmm.graphik.graal.core.grd.DefaultGraphOfRuleDependencies) LinkedList(java.util.LinkedList) Chase(fr.lirmm.graphik.graal.api.forward_chaining.Chase) Atom(fr.lirmm.graphik.graal.api.core.Atom) Theory(org.junit.experimental.theories.Theory)

Example 2 with DefaultGraphOfRuleDependencies

use of fr.lirmm.graphik.graal.core.grd.DefaultGraphOfRuleDependencies in project graal by graphik-team.

the class DefaultKnowledgeBase method getFESGraphOfRuleDependencies.

protected GraphOfRuleDependencies getFESGraphOfRuleDependencies() {
    if (this.fesGRD == null) {
        RuleSet fesRuleSet = this.getFESRuleSet();
        this.fesGRD = new DefaultGraphOfRuleDependencies(fesRuleSet);
    }
    return this.fesGRD;
}
Also used : AnalyserRuleSet(fr.lirmm.graphik.graal.rulesetanalyser.util.AnalyserRuleSet) RuleSet(fr.lirmm.graphik.graal.api.core.RuleSet) LinkedListRuleSet(fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet) DefaultGraphOfRuleDependencies(fr.lirmm.graphik.graal.core.grd.DefaultGraphOfRuleDependencies)

Example 3 with DefaultGraphOfRuleDependencies

use of fr.lirmm.graphik.graal.core.grd.DefaultGraphOfRuleDependencies 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;
}
Also used : AnalyserRuleSet(fr.lirmm.graphik.graal.rulesetanalyser.util.AnalyserRuleSet) RuleSet(fr.lirmm.graphik.graal.api.core.RuleSet) LinkedListRuleSet(fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet) DefaultConjunctiveQuery(fr.lirmm.graphik.graal.core.DefaultConjunctiveQuery) FrontierRestrictedChaseHaltingCondition(fr.lirmm.graphik.graal.forward_chaining.halting_condition.FrontierRestrictedChaseHaltingCondition) HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException) DefaultGraphOfRuleDependencies(fr.lirmm.graphik.graal.core.grd.DefaultGraphOfRuleDependencies) AtomSet(fr.lirmm.graphik.graal.api.core.AtomSet) DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) ChaseWithGRD(fr.lirmm.graphik.graal.forward_chaining.ChaseWithGRD) ChaseException(fr.lirmm.graphik.graal.api.forward_chaining.ChaseException) Chase(fr.lirmm.graphik.graal.api.forward_chaining.Chase)

Aggregations

DefaultGraphOfRuleDependencies (fr.lirmm.graphik.graal.core.grd.DefaultGraphOfRuleDependencies)3 RuleSet (fr.lirmm.graphik.graal.api.core.RuleSet)2 Chase (fr.lirmm.graphik.graal.api.forward_chaining.Chase)2 LinkedListRuleSet (fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet)2 AnalyserRuleSet (fr.lirmm.graphik.graal.rulesetanalyser.util.AnalyserRuleSet)2 Atom (fr.lirmm.graphik.graal.api.core.Atom)1 AtomSet (fr.lirmm.graphik.graal.api.core.AtomSet)1 GraphOfRuleDependencies (fr.lirmm.graphik.graal.api.core.GraphOfRuleDependencies)1 Rule (fr.lirmm.graphik.graal.api.core.Rule)1 ChaseException (fr.lirmm.graphik.graal.api.forward_chaining.ChaseException)1 HomomorphismException (fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException)1 DefaultAtom (fr.lirmm.graphik.graal.core.DefaultAtom)1 DefaultConjunctiveQuery (fr.lirmm.graphik.graal.core.DefaultConjunctiveQuery)1 ChaseWithGRD (fr.lirmm.graphik.graal.forward_chaining.ChaseWithGRD)1 FrontierRestrictedChaseHaltingCondition (fr.lirmm.graphik.graal.forward_chaining.halting_condition.FrontierRestrictedChaseHaltingCondition)1 LinkedList (java.util.LinkedList)1 Theory (org.junit.experimental.theories.Theory)1