Search in sources :

Example 6 with Chase

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();
}
Also used : Chase(fr.lirmm.graphik.graal.api.forward_chaining.Chase)

Example 7 with Chase

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());
}
Also used : Ontology(fr.lirmm.graphik.graal.api.core.Ontology) DefaultOntology(fr.lirmm.graphik.graal.core.ruleset.DefaultOntology) BreadthFirstChase(fr.lirmm.graphik.graal.forward_chaining.BreadthFirstChase) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) DefaultInMemoryGraphStore(fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore) DefaultOntology(fr.lirmm.graphik.graal.core.ruleset.DefaultOntology) Chase(fr.lirmm.graphik.graal.api.forward_chaining.Chase) BreadthFirstChase(fr.lirmm.graphik.graal.forward_chaining.BreadthFirstChase) Test(org.junit.Test)

Example 8 with Chase

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;
}
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)

Example 9 with Chase

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

Example 10 with Chase

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);
}
Also used : Rule(fr.lirmm.graphik.graal.api.core.Rule) 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)

Aggregations

Chase (fr.lirmm.graphik.graal.api.forward_chaining.Chase)14 Atom (fr.lirmm.graphik.graal.api.core.Atom)5 Rule (fr.lirmm.graphik.graal.api.core.Rule)5 Theory (org.junit.experimental.theories.Theory)5 ChaseException (fr.lirmm.graphik.graal.api.forward_chaining.ChaseException)4 LinkedList (java.util.LinkedList)4 DefaultGraphOfRuleDependencies (fr.lirmm.graphik.graal.core.grd.DefaultGraphOfRuleDependencies)3 GraphOfRuleDependencies (fr.lirmm.graphik.graal.api.core.GraphOfRuleDependencies)2 RuleSet (fr.lirmm.graphik.graal.api.core.RuleSet)2 LinkedListRuleSet (fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet)2 BreadthFirstChase (fr.lirmm.graphik.graal.forward_chaining.BreadthFirstChase)2 AtomSet (fr.lirmm.graphik.graal.api.core.AtomSet)1 AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)1 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)1 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)1 Ontology (fr.lirmm.graphik.graal.api.core.Ontology)1 AbstractChase (fr.lirmm.graphik.graal.api.forward_chaining.AbstractChase)1 RuleApplicationException (fr.lirmm.graphik.graal.api.forward_chaining.RuleApplicationException)1 HomomorphismException (fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException)1 KnowledgeBaseException (fr.lirmm.graphik.graal.api.kb.KnowledgeBaseException)1