Search in sources :

Example 1 with GraphOfRuleDependencies

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;
    }
}
Also used : AtomSet(fr.lirmm.graphik.graal.api.core.AtomSet) ChaseWithGRD(fr.lirmm.graphik.graal.forward_chaining.ChaseWithGRD) GraphOfRuleDependencies(fr.lirmm.graphik.graal.api.core.GraphOfRuleDependencies) DefaultGraphOfRuleDependencies(fr.lirmm.graphik.graal.core.grd.DefaultGraphOfRuleDependencies)

Example 2 with GraphOfRuleDependencies

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);
    }
}
Also used : IteratorException(fr.lirmm.graphik.util.stream.IteratorException) RuleApplicationException(fr.lirmm.graphik.graal.api.forward_chaining.RuleApplicationException) ChaseException(fr.lirmm.graphik.graal.api.forward_chaining.ChaseException) Atom(fr.lirmm.graphik.graal.api.core.Atom) Chase(fr.lirmm.graphik.graal.api.forward_chaining.Chase) AbstractChase(fr.lirmm.graphik.graal.api.forward_chaining.AbstractChase) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) Rule(fr.lirmm.graphik.graal.api.core.Rule) DefaultGraphOfRuleDependencies(fr.lirmm.graphik.graal.core.grd.DefaultGraphOfRuleDependencies) GraphOfRuleDependencies(fr.lirmm.graphik.graal.api.core.GraphOfRuleDependencies)

Example 3 with GraphOfRuleDependencies

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);
}
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 4 with GraphOfRuleDependencies

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");
        }
    }
}
Also used : AtomSet(fr.lirmm.graphik.graal.api.core.AtomSet) ChaseWithGRD(fr.lirmm.graphik.graal.forward_chaining.ChaseWithGRD) KnowledgeBaseException(fr.lirmm.graphik.graal.api.kb.KnowledgeBaseException) GraphOfRuleDependencies(fr.lirmm.graphik.graal.api.core.GraphOfRuleDependencies) DefaultGraphOfRuleDependencies(fr.lirmm.graphik.graal.core.grd.DefaultGraphOfRuleDependencies) ChaseException(fr.lirmm.graphik.graal.api.forward_chaining.ChaseException)

Aggregations

GraphOfRuleDependencies (fr.lirmm.graphik.graal.api.core.GraphOfRuleDependencies)4 DefaultGraphOfRuleDependencies (fr.lirmm.graphik.graal.core.grd.DefaultGraphOfRuleDependencies)4 Atom (fr.lirmm.graphik.graal.api.core.Atom)2 AtomSet (fr.lirmm.graphik.graal.api.core.AtomSet)2 Rule (fr.lirmm.graphik.graal.api.core.Rule)2 Chase (fr.lirmm.graphik.graal.api.forward_chaining.Chase)2 ChaseException (fr.lirmm.graphik.graal.api.forward_chaining.ChaseException)2 ChaseWithGRD (fr.lirmm.graphik.graal.forward_chaining.ChaseWithGRD)2 AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)1 AbstractChase (fr.lirmm.graphik.graal.api.forward_chaining.AbstractChase)1 RuleApplicationException (fr.lirmm.graphik.graal.api.forward_chaining.RuleApplicationException)1 KnowledgeBaseException (fr.lirmm.graphik.graal.api.kb.KnowledgeBaseException)1 IteratorException (fr.lirmm.graphik.util.stream.IteratorException)1 LinkedList (java.util.LinkedList)1 Theory (org.junit.experimental.theories.Theory)1