Search in sources :

Example 51 with Rule

use of fr.lirmm.graphik.graal.api.core.Rule in project graal by graphik-team.

the class BreadthFirstChase method next.

// /////////////////////////////////////////////////////////////////////////
// PUBLICS METHODS
// /////////////////////////////////////////////////////////////////////////
@Override
public void next() throws ChaseException {
    this.rulesToCheck = this.nextRulesToCheck;
    this.nextRulesToCheck = new TreeMap<Rule, AtomSet>();
    try {
        if (!this.rulesToCheck.isEmpty()) {
            if (this.getProfiler().isProfilingEnabled()) {
                this.getProfiler().start("saturationTime");
            }
            for (Entry<Rule, AtomSet> e : this.rulesToCheck.entrySet()) {
                String key = null;
                Rule rule = e.getKey();
                AtomSet data = e.getValue();
                if (this.getProfiler().isProfilingEnabled()) {
                    key = "Rule " + rule.getLabel() + " application time";
                    this.getProfiler().clear(key);
                    this.getProfiler().trace(rule.toString());
                    this.getProfiler().start(key);
                }
                CloseableIterator<Atom> it = this.getRuleApplier().delegatedApply(rule, data, this.atomSet);
                while (it.hasNext()) {
                    tmpData.add(it.next());
                }
                it.close();
                if (this.getProfiler().isProfilingEnabled()) {
                    this.getProfiler().stop(key);
                }
            }
            this.dispatchNewData(this.tmpData);
            this.atomSet.addAll(new CloseableIteratorAdapter<Atom>(this.tmpData.iterator()));
            this.tmpData.clear();
            if (this.getProfiler().isProfilingEnabled()) {
                this.getProfiler().stop("saturationTime");
            }
        }
    } catch (Exception e) {
        throw new ChaseException("An error occured during saturation step.", e);
    }
}
Also used : AtomSet(fr.lirmm.graphik.graal.api.core.AtomSet) Rule(fr.lirmm.graphik.graal.api.core.Rule) ChaseException(fr.lirmm.graphik.graal.api.forward_chaining.ChaseException) Atom(fr.lirmm.graphik.graal.api.core.Atom) ChaseException(fr.lirmm.graphik.graal.api.forward_chaining.ChaseException) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) CloseableIteratorWithoutException(fr.lirmm.graphik.util.stream.CloseableIteratorWithoutException)

Example 52 with Rule

use of fr.lirmm.graphik.graal.api.core.Rule in project graal by graphik-team.

the class BreadthFirstChase method init.

private void init(Iterator<Rule> rules) {
    this.nextRulesToCheck = new TreeMap<Rule, AtomSet>();
    while (rules.hasNext()) {
        Rule r = rules.next();
        this.ruleSet.add(r);
        this.nextRulesToCheck.put(r, atomSet);
    }
}
Also used : AtomSet(fr.lirmm.graphik.graal.api.core.AtomSet) Rule(fr.lirmm.graphik.graal.api.core.Rule)

Example 53 with Rule

use of fr.lirmm.graphik.graal.api.core.Rule in project graal by graphik-team.

the class UnifierTest method mostGeneralTest1.

@Test
public void mostGeneralTest1() throws IteratorException {
    Rule rule = DefaultRuleFactory.instance().create();
    rule.getBody().add(TestUtils.pXY);
    rule.getHead().add(TestUtils.qXY);
    InMemoryAtomSet atomset = DefaultAtomSetFactory.instance().create();
    atomset.add(TestUtils.qUV);
    CloseableIteratorWithoutException<Substitution> unifiers = DefaultUnifierAlgorithm.instance().computePieceUnifier(rule, atomset);
    Assert.assertEquals(1, Iterators.count(unifiers));
}
Also used : Substitution(fr.lirmm.graphik.graal.api.core.Substitution) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) Rule(fr.lirmm.graphik.graal.api.core.Rule) Test(org.junit.Test)

Example 54 with Rule

use of fr.lirmm.graphik.graal.api.core.Rule in project graal by graphik-team.

the class UnifierTest method unificationExistentialWithFrontier.

@Test
public void unificationExistentialWithFrontier() {
    Rule rule = DefaultRuleFactory.instance().create();
    rule.getBody().add(TestUtils.sX);
    rule.getHead().add(TestUtils.pXY);
    InMemoryAtomSet atomset = DefaultAtomSetFactory.instance().create();
    atomset.add(TestUtils.pUU);
    CloseableIteratorWithoutException<Substitution> unifiers = DefaultUnifierAlgorithm.instance().computePieceUnifier(rule, atomset);
    Assert.assertEquals(0, Iterators.count(unifiers));
}
Also used : Substitution(fr.lirmm.graphik.graal.api.core.Substitution) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) Rule(fr.lirmm.graphik.graal.api.core.Rule) Test(org.junit.Test)

Example 55 with Rule

use of fr.lirmm.graphik.graal.api.core.Rule in project graal by graphik-team.

the class UnifierTest method pieceUnifierTest2.

@Test
public void pieceUnifierTest2() {
    Rule rule = DefaultRuleFactory.instance().create();
    rule.getBody().add(TestUtils.sX);
    rule.getHead().add(TestUtils.pXB);
    InMemoryAtomSet atomset = DefaultAtomSetFactory.instance().create();
    atomset.add(TestUtils.pAU);
    CloseableIteratorWithoutException<Substitution> unifiers = DefaultUnifierAlgorithm.instance().computePieceUnifier(rule, atomset);
    Assert.assertEquals(1, Iterators.count(unifiers));
}
Also used : Substitution(fr.lirmm.graphik.graal.api.core.Substitution) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) Rule(fr.lirmm.graphik.graal.api.core.Rule) Test(org.junit.Test)

Aggregations

Rule (fr.lirmm.graphik.graal.api.core.Rule)141 Test (org.junit.Test)87 Atom (fr.lirmm.graphik.graal.api.core.Atom)64 OWL2Parser (fr.lirmm.graphik.graal.io.owl.OWL2Parser)52 DefaultNegativeConstraint (fr.lirmm.graphik.graal.core.DefaultNegativeConstraint)49 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)26 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)23 LinkedList (java.util.LinkedList)19 IteratorException (fr.lirmm.graphik.util.stream.IteratorException)16 Term (fr.lirmm.graphik.graal.api.core.Term)15 Prefix (fr.lirmm.graphik.util.Prefix)14 CloseableIteratorWithoutException (fr.lirmm.graphik.util.stream.CloseableIteratorWithoutException)14 OWL2ParserException (fr.lirmm.graphik.graal.io.owl.OWL2ParserException)13 Predicate (fr.lirmm.graphik.graal.api.core.Predicate)9 DefaultAtom (fr.lirmm.graphik.graal.core.DefaultAtom)9 AtomSet (fr.lirmm.graphik.graal.api.core.AtomSet)7 KnowledgeBase (fr.lirmm.graphik.graal.api.kb.KnowledgeBase)7 DefaultRule (fr.lirmm.graphik.graal.core.DefaultRule)7 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)6 Variable (fr.lirmm.graphik.graal.api.core.Variable)6