use of fr.lirmm.graphik.graal.api.core.AtomSet 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);
}
}
use of fr.lirmm.graphik.graal.api.core.AtomSet 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);
}
}
use of fr.lirmm.graphik.graal.api.core.AtomSet 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;
}
}
use of fr.lirmm.graphik.graal.api.core.AtomSet in project graal by graphik-team.
the class DefaultKnowledgeBaseTest method testGetRuleNames.
/**
* Test method for
* {@link fr.lirmm.graphik.graal.kb.DefaultKnowledgeBase#getRuleNames()}.
* @throws ParseException
*/
@Test
public void testGetRuleNames() throws ParseException {
Rule r1 = DlgpParser.parseRule("[R1] p(x) :- q(X).");
Rule r2 = DlgpParser.parseRule("[R2] q(x) :- r(X).");
AtomSet store = new DefaultInMemoryGraphStore();
RuleSet ruleset = new LinkedListRuleSet();
ruleset.add(r1);
ruleset.add(r2);
KnowledgeBase kb = new DefaultKnowledgeBase(store, ruleset);
Assert.assertTrue(kb.getRuleNames().contains("R1"));
Assert.assertTrue(kb.getRuleNames().contains("R2"));
Assert.assertEquals(r1, kb.getRule("R1"));
Assert.assertEquals(r2, kb.getRule("R2"));
kb.close();
}
use of fr.lirmm.graphik.graal.api.core.AtomSet in project graal by graphik-team.
the class DefaultKnowledgeBaseTest method testDefaultKnowledgeBaseAtomSetRuleSet.
/**
* Test method for
* {@link fr.lirmm.graphik.graal.kb.DefaultKnowledgeBase#DefaultKnowledgeBase(fr.lirmm.graphik.graal.api.core.AtomSet, fr.lirmm.graphik.graal.api.core.RuleSet)}.
* @throws AtomSetException
* @throws ParseException
*/
@Test
public void testDefaultKnowledgeBaseAtomSetRuleSet() throws AtomSetException, ParseException {
Atom aa = DlgpParser.parseAtom("q(a).");
Atom ab = DlgpParser.parseAtom("q(b).");
Atom ac = DlgpParser.parseAtom("q(c).");
Rule r = DlgpParser.parseRule("[R1] p(x) :- q(X).");
NegativeConstraint nc = DlgpParser.parseNegativeConstraint("[NC] ! :- q(X), p(X).");
AtomSet store = new DefaultInMemoryGraphStore();
store.add(aa);
store.add(ab);
store.add(ac);
RuleSet ruleset = new LinkedListRuleSet();
ruleset.add(r);
ruleset.add(nc);
KnowledgeBase kb = new DefaultKnowledgeBase(store, ruleset);
Assert.assertTrue(kb.getOntology().contains(r));
Assert.assertTrue(kb.getOntology().contains(nc));
Assert.assertTrue(kb.getFacts().contains(aa));
Assert.assertTrue(kb.getFacts().contains(ab));
Assert.assertTrue(kb.getFacts().contains(ac));
kb.close();
}
Aggregations